From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5 4/5] Add fchmodat2_01 test
Date: Fri, 2 Aug 2024 10:47:27 +0200 [thread overview]
Message-ID: <20240802084727.GA1602775@pevik> (raw)
In-Reply-To: <20240802-fchmodat2-v5-4-bff2ec1a4f06@suse.com>
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> This test verifies that fchmodat2() syscall is properly working with
> AT_SYMLINK_NOFOLLOW on regular files. When AT_SYMLINK_NOFOLLOW is used
> on symbolic links instead, we check for EOPNOTSUPP, since the feature is
> not implemented for VFS.
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> runtest/syscalls | 2 +
> testcases/kernel/syscalls/fchmodat2/.gitignore | 1 +
> testcases/kernel/syscalls/fchmodat2/Makefile | 7 ++
> testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 123 +++++++++++++++++++++
> 4 files changed, 133 insertions(+)
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 9b3cba667..50298d01e 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -270,6 +270,8 @@ fchmod06 fchmod06
> fchmodat01 fchmodat01
> fchmodat02 fchmodat02
> +fchmodat2_01 fchmodat2_01
> +
> fchown01 fchown01
> fchown01_16 fchown01_16
> fchown02 fchown02
> diff --git a/testcases/kernel/syscalls/fchmodat2/.gitignore b/testcases/kernel/syscalls/fchmodat2/.gitignore
> new file mode 100644
> index 000000000..47d5e2427
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/.gitignore
> @@ -0,0 +1 @@
> +fchmodat2_01
> diff --git a/testcases/kernel/syscalls/fchmodat2/Makefile b/testcases/kernel/syscalls/fchmodat2/Makefile
> new file mode 100644
> index 000000000..8cf1b9024
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> +
> +top_srcdir ?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> new file mode 100644
> index 000000000..d12c4a8fd
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that fchmodat2() syscall is properly working with
> + * regular files, symbolic links and directories. AT_SYMLINK_NOFOLLOW is a
> + * special feature that is not enabled in VFS for symbolic links, so we only
> + * verify that EOPNOTSUPP is correctly raised when used on those particular
> + * files.
If you don't mind, I'll add here explicit note that change done in 5d1f903f75a8.
> + */
> +
> +#include "tst_test.h"
> +#include "tst_safe_file_at.h"
> +#include "lapi/fcntl.h"
> +#include "lapi/stat.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FNAME "myfile"
> +#define SNAME "symlink"
> +#define DNAME "mydir"
> +#define DNAME_PATH MNTPOINT"/"DNAME
> +
> +static int fd_dir = -1;
> +
> +static void verify_mode(int dirfd, const char *path, mode_t mode)
> +{
> + struct stat st;
> +
> + SAFE_FSTATAT(dirfd, path, &st, AT_SYMLINK_NOFOLLOW);
> + TST_EXP_EQ_LI(st.st_mode, mode);
> +}
> +
> +static void test_regular_file(void)
> +{
> + tst_res(TINFO, "Using regular files");
> +
> + SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
> +
> + SAFE_FCHMODAT2(fd_dir, FNAME, 0700, 0);
> + verify_mode(fd_dir, FNAME, S_IFREG | 0700);
> +
> + SAFE_FCHMODAT2(fd_dir, FNAME, 0700, AT_SYMLINK_NOFOLLOW);
> + verify_mode(fd_dir, FNAME, S_IFREG | 0700);
> +}
> +
> +static void test_symbolic_link(void)
> +{
> + tst_res(TINFO, "Using symbolic link");
> +
> + SAFE_FCHMODAT2(fd_dir, SNAME, 0700, 0);
> + verify_mode(fd_dir, FNAME, S_IFREG | 0700);
> + verify_mode(fd_dir, SNAME, S_IFLNK | 0777);
> +
> + if (tst_kvercmp(6, 6, 0)) {
> + TST_EXP_FAIL(tst_syscall(__NR_fchmodat2,
> + fd_dir, SNAME, 0640, AT_SYMLINK_NOFOLLOW),
> + EOPNOTSUPP);
> + }
I wrote later this is wrong, because the change was backported to all active
stable/LTS trees. We should expect this functionality on all kernels
(tested on 6.6.15, 6.9.9, 6.10.1).
Also, I hesitated, whether we should check AT_SYMLINK_NOFOLLOW also in
safe_fchmodat2(), but we can probably ignore that.
I can change it before merge.
> +}
> +
> +static void test_empty_folder(void)
> +{
> + tst_res(TINFO, "Using empty folder");
> +
> + int fd;
> +
> + SAFE_CHMOD(DNAME_PATH, 0640);
> + fd = SAFE_OPEN(DNAME_PATH, O_PATH | O_DIRECTORY, 0640);
> +
> + SAFE_FCHMODAT2(fd, "", 0777, AT_EMPTY_PATH);
> + verify_mode(fd_dir, DNAME, S_IFDIR | 0777);
> +
> + SAFE_CLOSE(fd);
> +}
> +
> +static void run(void)
> +{
> + test_regular_file();
> + test_empty_folder();
> + test_symbolic_link();
> +}
> +
> +static void setup(void)
> +{
> + fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
> +
> + if (access(DNAME_PATH, F_OK) == -1)
> + SAFE_MKDIR(DNAME_PATH, 0640);
> +
> + SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
> + SAFE_SYMLINKAT(FNAME, fd_dir, SNAME);
> +}
> +
> +static void cleanup(void)
> +{
> + SAFE_UNLINKAT(fd_dir, SNAME, 0);
> + SAFE_RMDIR(DNAME_PATH);
> +
> + if (fd_dir != -1)
> + SAFE_CLOSE(fd_dir);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_root = 1,
> + .mntpoint = MNTPOINT,
> + .format_device = 1,
> + .all_filesystems = 1,
> + .skip_filesystems = (const char *const []) {
> + "fuse",
> + NULL
> + },
You were faster than I managed to write. IMHO skipping fuse is not needed.
IMHO it was broken due EOPNOTSUPP.
With these 2 changes:
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "5d1f903f75a8"},
> + {}
> + }
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-08-02 8:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 8:23 [LTP] [PATCH v5 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-08-02 8:23 ` [LTP] [PATCH v5 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
2024-08-02 9:47 ` Petr Vorel
2024-08-02 9:48 ` Cyril Hrubis
2024-08-02 10:02 ` Petr Vorel
2024-08-02 10:39 ` Andrea Cervesato via ltp
2024-08-02 8:23 ` [LTP] [PATCH v5 2/5] Add fchmodat2 syscalls definitions Andrea Cervesato
2024-08-02 9:49 ` Petr Vorel
2024-08-02 8:23 ` [LTP] [PATCH v5 3/5] Add fchmodat2 fallback definition Andrea Cervesato
2024-08-02 9:55 ` Petr Vorel
2024-08-02 10:38 ` Andrea Cervesato via ltp
2024-08-02 10:57 ` Petr Vorel
2024-08-02 8:23 ` [LTP] [PATCH v5 4/5] Add fchmodat2_01 test Andrea Cervesato
2024-08-02 8:47 ` Petr Vorel [this message]
2024-08-02 8:23 ` [LTP] [PATCH v5 5/5] Add fchmodat2_02 test Andrea Cervesato
2024-08-02 10:33 ` Petr Vorel
2024-08-02 9:58 ` [LTP] [PATCH v5 0/5] Add fchmodat2 testing suite Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240802084727.GA1602775@pevik \
--to=pvorel@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.