From: Richard Palethorpe <rpalethorpe@suse.de>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] move_mount03: check allow to mount beneath top mount
Date: Tue, 14 Nov 2023 09:17:15 +0000 [thread overview]
Message-ID: <87zfzga7xj.fsf@suse.de> (raw)
In-Reply-To: <20230913101542.18550-1-wegao@suse.com>
Hello,
Wei Gao via ltp <ltp@lists.linux.it> writes:
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> include/lapi/fsmount.h | 4 ++
> runtest/syscalls | 1 +
> .../kernel/syscalls/move_mount/.gitignore | 1 +
> .../kernel/syscalls/move_mount/move_mount03.c | 63 +++++++++++++++++++
> 4 files changed, 69 insertions(+)
> create mode 100644 testcases/kernel/syscalls/move_mount/move_mount03.c
>
> diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
> index 07eb42ffa..216e966c7 100644
> --- a/include/lapi/fsmount.h
> +++ b/include/lapi/fsmount.h
> @@ -115,6 +115,10 @@ static inline int mount_setattr(int dirfd, const char *from_pathname, unsigned i
> }
> #endif /* HAVE_MOUNT_SETATTR */
>
> +#ifndef MOVE_MOUNT_BENEATH
> +#define MOVE_MOUNT_BENEATH 0x00000200
> +#endif /* MOVE_MOUNT_BENEATH */
> +
> /*
> * New headers added in kernel after 5.2 release, create them for old userspace.
> */
> diff --git a/runtest/syscalls b/runtest/syscalls
> index b1125dd75..04b758fd9 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -824,6 +824,7 @@ mount_setattr01 mount_setattr01
>
> move_mount01 move_mount01
> move_mount02 move_mount02
> +move_mount03 move_mount03
>
> move_pages01 move_pages01
> move_pages02 move_pages02
> diff --git a/testcases/kernel/syscalls/move_mount/.gitignore b/testcases/kernel/syscalls/move_mount/.gitignore
> index 83ae40145..ddfe10128 100644
> --- a/testcases/kernel/syscalls/move_mount/.gitignore
> +++ b/testcases/kernel/syscalls/move_mount/.gitignore
> @@ -1,2 +1,3 @@
> /move_mount01
> /move_mount02
> +/move_mount03
> diff --git a/testcases/kernel/syscalls/move_mount/move_mount03.c b/testcases/kernel/syscalls/move_mount/move_mount03.c
> new file mode 100644
> index 000000000..071fd984c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/move_mount/move_mount03.c
> @@ -0,0 +1,63 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Verify allow to mount beneath top mount
This should at least reference the following commit:
commit 6ac392815628f317fcfdca1a39df00b9cc4ebc8b
Author: Christian Brauner <brauner@kernel.org>
Date: Wed May 3 13:18:42 2023 +0200
fs: allow to mount beneath top mount
To be honest I am struggling to understand what all of this
does. However I think that I found some issues with the test which I
have noted below.
> + *
> + */
> +
> +#include <stdio.h>
> +
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +#include "lapi/sched.h"
> +
> +#define MNTPOINTR "mntpoint"
> +#define DIRA "LTP_DIR_A"
> +
> +static void run(void)
> +{
> + int fd;
> +
> + SAFE_UNSHARE(CLONE_NEWNS);
> + SAFE_MKDIR(DIRA, 0777);
> + SAFE_TOUCH(DIRA "/A", 0, NULL);
> + /* The parent mnt should be private if check MOVE_MOUNT_BENEATH */
> + SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
Is it necessary and safe to do this on root? It's not clear what effect
setting all mounts under the present "/" and namespace might have. I
guess it should be possible to create a mount to use as the parent that
is private?
> + SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
> + fd = SAFE_OPEN(DIRA, O_RDONLY | O_DIRECTORY);
Why do we open this directory? It seems both source and destination can
be paths.
Also it is never closed.
> +
> + TST_EXP_PASS(move_mount(fd, "", AT_FDCWD, MNTPOINT,
> + MOVE_MOUNT_BENEATH | MOVE_MOUNT_F_EMPTY_PATH));
> +
> + if (access(MNTPOINT "/A", F_OK) == 0)
So we have mounted mntpoint/LTP_DIR_A at mntpoint (or moved it there),
but we don't expect file A to be there?
> + tst_res(TFAIL, "mount beneath top mount failed");
> + else
> + tst_res(TPASS, "mount beneath top mount pass");
This message doesn't explain what the test is doing. You can probably
use TST_EXP_* here as well.
> +
> + if (tst_is_mounted_at_tmpdir(MNTPOINT))
> + SAFE_UMOUNT(MNTPOINT);
> +
> + if (access(MNTPOINT "/A", F_OK) == 0)
> + tst_res(TPASS, "mount beneath top mount pass");
> + else
> + tst_res(TFAIL, "mount beneath top mount failed");
> +
So if MNTPOINT is not under tmpdir we do nothing, but the test now
expects A to exist?
If we always unmount MNTPOINT then this should always fail because we
never created anything at mntpoint/A.
> + remove(DIRA "/A");
This should probably be SAFE_UNLINK.
> + SAFE_RMDIR(DIRA);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .needs_root = 1,
> + .format_device = 1,
> + .mntpoint = MNTPOINT,
> + .mount_device = 1,
> + .all_filesystems = 1,
> + .skip_filesystems = (const char *const []){"fuse", NULL},
> + .min_kver = "6.5.0"
> +};
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-11-14 11:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 10:15 [LTP] [PATCH v1] move_mount03: check allow to mount beneath top mount Wei Gao via ltp
2023-11-14 9:17 ` Richard Palethorpe [this message]
2023-12-26 15:11 ` Wei Gao via ltp
2023-12-27 0:04 ` [LTP] [PATCH v2] " Wei Gao via ltp
2023-12-27 14:26 ` Petr Vorel
2023-12-28 2:53 ` Wei Gao via ltp
2023-12-28 2:55 ` [LTP] [PATCH v3] " Wei Gao via ltp
2024-03-06 17:24 ` Martin Doucha
2024-03-20 7:43 ` Petr Vorel
2024-03-20 9:25 ` Martin Doucha
2024-03-20 9:54 ` Petr Vorel
2024-03-21 4:46 ` Petr Vorel
2024-03-22 11:20 ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-05-17 14:48 ` Martin Doucha
2024-06-03 7:38 ` Petr Vorel
2024-06-05 10:59 ` [LTP] [PATCH v5] " Wei Gao via ltp
2025-02-21 10:35 ` 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=87zfzga7xj.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=ltp@lists.linux.it \
--cc=wegao@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox