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: 62876 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp96801lbc; Thu, 25 Feb 2016 03:05:45 -0800 (PST) X-Received: by 10.140.250.213 with SMTP id v204mr59133638qhc.9.1456398345122; Thu, 25 Feb 2016 03:05:45 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z192si7614152qka.1.2016.02.25.03.05.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 25 Feb 2016 03:05:45 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dkim=fail header.i=@linaro.org Received: from localhost ([::1]:42186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYtjs-00036N-BG for patch@linaro.org; Thu, 25 Feb 2016 06:05:44 -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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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(-) -- 2.1.4 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; }