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: 8361311 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 73DBD9F2F0 for ; Fri, 19 Feb 2016 13:48:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7AEF2045B for ; Fri, 19 Feb 2016 13:48:19 +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 14CED20443 for ; Fri, 19 Feb 2016 13:48:19 +0000 (UTC) Received: from localhost ([::1]:52448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWlPu-0001Za-Ge for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Feb 2016 08:48:18 -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+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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 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; }