From patchwork Tue Jul 31 08:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 143177 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5063393ljj; Tue, 31 Jul 2018 01:43:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcBZbwPnGw/JCS0FbAG9AhqCSNGQPEl1F+ndXYr1YS0sU5foiBS2V5leeCc2WXDEVgAVUzN X-Received: by 2002:a37:a816:: with SMTP id r22-v6mr19024134qke.54.1533026612665; Tue, 31 Jul 2018 01:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533026612; cv=none; d=google.com; s=arc-20160816; b=TUoUULXVbaGgV7Om5F9kGv4b2P4UedBL5kT3rKeDua9bGbxwa9pN+T+cGnEZqxIVl6 RwRj1WFKdEG8Fyz/ksMtRi8/eVqZTSZiGl5ddE3hF2fvr7GBNhtKS4rwdqkJK5RLh2ti 636v0QaM1lpi9gB4ZPzZ0DHc/uoF4mywoxJxDDAe3JVFtfAARaHGTUmO2y+0+9GS1lQA 40MyBPkE8mTmRsgD5LZI1X24pyJNKtV46um/uuo0qv87cq0FYOiian+bXOa/wRUv5Sa8 3uF6+Qjaa+5ZtokOpIedDs/R4pJr7OuBC579LKaOb1+vLQBFozdTBNRKXBQCYrLumqAd U/Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=1DcgYkq3TOJHynIuoeVFLp5HwmJaTqajCSAoiv8OltU=; b=BbFSOn/HDiESq+i27Xi0kl3Q/Q7N2FlIGklitwxyf+J56ktmarrmHQzj0KvTCu3CMP YxNdZEmb1zXrw3BGZidnXgDJbti97yau5ZVHD2Wbo9F67Y1cs95BgNxefI0VfjRDHdVG W8pfjjrytRqklyOMQxhAiD0iRk/yYIrCeNW17u/yjXhAUPJT8g4OzVJlDyTyn6PxjrFi INs453oP79G5Hrva2jl10nI7OAOydLJakUqm8/WGqOj7nPB3ssl7Ux/tJzICGr638o8n S5fOVHNCt+Gr3Q4ne72dG1Arc68kLbo586zBKcz2GwwMy6P1u9hHrev+6tKlorkSbgLM kkhA== ARC-Authentication-Results: i=1; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o19-v6si974428qtf.274.2018.07.31.01.43.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 31 Jul 2018 01:43:32 -0700 (PDT) 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" Received: from localhost ([::1]:57624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkQFg-0003Sl-4X for patch@linaro.org; Tue, 31 Jul 2018 04:43:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkQFD-0003QX-Ej for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:43:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkQFA-0006et-0L for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:43:03 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:38217) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fkQF9-0006di-NN for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:42:59 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0Ln0mX-1gRlKw2hnZ-00hJRF; Tue, 31 Jul 2018 10:42:19 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 31 Jul 2018 10:42:01 +0200 Message-Id: <20180731084203.29959-2-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180731084203.29959-1-laurent@vivier.eu> References: <20180731084203.29959-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:AYph8q12/f2lP2Jnrh1mxlkrPuDAetQ+FXH/BGYWE/xZTHZ5OWN t70Ily+YohzXNa+V3nAmmww8GpNgIieYT4pboA5r5rX42gfNPz89cwVP/QRCIFJyqkOzwjl ItXbzqjNo19wjmeRp0uzigF4mkzYDYkj3r0ohJADWw4OWq1ECAbROvKiSf5fTXXen59hOHs YLqEZjwhb3lqHpAXvT+6Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:CNmPF70UGZg=:xf5bIuZzSW8OetEABtl4Ql z//MX9G1JUESOuL3YlYrf1oZMIbHmm8K6dd8/+MypyPrwsiOrKvQXnmlGZDXfhoriefbysgEs 6XcPCOWkTPtCDuYe4fwbG+t14mDgzAQTwu/rrSLP/1CvVFmyd0vrvqy8PZZUHfuCX5pQkYn3W I5AfyveIYc9uStocMiiFCEiBWJ4oLfJ5qbf+j0Ds0y8xfPdi2v03it9pP7OmoV2t3rpPr1CXs KejpHofQPPuzwjGHCRfOmkVcBC5hGiiyXvRO43UdvyZ8EO7Q2JOPBwbGuoOe5/qbWSOPve5Fk DaPvdurTh9IDUHn/sKKP3DsfBsH9z7xX+Gou7NSWOhhH3sCK887GUQvbtQcGX7mYDftWSdDwY SozxMRTOe8CzPERgR2fa/HvJrkls5qIQ++fAkDcQaFqql+NF7cFpVfGt1rb3gPBcjhbeZV72D iEGiU/vGojZPyYLB/zrtoqeLYDBWgUkPO8gnsrjuouytNSNSzRKtg0mfwSvMpDjMeQ/MhHAEY J/KG+PIWy0CR6Ei8Sw9x54U2OcsYDrsW+XcQDFTDuENTqPNtEdmdGc62GTQ/OkaJ5S+tNyYME mHz/Dhy0YOkOFI/42NHNPvepwoZ/wyUvi+m3cVkOMMXWPn9eVRFW6Q0MQqvysqWHppgPpmg5E rUvv5sNdkv/R944xzT0Q07e6qpv+80IiD/620ufDgI+6b41+EeubaBv7p1DF26IhWiCYmAlIA ZSCmdBnBcNM91JsG X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL 1/3] linux-user/mmap.c: handle invalid len 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_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée I've slightly re-organised the check to more closely match the sequence that the kernel uses in do_mmap(). We check for both the zero case (EINVAL) and the overflow length case (ENOMEM). Signed-off-by: Alex Bennée Cc: umarcor <1783362@bugs.launchpad.net> Reviewed-by: Laurent Vivier Message-Id: <20180730134321.19898-2-alex.bennee@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d0c50e4888..41e0983ce8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -391,14 +391,23 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } #endif - if (offset & ~TARGET_PAGE_MASK) { + if (!len) { errno = EINVAL; goto fail; } + /* Also check for overflows... */ len = TARGET_PAGE_ALIGN(len); - if (len == 0) - goto the_end; + if (!len) { + errno = ENOMEM; + goto fail; + } + + if (offset & ~TARGET_PAGE_MASK) { + errno = EINVAL; + goto fail; + } + real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask; From patchwork Tue Jul 31 08:42:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 143178 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5064241ljj; Tue, 31 Jul 2018 01:44:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvBlP3tUoGyRpkR9+Kc4phIXfDuMjWILXiU8G83vBh+OXOKv/v8q9tPI4Zowb3JOh/iAOO X-Received: by 2002:ac8:505:: with SMTP id u5-v6mr20632752qtg.114.1533026679381; Tue, 31 Jul 2018 01:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533026679; cv=none; d=google.com; s=arc-20160816; b=Nqs8xoG6/CrlXkCJAwZKgvr2jD3Dur8bNOBqfkc9/nuGAESIabVjQ9ozPZv63spqXa 7WsdXOdJpHxQkD1olDsuCnXHefARnX1wg1Bb9OBYCU45XrftEoLFf0ZTwBgcCoRmFCeG gd8J0l/NMPJZE6ro1omySJpRVkJmnOszhjLVTFhKGR8EVebdxK6W+xFsUTFiOyyzKL8C Ob7vxhaBuAOE8X6nWmDuUZ2TUyHGZq8Q2c3702N6GtbqQzkHvT+WpakmSFB5rGuj3k9l ugP1hMoEadPuwHFJJ1MrefiAbvPBaPYwjgQkvjZ8EmcDtnlDHHN+vEDDq6+dMD1o3wxT VytQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=0KRjAHaIgE7zN3TL4wLcec3Ai4nClMwrsbe07lWoAqw=; b=MKhUlyStFp7zZ54Hxb4zzdlpe+JUlPQBouD5yR7tE2YRqX7VLylIZZmYo39GPLNjzi 1m7lehe2V1IysY2LUlkxgdfia4yKH+uYcQUflOJg0BUcbE+E8U5fmWmLv9Bn0k++Z7S4 39LzG+gDIsqbFqO3qhPN0RmKoXgSvwt5I5A7S4Sl22+IjU+I94aE/MRcoQEV5/xEEZJm 9sXBkJt5rzq29vt1/UrB0KP1EDiuFl+zYCzWDmg/iliOuStcm+NhTMFrF8GScLBcZFyZ /9PvNWL0vCrFAmbYaOOgHaKcPi8pIeVnlxNJdpP2T23zBnBhayl761SuMNoWOCXPRq33 YcFQ== ARC-Authentication-Results: i=1; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n32-v6si182433qta.356.2018.07.31.01.44.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 31 Jul 2018 01:44:39 -0700 (PDT) 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" Received: from localhost ([::1]:57626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkQGk-0003dI-R7 for patch@linaro.org; Tue, 31 Jul 2018 04:44:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkQEj-0003B9-3c for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkQEg-0005pm-12 for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:42:33 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:59171) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fkQEf-0005ns-Ix for qemu-devel@nongnu.org; Tue, 31 Jul 2018 04:42:29 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0LmRkt-1gKaKd0xVL-00aBtr; Tue, 31 Jul 2018 10:42:20 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 31 Jul 2018 10:42:02 +0200 Message-Id: <20180731084203.29959-3-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180731084203.29959-1-laurent@vivier.eu> References: <20180731084203.29959-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:l52YK29W4RcdRtgSZYR/3yl72ugWcqgsGCQT1WYtd8JtO+gcOSB dEzSIluOvcRIIMyGKhS5qaIchqjOubU3ukFEoLBbrl1jJk4/icvlG01LS0xzgGHL4+2TpbP NYpY1uYdvuP84kUulPyAUUYsn8yKTOOPgsAgFp9TJM3JA/+4SeJEu4qi+wC0QIitduFnCUg u32j4ihZI6/tH1Eh3KjiQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:MLtbDN/5A/I=:E29OnVJkI7z2eMzCrV375E i+StIgnvDPk0ihLBBVAJBI06SSJk7llvvkyA318XUwmcg6b5x40OD/akw/SfM8mad0edNxk9n sWWKKW2iElhMSu1krg9e2gSvbziVK8yf++vnpqHQliKP/Bp9XOB4N5mpkh1Jcl3eWWBj9W7Ko bFXxZkTXspjcCj80uw304Z1RuYhHxJRpoJAsIMOTUkiGbI5KiqnuOZEMKucW2SgQZL9i4kA1p aDV0gNVoaFcxwX/icevJGkzPQ0vLtuwp809JFcYvdR1D5PqFG/3/74dIAOkwu4FxTrljdZ5s3 Yn9YVSgaoa29bp4LmDpOHOELe3Joi0m5yHnhfCtw17Rrzx91+L4M4UwgYwuAYssPpYGop9s44 gdtp+KnkDurIDgrJe7QZ0cW1PaynJiK+Z0zszUG6mKx8j7S/XrddWObUnolZv8LzK+KkKTlJ/ uHPNHi6pPoBXE3y95ZEMITptriIONJi+9g80eUWUvZT8oWMfZn3slqxtWwCdub8B6ywah4VpO H//AYKEcm51dQFedDkR5G6AIAeIA5rxwpIqCtmaudOam8CkT1zBOxxauDuVRJacYRZen0LgcL Wquv9JivckMY2BqKk/ixzkjpI56dEg4Gm/z4qM+/eMd2MrFkBU8SNwOTUEwvPfXa3kduLyRkS b3yfgMYXP4SyJntWf8MdlIqMGpDTmJIZq81ozyN2E97DStcA5Gg3s7Wv/Pf1z50w8DUQbmheK uYQ+Ti407l+O1VK8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL 2/3] 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>, Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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ée Reviewed-by: Richard Henderson Cc: umarcor <1783362@bugs.launchpad.net> Message-Id: <20180730134321.19898-3-alex.bennee@linaro.org> Signed-off-by: Laurent Vivier --- tests/tcg/multiarch/test-mmap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/tests/tcg/multiarch/test-mmap.c b/tests/tcg/multiarch/test-mmap.c index 5c0afe6e49..11d0e777b1 100644 --- a/tests/tcg/multiarch/test-mmap.c +++ b/tests/tcg/multiarch/test-mmap.c @@ -27,7 +27,7 @@ #include #include #include - +#include #include #define D(x) @@ -435,6 +435,25 @@ void checked_write(int fd, const void *buf, size_t count) fail_unless(rc == count); } +void check_invalid_mmaps(void) +{ + unsigned char *addr; + + /* Attempt to map a zero length page. */ + addr = mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); + fail_unless(addr == MAP_FAILED); + fail_unless(errno == EINVAL); + + /* Attempt to map a over length page. */ + addr = mmap(NULL, -4, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); + fail_unless(addr == MAP_FAILED); + fail_unless(errno == ENOMEM); + + fprintf(stdout, " passed\n"); +} + int main(int argc, char **argv) { char tempname[] = "/tmp/.cmmapXXXXXX"; @@ -476,6 +495,7 @@ int main(int argc, char **argv) check_file_fixed_mmaps(); check_file_fixed_eof_mmaps(); check_file_unfixed_eof_mmaps(); + check_invalid_mmaps(); /* Fails at the moment. */ /* check_aligned_anonymous_fixed_mmaps_collide_with_host(); */