From: Amir Goldstein <amir73il@gmail.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
ltp@lists.linux.it
Subject: [LTP] [PATCH v2 3/3] fanotify14: Test disallow sb/mount mark on anonymous pipe
Date: Sun, 16 Jul 2023 08:35:30 +0300 [thread overview]
Message-ID: <20230716053530.1629416-4-amir73il@gmail.com> (raw)
In-Reply-To: <20230716053530.1629416-1-amir73il@gmail.com>
This case was retroactively disallowed.
This test is meant to encourage the backporting of commit 69562eb0bd3e
("fanotify: disallow mount/sb marks on kernel internal pseudo fs") to
all stable kernels.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify14.c | 38 ++++++++++++++++++-
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
index 2c6f6afea..4596511f0 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify14.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
@@ -19,6 +19,9 @@
*
* ceaf69f8eadc fanotify: do not allow setting dirent events in mask of non-dir
* 8698e3bab4dd fanotify: refine the validation checks on non-dir inode mask
+ *
+ * The pipes test cases are regression tests for commit:
+ * 69562eb0bd3e fanotify: disallow mount/sb marks on kernel internal pseudo fs
*/
#define _GNU_SOURCE
@@ -40,6 +43,7 @@
#define FLAGS_DESC(flags) {(flags), (#flags)}
+static int pipes[2] = {-1, -1};
static int fanotify_fd;
static int fan_report_target_fid_unsupported;
static int ignore_mark_unsupported;
@@ -60,6 +64,7 @@ static struct test_case_t {
/* when mask.flags == 0, fanotify_init() is expected to fail */
struct test_case_flags_t mask;
int expected_errno;
+ int *pfd;
} test_cases[] = {
/* FAN_REPORT_FID without class FAN_CLASS_NOTIF is not valid */
{
@@ -216,6 +221,22 @@ static struct test_case_t {
.mask = FLAGS_DESC(FAN_OPEN),
.expected_errno = EINVAL,
},
+ /* mount mark on anonymous pipe is not valid */
+ {
+ .init = FLAGS_DESC(FAN_CLASS_NOTIF),
+ .mark = FLAGS_DESC(FAN_MARK_MOUNT),
+ .mask = { FAN_ACCESS, "anonymous pipe"},
+ .pfd = pipes,
+ .expected_errno = EINVAL,
+ },
+ /* filesystem mark on anonymous pipe is not valid */
+ {
+ .init = FLAGS_DESC(FAN_CLASS_NOTIF),
+ .mark = FLAGS_DESC(FAN_MARK_FILESYSTEM),
+ .mask = { FAN_ACCESS, "anonymous pipe"},
+ .pfd = pipes,
+ .expected_errno = EINVAL,
+ },
};
static void do_test(unsigned int number)
@@ -253,11 +274,17 @@ static void do_test(unsigned int number)
/* Set mark on non-dir only when expecting error ENOTDIR */
const char *path = tc->expected_errno == ENOTDIR ? FILE1 : MNTPOINT;
+ int dirfd = AT_FDCWD;
+
+ if (tc->pfd) {
+ dirfd = tc->pfd[0];
+ path = NULL;
+ }
- tst_res(TINFO, "Testing fanotify_mark(FAN_MARK_ADD | %s, %s)",
+ tst_res(TINFO, "Testing %s with %s",
tc->mark.desc, tc->mask.desc);
TST_EXP_FD_OR_FAIL(fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark.flags,
- tc->mask.flags, AT_FDCWD, path),
+ tc->mask.flags, dirfd, path),
tc->expected_errno);
/*
@@ -299,12 +326,18 @@ static void do_setup(void)
/* Create temporary test file to place marks on */
SAFE_FILE_PRINTF(FILE1, "0");
+ /* Create anonymous pipes to place marks on */
+ SAFE_PIPE2(pipes, O_CLOEXEC);
}
static void do_cleanup(void)
{
if (fanotify_fd > 0)
SAFE_CLOSE(fanotify_fd);
+ if (pipes[0] != -1)
+ SAFE_CLOSE(pipes[0]);
+ if (pipes[1] != -1)
+ SAFE_CLOSE(pipes[1]);
}
static struct tst_test test = {
@@ -319,6 +352,7 @@ static struct tst_test test = {
.tags = (const struct tst_tag[]) {
{"linux-git", "ceaf69f8eadc"},
{"linux-git", "8698e3bab4dd"},
+ {"linux-git", "69562eb0bd3e"},
{}
}
};
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-07-16 5:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-16 5:35 [LTP] [PATCH v2 0/3] Tests for fanotify on anonymous pipe Amir Goldstein
2023-07-16 5:35 ` [LTP] [PATCH v2 1/3] fanotify14: Use FAN_MARK_INODE semantic flag Amir Goldstein
2023-07-17 6:34 ` Petr Vorel
2023-07-16 5:35 ` [LTP] [PATCH v2 2/3] fanotify14: Use named initializers Amir Goldstein
2023-07-17 6:35 ` Petr Vorel
2023-07-16 5:35 ` Amir Goldstein [this message]
2023-07-17 6:38 ` [LTP] [PATCH v2 3/3] fanotify14: Test disallow sb/mount mark on anonymous pipe Petr Vorel
2023-07-17 6:44 ` [LTP] [PATCH v2 0/3] Tests for fanotify " 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=20230716053530.1629416-4-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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