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(); */