From patchwork Wed Jul 11 05:16:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 942311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41QS3v4kRFzB4MN for ; Wed, 11 Jul 2018 15:16:56 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4C4FC3E76D1 for ; Wed, 11 Jul 2018 07:16:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id E9BA03E76A4 for ; Wed, 11 Jul 2018 07:16:51 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 246E2601717 for ; Wed, 11 Jul 2018 07:16:50 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E056407048A for ; Wed, 11 Jul 2018 05:16:49 +0000 (UTC) Received: from dhcp-12-102.nay.redhat.com (dhcp-12-102.nay.redhat.com [10.66.12.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59A122166BA2; Wed, 11 Jul 2018 05:16:48 +0000 (UTC) From: Li Wang To: jstancek@redhat.com Date: Wed, 11 Jul 2018 13:16:45 +0800 Message-Id: <20180711051645.5075-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 11 Jul 2018 05:16:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 11 Jul 2018 05:16:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'liwang@redhat.com' RCPT:'' X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH] open08: calling tst_get_bad_addr from LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From open(2) manual, pathname(unmapped_fname) points outside the accessible address space, then test will result in failure with EFAULT. LTP tst_get_bad_addr() maps a "guard-page" by using PROT_NONE to provides page not be accessed too. Here we can take use of it to achieve the same purpose. Signed-off-by: Li Wang --- Notes: Jan, I'm sorry I didn't think of that function in LTP API when reveiwed your open08 patch. Here I propose to remove the get_invalid_addr() from open08.c. Li Wang testcases/kernel/syscalls/open/open08.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c index 5b24752..c407332 100644 --- a/testcases/kernel/syscalls/open/open08.c +++ b/testcases/kernel/syscalls/open/open08.c @@ -58,6 +58,7 @@ #include #include #include "tst_test.h" +#include "tst_get_bad_addr.h" static char *existing_fname = "open08_testfile"; static char *toolong_fname = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; @@ -101,17 +102,6 @@ void verify_open(unsigned int i) } } -static void *get_invalid_addr(void) -{ - char *bad_addr; - int len = 2 * 1024 * 1024; - - bad_addr = SAFE_MMAP(0, len, PROT_READ|PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - SAFE_MUNMAP(bad_addr, len); - return bad_addr + len/2; -} - static void setup(void) { int fildes; @@ -130,7 +120,7 @@ static void setup(void) fildes = SAFE_CREAT(existing_fname, 0600); close(fildes); - unmapped_fname = get_invalid_addr(); + unmapped_fname = tst_get_bad_addr(NULL); } static struct tst_test test = {