From patchwork Wed Jul 11 09:28:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 942381 X-Patchwork-Delegate: petr.vorel@gmail.com 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 41QYfS0bqPz9s0n for ; Wed, 11 Jul 2018 19:28:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5466E3E6A9F for ; Wed, 11 Jul 2018 11:28:45 +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 7B6A43E6608 for ; Wed, 11 Jul 2018 11:28:43 +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 A8E4D6017C9 for ; Wed, 11 Jul 2018 11:28:41 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 164BBBB40D for ; Wed, 11 Jul 2018 09:28:40 +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 2203D2026D6B for ; Wed, 11 Jul 2018 09:28:38 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Wed, 11 Jul 2018 17:28:35 +0800 Message-Id: <20180711092835.12062-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 11 Jul 2018 09:28:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 11 Jul 2018 09:28:40 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 Subject: [LTP] [PATCH v2] 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 contiguous virtual memory region by using PROT_NONE to provide page not be accessed too. Here we can take use of it to achieve the same purpose. Also fix code comments to match open(2) maunal precisely. Signed-off-by: Li Wang --- testcases/kernel/syscalls/open/open08.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c index 5b24752..0a06d3a 100644 --- a/testcases/kernel/syscalls/open/open08.c +++ b/testcases/kernel/syscalls/open/open08.c @@ -44,8 +44,8 @@ * open(2) should fail with EACCES. * * 6. Attempt to pass an invalid pathname with an address pointing outside - * the address space of the process, as the argument to open(), and - * expect to get EFAULT. + * the accessible address space of the process, as the argument to open(), + * and expect to get EFAULT. */ #define _GNU_SOURCE /* for O_DIRECTORY */ @@ -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 = {