From patchwork Wed May 13 14:36:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 1289364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49McpV5DrXz9sRR for ; Thu, 14 May 2020 00:42:40 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4EA743C25D8 for ; Wed, 13 May 2020 16:42:35 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id EC4133C2555 for ; Wed, 13 May 2020 16:42:32 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id E8B1E14011A9 for ; Wed, 13 May 2020 16:42:30 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.73,388,1583164800"; d="scan'208";a="92014703" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 13 May 2020 22:42:21 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 150964BCC8A6 for ; Wed, 13 May 2020 22:42:21 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 13 May 2020 22:42:20 +0800 Received: from Fedora-30.g08.fujitsu.local (10.167.220.106) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 13 May 2020 22:42:21 +0800 From: Xiao Yang To: Date: Wed, 13 May 2020 22:36:28 +0800 Message-ID: <20200513143629.2103-1-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 150964BCC8A6.ADD89 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/2] syscalls/pidfd_open01.c: Add check for close-on-exec flag X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" pidfd_open(2) will set close-on-exec flag on the file descriptor as its manpage states, so check close-on-exec flag by fcntl(2). Signed-off-by: Xiao Yang --- .../kernel/syscalls/pidfd_open/pidfd_open01.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c index 93bb86687..f475fe28e 100644 --- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c @@ -11,12 +11,21 @@ static void run(void) { - TEST(pidfd_open(getpid(), 0)); + int pidfd, flag; - if (TST_RET == -1) - tst_brk(TFAIL | TTERRNO, "pidfd_open(getpid(), 0) failed"); + pidfd = pidfd_open(getpid(), 0); + if (pidfd == -1) + tst_brk(TFAIL | TERRNO, "pidfd_open(getpid(), 0) failed"); - SAFE_CLOSE(TST_RET); + flag = fcntl(pidfd, F_GETFD); + + SAFE_CLOSE(pidfd); + + if (flag == -1) + tst_brk(TFAIL | TERRNO, "fcntl(F_GETFD) failed"); + + if (!(flag & FD_CLOEXEC)) + tst_brk(TFAIL, "pidfd_open(getpid(), 0) didn't set close-on-exec flag"); tst_res(TPASS, "pidfd_open(getpid(), 0) passed"); } From patchwork Wed May 13 14:36:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 1289365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49McpZ4bCgz9sRY for ; Thu, 14 May 2020 00:42:46 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F10CB3C550C for ; Wed, 13 May 2020 16:42:43 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 439893C2555 for ; Wed, 13 May 2020 16:42:33 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 0D3761A01442 for ; Wed, 13 May 2020 16:42:30 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.73,388,1583164800"; d="scan'208";a="92014709" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 13 May 2020 22:42:27 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id CF6D750A996E for ; Wed, 13 May 2020 22:42:21 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 13 May 2020 22:42:22 +0800 Received: from Fedora-30.g08.fujitsu.local (10.167.220.106) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 13 May 2020 22:42:21 +0800 From: Xiao Yang To: Date: Wed, 13 May 2020 22:36:29 +0800 Message-ID: <20200513143629.2103-2-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200513143629.2103-1-yangx.jy@cn.fujitsu.com> References: <20200513143629.2103-1-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: CF6D750A996E.ABF4F X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/2] syscalls/pidfd_open*.c: Drop .min_kver flag X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1) Drop .min_kver flag directly because of two following reasons: a) pidfd_open(2) may be backported to old kernel which is less than v5.3 so kernel version check is meaningless. b) tst_syscall() can report TCONF if pidfd_open(2) is not supported. 2) For pidfd_open03.c, check if pidfd_open(2) is not supported before calling fork() and remove unnecessary TEST(). Signed-off-by: Xiao Yang --- .../kernel/syscalls/pidfd_open/pidfd_open01.c | 1 - .../kernel/syscalls/pidfd_open/pidfd_open02.c | 1 - .../kernel/syscalls/pidfd_open/pidfd_open03.c | 17 ++++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c index f475fe28e..b88fd0bf9 100644 --- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c @@ -31,6 +31,5 @@ static void run(void) } static struct tst_test test = { - .min_kver = "5.3", .test_all = run, }; diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c index dc86cae7a..a7328ddfe 100644 --- a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c @@ -51,7 +51,6 @@ static void run(unsigned int n) } static struct tst_test test = { - .min_kver = "5.3", .tcnt = ARRAY_SIZE(tcases), .test = run, .setup = setup, diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c index 48470e5e1..af719e1f4 100644 --- a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c @@ -27,11 +27,9 @@ static void run(void) exit(EXIT_SUCCESS); } - TEST(pidfd_open(pid, 0)); - - fd = TST_RET; + fd = pidfd_open(pid, 0); if (fd == -1) - tst_brk(TFAIL | TTERRNO, "pidfd_open() failed"); + tst_brk(TFAIL | TERRNO, "pidfd_open() failed"); TST_CHECKPOINT_WAKE(0); @@ -49,8 +47,17 @@ static void run(void) tst_res(TPASS, "pidfd_open() passed"); } +static void pidfd_open_supported_by_kernel(void) +{ + int pidfd; + + pidfd = tst_syscall(__NR_pidfd_open, getpid(), 0); + if (pidfd != -1) + SAFE_CLOSE(pidfd); +} + static struct tst_test test = { - .min_kver = "5.3", + .setup = pidfd_open_supported_by_kernel, .test_all = run, .forks_child = 1, .needs_checkpoints = 1,