From nobody Wed Nov 5 02:32:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532611886319796.8903758253601; Thu, 26 Jul 2018 06:31:26 -0700 (PDT) Received: from localhost ([::1]:36024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figMV-0005G6-Ky for importer@patchew.org; Thu, 26 Jul 2018 09:31:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figL3-0004Oy-WB for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1figL1-0004G6-0r for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:54 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:39181) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1figL0-0004Dx-Pk for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:50 -0400 Received: by mail-wm0-x241.google.com with SMTP id h20-v6so2005017wmb.4 for ; Thu, 26 Jul 2018 06:29:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d7-v6sm1547694wro.92.2018.07.26.06.29.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Jul 2018 06:29:48 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C88533E012E; Thu, 26 Jul 2018 14:29:47 +0100 (BST) 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 :mime-version:content-transfer-encoding; bh=wgb29qVTxsksM7UXTcNm6n8cOSpKpK2tp1eBDFY0WJs=; b=J4qj3i2GGtcFgP3f6JnpPd1kG3YRz2J77491Q+GUXs8OZJKYEWtiHJbw9lEeYoh88+ oOsWfpIaicGqolG+UBhxVbXty6FnVD+7ER7UQEn3GpqhiXNeXPlOkKc/+j5LuEVAPGrt U4mJO3JCG/Cp+YUTUmzCOmIm4HqzfCEzONj1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wgb29qVTxsksM7UXTcNm6n8cOSpKpK2tp1eBDFY0WJs=; b=qb5rx1PfWM3T1iC+2LbxGW3Mci8sTSCL+uyduKMuFETO1qlZ5Qw8u4RTZn3ZWPFlU8 FTe9ai9QwL13c8X3ao5ntzdPlN6vNMIzsgpD5QmQ1TpFmspOol9HWCjxRzv4G4fjVNeS HvrWkRaNmgOrKxO6g8AhaIc4LXBkjbPnuyPsFVonMtzhWgNJVsGQk51fzOJGx5dvF3zG +QTic0qyKn8F//PmpxsPB7iN73rTn/xaoBqvTkejeCSJgY3PbdFaXngy793Yy1QcxhE/ gGKV78ZxOje1V0ccEZq0LqEBlS7nw+/dtQJvwtKwx0c0VB3k3AFKktm6VL4WO6nyWJeC kStg== X-Gm-Message-State: AOUpUlFV4ILCH2G52uFRC8eNwNjWNljjdAp5+dap19Qx6IDE6CbUffrq lYZYMrngGoy52Dxc1qWYhPt3kA== X-Google-Smtp-Source: AAOMgpcr51xM2OY3Y8j3RXIPQV20+yDKbskFPd5lTK7zYwu+ccJiHlv46l6YEfDtOBqrG36ZjSlVnA== X-Received: by 2002:a1c:9042:: with SMTP id s63-v6mr1520967wmd.91.1532611789732; Thu, 26 Jul 2018 06:29:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 26 Jul 2018 14:29:46 +0100 Message-Id: <20180726132947.28538-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180726132947.28538-1-alex.bennee@linaro.org> References: <20180726132947.28538-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v1 for 3.0 1/2] linux-user/mmap.c: handle len = 0 maps correctly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: umarcor <1783362@bugs.launchpad.net>, Riku Voipio , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 I've slightly re-organised the check to more closely match the sequence that the kernel uses in do_mmap(). Signed-off-by: Alex Benn=C3=A9e Cc: umarcor <1783362@bugs.launchpad.net> --- linux-user/mmap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d0c50e4888..3ef69fa2d0 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -391,14 +391,22 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, } #endif =20 - if (offset & ~TARGET_PAGE_MASK) { + if (!len) { errno =3D EINVAL; goto fail; } =20 len =3D TARGET_PAGE_ALIGN(len); - if (len =3D=3D 0) - goto the_end; + if (!len) { + errno =3D EINVAL; + goto fail; + } + + if (offset & ~TARGET_PAGE_MASK) { + errno =3D EINVAL; + goto fail; + } + real_start =3D start & qemu_host_page_mask; host_offset =3D offset & qemu_host_page_mask; =20 --=20 2.17.1 From nobody Wed Nov 5 02:32:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532611987907455.3186013896219; Thu, 26 Jul 2018 06:33:07 -0700 (PDT) Received: from localhost ([::1]:36036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figO5-0006Bw-Ix for importer@patchew.org; Thu, 26 Jul 2018 09:33:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1figL4-0004PB-Qq for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1figL1-0004If-Qk for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:54 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:40906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1figL1-0004G4-K7 for qemu-devel@nongnu.org; Thu, 26 Jul 2018 09:29:51 -0400 Received: by mail-wm0-x236.google.com with SMTP id y9-v6so2037160wma.5 for ; Thu, 26 Jul 2018 06:29:51 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i4-v6sm2208493wmf.4.2018.07.26.06.29.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Jul 2018 06:29:49 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DB1233E0190; Thu, 26 Jul 2018 14:29:47 +0100 (BST) 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 :mime-version:content-transfer-encoding; bh=fPpsMUZsooFNseQTxSxS5/ciqBkWh8WBCac9H5dCwnE=; b=F5uV0k5a0djBl5agBSRdD/wlyk3p4uZoTW4FnmVHaXr1S8ocNCsjCLnHy2/v4+jJci i4T7D1VFD+sVY2d2y4bYMFeRvszSNM5x8GEGKhvOcayOniwG2QWg+GLHm/cGAWr7Tv/K bpg4Y0h/f3be3ifTMrUIh6a1IeEqVfHzdxuT8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fPpsMUZsooFNseQTxSxS5/ciqBkWh8WBCac9H5dCwnE=; b=lrh9+Y2I6knTDHU4d3KZXAYFCferXJ4hiuGe8hPvMEmRXNhUD9XLbvvz0jVv8oBWk+ 6nFzmHi1luBd9I1OQn6BWd8G7L+kS30nkZxqiF0Y6cA7EKsG6ZWmoyyu/JD3OKvz1Ob3 cWEm0G40k0vMx0yUWgDcDnA12zOe393mVMnF3L2tUBe7Ed+ovduG/ZmRSt3xj3NKT0c8 2bw6nuZnIiErWFwyfUOvhhFl3i8IQsPkvdR+oDDmI/o8VXq8HKb75Lu7+k3vmJQtlhGN FoFsWjFy70PCSPyVKXl/i2fOwo9vMnMwNmwMY5+TYTm06vuwdDjGG1m9Omr9WUWYtHCj 2esQ== X-Gm-Message-State: AOUpUlFEA+b27dAeKjtxvVKxPpyy3fVRPHk384XUR20yB5iSkgZSwBzb ptODN2sd1IzabDU9+XUb/esapQ== X-Google-Smtp-Source: AAOMgpfW/dCuhKDBTqHdqMYk4MIWAa6mhvg4HT95721Irq70Y+vaDVYDdQtdb/3///cKZIlBoACRlQ== X-Received: by 2002:a1c:e189:: with SMTP id y131-v6mr1571278wmg.44.1532611790564; Thu, 26 Jul 2018 06:29:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 26 Jul 2018 14:29:47 +0100 Message-Id: <20180726132947.28538-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180726132947.28538-1-alex.bennee@linaro.org> References: <20180726132947.28538-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 Subject: [Qemu-devel] [PATCH v1 for 3.0 2/2] tests: add check_invalid_maps to test-mmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: umarcor <1783362@bugs.launchpad.net>, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 This adds a test to make sure we fail properly for a 0 length mmap. There are most likely other failure conditions we should also check. Signed-off-by: Alex Benn=C3=A9e Cc: umarcor <1783362@bugs.launchpad.net> Reviewed-by: Richard Henderson --- tests/tcg/multiarch/test-mmap.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/tcg/multiarch/test-mmap.c b/tests/tcg/multiarch/test-mma= p.c index 5c0afe6e49..7f62eba4e9 100644 --- a/tests/tcg/multiarch/test-mmap.c +++ b/tests/tcg/multiarch/test-mmap.c @@ -27,7 +27,7 @@ #include #include #include - +#include #include =20 #define D(x) @@ -435,6 +435,19 @@ void checked_write(int fd, const void *buf, size_t cou= nt) fail_unless(rc =3D=3D count); } =20 +void check_invalid_mmaps(void) +{ + unsigned char *addr; + + /* Attempt to map a zero length page. */ + addr =3D mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + fprintf(stdout, "%s addr=3D%p", __func__, (void *)addr); + fail_unless(addr =3D=3D MAP_FAILED); + fail_unless(errno =3D=3D EINVAL); + + fprintf(stdout, " passed\n"); +} + int main(int argc, char **argv) { char tempname[] =3D "/tmp/.cmmapXXXXXX"; @@ -476,6 +489,7 @@ int main(int argc, char **argv) check_file_fixed_mmaps(); check_file_fixed_eof_mmaps(); check_file_unfixed_eof_mmaps(); + check_invalid_mmaps(); =20 /* Fails at the moment. */ /* check_aligned_anonymous_fixed_mmaps_collide_with_host(); */ --=20 2.17.1