From patchwork Tue Aug 22 10:41:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1824094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVQsN4Gmvz1ydn for ; Tue, 22 Aug 2023 20:42:32 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 415153CC75A for ; Tue, 22 Aug 2023 12:42:30 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C0C783CC6D2 for ; Tue, 22 Aug 2023 12:42:16 +0200 (CEST) Received: from esa8.hc1455-7.c3s2.iphmx.com (esa8.hc1455-7.c3s2.iphmx.com [139.138.61.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 84AD5200B98 for ; Tue, 22 Aug 2023 12:42:14 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="117086216" X-IronPort-AV: E=Sophos;i="6.01,192,1684767600"; d="scan'208";a="117086216" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa8.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2023 19:42:12 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 1526CE428A for ; Tue, 22 Aug 2023 19:42:10 +0900 (JST) Received: from aks-ab2.gw.nic.fujitsu.com (aks-ab2.gw.nic.fujitsu.com [192.51.207.12]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 541ECD21AF for ; Tue, 22 Aug 2023 19:42:09 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by aks-ab2.gw.nic.fujitsu.com (Postfix) with ESMTP id 7017E87899; Tue, 22 Aug 2023 19:42:08 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Tue, 22 Aug 2023 18:41:39 +0800 Message-Id: <1692700900-13521-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27828.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27828.006 X-TMASE-Result: 10--11.132000-10.000000 X-TMASE-MatchedRID: NGDYxnKYxb3IY6JevWs4vgPZZctd3P4B9LMB0hXFSeg6FHRWx2FGsI3c eRXYSJoDIvrftAIhWmJU1CACweeL4NbNQByfRPHgSs47mbT7SATzWEMQjooUzShjD8kfQ8yyuJE UmdYPGSUgRqs658XN41OWqZ+cVy7s8PB/0vDHqZc2aDVyTGx/pwGZ/+APXW9kr2Pto2emO2UG6E w0t87pQEEtPSJifonDyYyeAPTbBZYpcZda/ugaiN9JA2lmQRNUHhysWPN3OzibKItl61J/yZ+in TK0bC9eKrauXd3MZDXaU0BzsrbL7cGuZvewCr0K/HLlZA8T7EofsctTTvxpC2lj74733u09 X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/2] syscalls/faccessat201: Add new testcase 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check the basic functionality of faccessat2(). Signed-off-by: Yang Xu --- configure.ac | 1 + include/lapi/faccessat.h | 21 +++++ include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + runtest/syscalls | 3 + .../kernel/syscalls/faccessat2/.gitignore | 1 + testcases/kernel/syscalls/faccessat2/Makefile | 9 ++ .../kernel/syscalls/faccessat2/faccessat201.c | 89 +++++++++++++++++++ 20 files changed, 138 insertions(+) create mode 100644 include/lapi/faccessat.h create mode 100644 testcases/kernel/syscalls/faccessat2/.gitignore create mode 100644 testcases/kernel/syscalls/faccessat2/Makefile create mode 100644 testcases/kernel/syscalls/faccessat2/faccessat201.c diff --git a/configure.ac b/configure.ac index e4aa2cadf..662c4c058 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,7 @@ AC_CHECK_FUNCS_ONCE([ \ epoll_pwait \ epoll_pwait2 \ execveat \ + faccessat2 \ fallocate \ fchownat \ fsconfig \ diff --git a/include/lapi/faccessat.h b/include/lapi/faccessat.h new file mode 100644 index 000000000..5b42014d2 --- /dev/null +++ b/include/lapi/faccessat.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved. + * Copyright (c) Linux Test Project, 2003-2023 + * Author: Yang Xu + */ + +#ifndef FACCESSAT2_H +#define FACCESSAT2_H + +#include "tst_test.h" +#include "lapi/syscalls.h" + +#ifndef HAVE_FACCESSAT2 +int faccessat2(int dirfd, const char *pathname, int mode, int flags) +{ + return tst_syscall(__NR_faccessat2, dirfd, pathname, mode, flags); +} +#endif + +#endif /* FACCESSAT2_H */ diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index de4ed5fb1..2cb6c2d87 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -293,6 +293,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in index 9f11381db..3e2ee9061 100644 --- a/include/lapi/syscalls/arc.in +++ b/include/lapi/syscalls/arc.in @@ -313,6 +313,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index 4b0f63a28..7bdbca533 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -391,6 +391,7 @@ clone3 (__NR_SYSCALL_BASE+435) close_range (__NR_SYSCALL_BASE+436) openat2 (__NR_SYSCALL_BASE+437) pidfd_getfd (__NR_SYSCALL_BASE+438) +faccessat2 (__NR_SYSCALL_BASE+439) epoll_pwait2 (__NR_SYSCALL_BASE+441) quotactl_fd (__NR_SYSCALL_BASE+443) futex_waitv (__NR_SYSCALL_BASE+449) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index b6d32d386..8ebdafafb 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -40,6 +40,7 @@ fsmount 432 fspick 433 pidfd_open 434 close_range 436 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index d0e6e9a4b..1472631c4 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -427,6 +427,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index 123200624..0ea6e9722 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -340,6 +340,7 @@ pidfd_open 1458 close_range 1460 openat2 1461 pidfd_getfd 1462 +faccessat2 1463 epoll_pwait2 1465 quotactl_fd 1467 futex_waitv 1473 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index d5de621e1..545d9d3d6 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -420,6 +420,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index d5de621e1..545d9d3d6 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -420,6 +420,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index 6505f3822..7213ac5f8 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -407,6 +407,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index bc5d2b34c..879012e2b 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -355,6 +355,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index 316ffe5f1..7d5192a27 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -401,6 +401,7 @@ pidfd_open 434 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index e0c60a360..91d2fb1c2 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -406,6 +406,7 @@ pidfd_open 434 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index 0acde6856..1f2fc59b7 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -371,6 +371,7 @@ pidfd_open 434 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index 1863e1df7..dc61aa56e 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -348,6 +348,7 @@ clone3 435 close_range 436 openat2 437 pidfd_getfd 438 +faccessat2 439 epoll_pwait2 441 quotactl_fd 443 futex_waitv 449 diff --git a/runtest/syscalls b/runtest/syscalls index 119710d63..02768c236 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -216,6 +216,9 @@ exit_group01 exit_group01 #faccessat test cases faccessat01 faccessat01 +#faccessat2 test cases +faccessat201 faccessat201 + #fallocate test cases fallocate01 fallocate01 fallocate02 fallocate02 diff --git a/testcases/kernel/syscalls/faccessat2/.gitignore b/testcases/kernel/syscalls/faccessat2/.gitignore new file mode 100644 index 000000000..53f700bac --- /dev/null +++ b/testcases/kernel/syscalls/faccessat2/.gitignore @@ -0,0 +1 @@ +/faccessat201 diff --git a/testcases/kernel/syscalls/faccessat2/Makefile b/testcases/kernel/syscalls/faccessat2/Makefile new file mode 100644 index 000000000..aaac6b703 --- /dev/null +++ b/testcases/kernel/syscalls/faccessat2/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2023 FUJITSU LIMITED. All rights reserved. +# Author: Yang Xu + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/faccessat2/faccessat201.c b/testcases/kernel/syscalls/faccessat2/faccessat201.c new file mode 100644 index 000000000..88ee21522 --- /dev/null +++ b/testcases/kernel/syscalls/faccessat2/faccessat201.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved. + * Copyright (c) Linux Test Project, 2003-2023 + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * Check the basic functionality of faccessat2(). + * + * Minimum Linux version required is v5.8. + */ + +#include + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "lapi/faccessat.h" + +#define TESTDIR "faccessat2dir" +#define TESTFILE "faccessat2file" +#define RELPATH "faccessat2dir/faccessat2file" +#define TESTSYMLINK "faccessat2symlink" + +static int dir_fd, bad_fd = -1; +static int atcwd_fd = AT_FDCWD; +static char *testfile; +static char *abs_path; +static char *rel_path; +static char *sym_path; + +static struct tcase { + int *fd; + char **filename; + int flags; +} tcases[] = { + {&dir_fd, &testfile, 0}, + {&bad_fd, &abs_path, 0}, + {&atcwd_fd, &rel_path, 0}, + {&dir_fd, &testfile, AT_EACCESS}, + {&bad_fd, &abs_path, AT_EACCESS}, + {&atcwd_fd, &rel_path, AT_EACCESS}, + {&atcwd_fd, &sym_path, AT_SYMLINK_NOFOLLOW}, +}; + +static void verify_faccessat2(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + + TST_EXP_PASS(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags), + "faccessat2(%d, %s, R_OK, %d)", + *tc->fd, *tc->filename, tc->flags); +} + +static void setup(void) +{ + char *tmpdir_path = tst_get_tmpdir(); + + abs_path = tst_aprintf("%s/%s", tmpdir_path, RELPATH); + free(tmpdir_path); + + SAFE_MKDIR(TESTDIR, 0666); + dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY); + SAFE_TOUCH(abs_path, 0444, NULL); + SAFE_SYMLINK(abs_path, TESTSYMLINK); +} + +static void cleanup(void) +{ + if (dir_fd > -1) + SAFE_CLOSE(dir_fd); +} + +static struct tst_test test = { + .test = verify_faccessat2, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .bufs = (struct tst_buffers []) { + {&testfile, .str = TESTFILE}, + {&abs_path, .size = sizeof(char)}, + {&rel_path, .str = RELPATH}, + {&sym_path, .str = TESTSYMLINK}, + {}, + }, + .needs_tmpdir = 1, +}; From patchwork Tue Aug 22 10:41:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1824093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVQs96569z1ydn for ; Tue, 22 Aug 2023 20:42:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DDF153CC737 for ; Tue, 22 Aug 2023 12:42:18 +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 [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 54F323CC6D2 for ; Tue, 22 Aug 2023 12:42:15 +0200 (CEST) Received: from esa5.hc1455-7.c3s2.iphmx.com (esa5.hc1455-7.c3s2.iphmx.com [68.232.139.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id EA02260012F for ; Tue, 22 Aug 2023 12:42:14 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="128510678" X-IronPort-AV: E=Sophos;i="6.01,192,1684767600"; d="scan'208";a="128510678" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2023 19:42:13 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 68880C68E4 for ; Tue, 22 Aug 2023 19:42:10 +0900 (JST) Received: from aks-ab2.gw.nic.fujitsu.com (aks-ab2.gw.nic.fujitsu.com [192.51.207.12]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 99C52D5040 for ; Tue, 22 Aug 2023 19:42:09 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by aks-ab2.gw.nic.fujitsu.com (Postfix) with ESMTP id DA039884AF; Tue, 22 Aug 2023 19:42:08 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Tue, 22 Aug 2023 18:41:40 +0800 Message-Id: <1692700900-13521-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1692700900-13521-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1692700900-13521-1-git-send-email-xuyang2018.jy@fujitsu.com> X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27828.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27828.006 X-TMASE-Result: 10--16.734900-10.000000 X-TMASE-MatchedRID: NGDYxnKYxb3IY6JevWs4vgPZZctd3P4B9LMB0hXFSeg6FHRWx2FGsI3c eRXYSJoDIvrftAIhWmJ8eC2pVr1wb6/Elphzpf1LGYJhRh6ssesfimmlcABuNyfJTn+dmnFQszW bbhESzfd+CxzcGwLNWAGDTGLhNrAfxzpH9vijA/wqIkSpQVZGCF/d6ediod7Y+32SXw3QiFwOvq z8x19fG2qJ0+VpCAVgyYyeAPTbBZYXHLPN9+q8ed9JA2lmQRNUHhysWPN3OzibKItl61J/yZ+in TK0bC9eKrauXd3MZDUD/dHyT/Xh7Q== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/2] syscalls/faccessat202: Add new testcase 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check various errnos for faccessat2(). Signed-off-by: Yang Xu --- runtest/syscalls | 1 + .../kernel/syscalls/faccessat2/.gitignore | 1 + .../kernel/syscalls/faccessat2/faccessat202.c | 105 ++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 testcases/kernel/syscalls/faccessat2/faccessat202.c diff --git a/runtest/syscalls b/runtest/syscalls index 02768c236..7af2842f3 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -218,6 +218,7 @@ faccessat01 faccessat01 #faccessat2 test cases faccessat201 faccessat201 +faccessat202 faccessat202 #fallocate test cases fallocate01 fallocate01 diff --git a/testcases/kernel/syscalls/faccessat2/.gitignore b/testcases/kernel/syscalls/faccessat2/.gitignore index 53f700bac..f58f045f4 100644 --- a/testcases/kernel/syscalls/faccessat2/.gitignore +++ b/testcases/kernel/syscalls/faccessat2/.gitignore @@ -1 +1,2 @@ /faccessat201 +/faccessat202 diff --git a/testcases/kernel/syscalls/faccessat2/faccessat202.c b/testcases/kernel/syscalls/faccessat2/faccessat202.c new file mode 100644 index 000000000..607a615e4 --- /dev/null +++ b/testcases/kernel/syscalls/faccessat2/faccessat202.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved. + * Copyright (c) Linux Test Project, 2003-2023 + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * Test basic error handling of faccessat2 syscall: + * + * - faccessat2() fails with EFAULT if pathname is a bad pathname point. + * - faccessat2() fails with EINVAL if flags is -1. + * - faccessat2() fails with EINVAL if mode is -1. + * - faccessat2() fails with EBADF if dirfd is -1. + * - faccessat2() fails with ENOTDIR if pathname is relative path to a + * file and dir_fd is file descriptor for this file. + * - faccessat2() fails with EACCES if flags is AT_EACCESS and not using + * the effective user and group IDs. + * + * Minimum Linux version required is v5.8. + */ + +#include + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "lapi/faccessat.h" + +#define TESTUSER "nobody" +#define TESTDIR "faccessat2dir" +#define RELPATH "faccessat2dir/faccessat2file" + +static int fd; +static int bad_fd = -1; +static int atcwd_fd = AT_FDCWD; +static char *bad_path; +static char *rel_path; + +static struct passwd *ltpuser; + +static struct tcase { + int *fd; + char **filename; + int mode; + int flags; + int exp_errno; +} tcases[] = { + {&atcwd_fd, &bad_path, R_OK, 0, EFAULT}, + {&atcwd_fd, &rel_path, R_OK, -1, EINVAL}, + {&atcwd_fd, &rel_path, -1, 0, EINVAL}, + {&bad_fd, &rel_path, R_OK, 0, EBADF}, + {&fd, &rel_path, R_OK, 0, ENOTDIR}, + {&atcwd_fd, &rel_path, R_OK, AT_EACCESS, EACCES}, +}; + +static void verify_faccessat2(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + + if (tc->exp_errno == EACCES) { + if (SAFE_FORK() == 0) { + SAFE_SETUID(ltpuser->pw_uid); + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename, + tc->mode, tc->flags), tc->exp_errno); + } + + tst_reap_children(); + } else { + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename, + tc->mode, tc->flags), tc->exp_errno); + } +} + +static void setup(void) +{ + SAFE_MKDIR(TESTDIR, 0666); + SAFE_TOUCH(RELPATH, 0444, NULL); + + fd = SAFE_OPEN(RELPATH, O_RDONLY); + bad_path = tst_get_bad_addr(NULL); + + ltpuser = SAFE_GETPWNAM(TESTUSER); +} + +static void cleanup(void) +{ + if (fd > -1) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .test = verify_faccessat2, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .bufs = (struct tst_buffers []) { + {&rel_path, .str = RELPATH}, + {}, + }, + .needs_tmpdir = 1, + .needs_root = 1, + .forks_child = 1, +};