From patchwork Fri Feb 19 13:42:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 62345 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1177862lbl; Fri, 19 Feb 2016 05:48:56 -0800 (PST) X-Received: by 10.140.29.202 with SMTP id b68mr15462313qgb.100.1455889736230; Fri, 19 Feb 2016 05:48:56 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y69si14424977qka.73.2016.02.19.05.48.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Feb 2016 05:48:56 -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]:52454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWlQV-0002Qg-Oo for patch@linaro.org; Fri, 19 Feb 2016 08:48:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWlKc-0000Th-GK for qemu-devel@nongnu.org; Fri, 19 Feb 2016 08:42:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWlKY-0004cn-Ev for qemu-devel@nongnu.org; Fri, 19 Feb 2016 08:42:50 -0500 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:36230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWlKY-0004ch-6c for qemu-devel@nongnu.org; Fri, 19 Feb 2016 08:42:46 -0500 Received: by mail-lf0-x234.google.com with SMTP id 78so53884832lfy.3 for ; Fri, 19 Feb 2016 05:42:46 -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=McL/YmCHau9Z9j0+rIoCMac6rzQlRLsZEz0GTs//v/w=; b=P+sPYmiOQrDXUQxZ6JD0V/eOhPwfVX2n5PBoh77Q3MoLSa0AhKHGzJCUBO9S5PlecJ UOYDOypkXWCINLVvVfSIy7sMAsDWEfjk1frwcRL6rURNmdVfGk8Y6oS6f/ygATVF3GUu y4QstnDBCtBUySS6OJ7h24XP9oi55iFv5O47U= 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=McL/YmCHau9Z9j0+rIoCMac6rzQlRLsZEz0GTs//v/w=; b=FJ6HOB7hEufgGRpHHEjkwKK7+sRrchKmIjUqXEe4cJJ7QDHio1djuZ/gbrpFXHCg4A WIQzgN4orq0eV/co/7J3AjXoBvvpSCvGl1SbaWsVXTsLp81IFX+oxHWDXV3sv/daArbX SGoHpVh36yGqNGhyT5pOgicoXagg872tWX2moo8rNed0q0Bg9rLu4eSMm+csdKsvwhOF ZDNzDlNGKJ4yQJ9dTEJ5LAUhWius8s1EfKbJM64n/a4mCVuzDUZ2u4v7LNMO9hSYTzrR v6pEsQYas2eJ+Z410/TuZj1ofFZGm8b0pfeEJ3WZWj5z7i6Xu7apR2FRCDtDMB6BdPjr TUvg== X-Gm-Message-State: AG10YOS0JZSyNMMiIZcdBrjlxiovMDEjwlSpyUQQOpAve/K1p+kWcunocJrthSh5c4VH+O9w X-Received: by 10.25.20.228 with SMTP id 97mr5452816lfu.25.1455889365480; Fri, 19 Feb 2016 05:42:45 -0800 (PST) Received: from localhost.localdomain (91-157-175-207.elisa-laajakaista.fi. [91.157.175.207]) by smtp.gmail.com with ESMTPSA id o184sm1557417lfb.15.2016.02.19.05.42.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 05:42:44 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 19 Feb 2016 15:42:27 +0200 Message-Id: X-Mailer: git-send-email 2.7.0 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::234 Cc: Peter Maydell Subject: [Qemu-devel] [PULL 5/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.7.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6801fa2..83b881c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2601,8 +2601,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 @@ -3294,7 +3295,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; @@ -3311,8 +3313,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; }