From patchwork Thu Feb 25 11:01:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 8422531 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 60F5AC0553 for ; Thu, 25 Feb 2016 11:05:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4F91202B8 for ; Thu, 25 Feb 2016 11:05:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33DC6202AE for ; Thu, 25 Feb 2016 11:05:18 +0000 (UTC) Received: from localhost ([::1]:42181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYtjR-0002Un-Im for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Feb 2016 06:05:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYtfi-000556-SQ for qemu-devel@nongnu.org; Thu, 25 Feb 2016 06:01:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYtff-0000cJ-1k for qemu-devel@nongnu.org; Thu, 25 Feb 2016 06:01:26 -0500 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]:32940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYtfe-0000c9-P7 for qemu-devel@nongnu.org; Thu, 25 Feb 2016 06:01:22 -0500 Received: by mail-lf0-x232.google.com with SMTP id m1so30748504lfg.0 for ; Thu, 25 Feb 2016 03:01:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=USrgdlbxyL3ZdK7O5yYUcMwim6ohUwfyBiP8EDc0tr0=; b=JGX87Ab3Hifs90uHHlIWEvlxZSEnVcbu5ygMMoh4G8BbDsnbuVL+FWpKNyQRDA1W5n txI03zw4jjKgG0sftr8bbg5SZaEGbLuOswxYsesau53HDyFhGuXQR11Ly3SR36tx7/67 QQQ5oieZlgmt6bcaDKpjp1gldLwBwyx9IZAmg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=USrgdlbxyL3ZdK7O5yYUcMwim6ohUwfyBiP8EDc0tr0=; b=dRMbyNk/dYamHyTU12n38db4FlPGyAMpirpQY8/OgvkauqooS/E+hmcm9qUAIs6yCw ZhHoIimocTxbEtn5/VX91Kuj1jJNqh/Ai4CYMh5r0HhrBTQ2WOSTk15v0ehmfAd/84TK HBMChzrtJ5FW35EFw3h0kLsgNsyT7/xV4s615ERpebgYc/vAdS2SChSwERfz+XB+4CVr Ob8P2YFgQP1e7oS8HlSHd4pvxh9sg0pyvzgXY1KpkZRNdwtsDAvIJPrjrm4QzcGu0SXd 7gbh6gDx22g0HzuSM0i5+35P9PcJEg3JheBoSV1HNhLvg8cS+KbxMyxWl2JlHCVBmiDk gcyA== X-Gm-Message-State: AG10YOS5AdDVFoI5qEa9XmFE7vOtmOY9jN4DtKmuLjKmXa5PF5TeY1UjtE1spBH7abB8UjbV X-Received: by 10.25.86.144 with SMTP id k138mr16950871lfb.59.1456398081998; Thu, 25 Feb 2016 03:01:21 -0800 (PST) Received: from beaming.home (91-157-175-207.elisa-laajakaista.fi. [91.157.175.207]) by smtp.gmail.com with ESMTPSA id f184sm1066803lfe.6.2016.02.25.03.01.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 03:01:20 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2016 13:01:09 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::232 Cc: Peter Maydell Subject: [Qemu-devel] [PULL v2 4/8] linux-user: Don't assert if guest tries shmdt(0) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Maydell Our implementation of shmat() and shmdt() for linux-user was using "zero guest address" as its marker for "entry in the shm_regions[] array is not in use". This meant that if the guest did a shmdt(0) we would match on an unused array entry and call page_set_flags() with both start and end addresses zero, which causes an assertion failure. Use an explicit in_use flag to manage the shm_regions[] array, so that we avoid this problem. Signed-off-by: Peter Maydell Reported-by: Pavel Shamis Reviewed-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dac5518..8b76169 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2598,8 +2598,9 @@ static abi_long do_socketcall(int num, abi_ulong vptr) #define N_SHM_REGIONS 32 static struct shm_region { - abi_ulong start; - abi_ulong size; + abi_ulong start; + abi_ulong size; + bool in_use; } shm_regions[N_SHM_REGIONS]; struct target_semid_ds @@ -3291,7 +3292,8 @@ static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg) ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); for (i = 0; i < N_SHM_REGIONS; i++) { - if (shm_regions[i].start == 0) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use = true; shm_regions[i].start = raddr; shm_regions[i].size = shm_info.shm_segsz; break; @@ -3308,8 +3310,8 @@ static inline abi_long do_shmdt(abi_ulong shmaddr) int i; for (i = 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].start == shmaddr) { - shm_regions[i].start = 0; + if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { + shm_regions[i].in_use = false; page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); break; }