From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Matthew Bobrowski <mbobrowski@mbobrowski.org>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 4/5] fanotify: add support for exclusive create of mark
Date: Mon, 7 Mar 2022 17:57:40 +0200 [thread overview]
Message-ID: <20220307155741.1352405-5-amir73il@gmail.com> (raw)
In-Reply-To: <20220307155741.1352405-1-amir73il@gmail.com>
Similar to inotify's IN_MARK_CREATE, adding an fanotify mark with flag
FAN_MARK_CREATE will fail with error EEXIST if an fanotify mark already
exists on the object.
Unlike inotify's IN_MARK_CREATE, FAN_MARK_CREATE has to supplied in
combination with FAN_MARK_ADD (FAN_MARK_ADD is like inotify_add_watch()
and the behavior of IN_MARK_ADD is the default for fanotify_mark()).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fanotify/fanotify_user.c | 13 ++++++++++---
include/linux/fanotify.h | 8 +++++---
include/uapi/linux/fanotify.h | 1 +
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 9b32b76a9c30..99c5ced6abd8 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -1185,6 +1185,9 @@ static int fanotify_add_mark(struct fsnotify_group *group,
mutex_unlock(&group->mark_mutex);
return PTR_ERR(fsn_mark);
}
+ } else if (flags & FAN_MARK_CREATE) {
+ ret = -EEXIST;
+ goto out;
}
/*
@@ -1510,6 +1513,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
__kernel_fsid_t __fsid, *fsid = NULL;
u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS;
unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS;
+ unsigned int mark_cmd = flags & FANOTIFY_MARK_CMD_BITS;
bool ignored = flags & FAN_MARK_IGNORED_MASK;
unsigned int obj_type, fid_mode;
u32 umask = 0;
@@ -1539,7 +1543,10 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
return -EINVAL;
}
- switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) {
+ if (flags & FAN_MARK_CREATE && mark_cmd != FAN_MARK_ADD)
+ return -EINVAL;
+
+ switch (mark_cmd) {
case FAN_MARK_ADD:
case FAN_MARK_REMOVE:
if (!mask)
@@ -1671,7 +1678,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
}
/* create/update an inode mark */
- switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) {
+ switch (mark_cmd) {
case FAN_MARK_ADD:
if (mark_type == FAN_MARK_MOUNT)
ret = fanotify_add_vfsmount_mark(group, mnt, mask,
@@ -1749,7 +1756,7 @@ static int __init fanotify_user_setup(void)
BUILD_BUG_ON(FANOTIFY_INIT_FLAGS & FANOTIFY_INTERNAL_GROUP_FLAGS);
BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 12);
- BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9);
+ BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 10);
fanotify_mark_cache = KMEM_CACHE(fsnotify_mark,
SLAB_PANIC|SLAB_ACCOUNT);
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h
index 419cadcd7ff5..780f4b17d4c9 100644
--- a/include/linux/fanotify.h
+++ b/include/linux/fanotify.h
@@ -59,14 +59,16 @@
#define FANOTIFY_MARK_TYPE_BITS (FAN_MARK_INODE | FAN_MARK_MOUNT | \
FAN_MARK_FILESYSTEM)
+#define FANOTIFY_MARK_CMD_BITS (FAN_MARK_ADD | FAN_MARK_REMOVE | \
+ FAN_MARK_FLUSH)
+
#define FANOTIFY_MARK_FLAGS (FANOTIFY_MARK_TYPE_BITS | \
- FAN_MARK_ADD | \
- FAN_MARK_REMOVE | \
+ FANOTIFY_MARK_CMD_BITS | \
FAN_MARK_DONT_FOLLOW | \
FAN_MARK_ONLYDIR | \
FAN_MARK_IGNORED_MASK | \
FAN_MARK_IGNORED_SURV_MODIFY | \
- FAN_MARK_FLUSH)
+ FAN_MARK_CREATE)
/*
* Events that can be reported with data type FSNOTIFY_EVENT_PATH.
diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h
index e8ac38cc2fd6..c41feac21fe9 100644
--- a/include/uapi/linux/fanotify.h
+++ b/include/uapi/linux/fanotify.h
@@ -82,6 +82,7 @@
#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040
#define FAN_MARK_FLUSH 0x00000080
/* FAN_MARK_FILESYSTEM is 0x00000100 */
+#define FAN_MARK_CREATE 0x00000200
/* These are NOT bitwise flags. Both bits can be used togther. */
#define FAN_MARK_INODE 0x00000000
--
2.25.1
next prev parent reply other threads:[~2022-03-07 15:58 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-07 15:57 [PATCH 0/5] Volatile fanotify marks Amir Goldstein
2022-03-07 15:57 ` [PATCH 1/5] fsnotify: move inotify control flags to mark flags Amir Goldstein
2022-03-17 14:25 ` Jan Kara
2022-03-17 15:12 ` Amir Goldstein
2022-03-07 15:57 ` [PATCH 2/5] fsnotify: pass flags argument to fsnotify_add_mark() Amir Goldstein
2022-03-07 15:57 ` [PATCH 3/5] fsnotify: allow adding an inode mark without pinning inode Amir Goldstein
2022-03-17 15:27 ` Jan Kara
2022-03-18 6:23 ` Amir Goldstein
2022-03-20 13:06 ` Amir Goldstein
2022-03-07 15:57 ` Amir Goldstein [this message]
2022-03-17 15:34 ` [PATCH 4/5] fanotify: add support for exclusive create of mark Jan Kara
2022-03-17 15:45 ` Jan Kara
2022-03-18 3:13 ` Amir Goldstein
2022-03-18 10:32 ` Jan Kara
2022-03-18 11:04 ` Amir Goldstein
2022-03-18 14:09 ` Jan Kara
2022-03-18 16:06 ` Amir Goldstein
2022-03-20 13:00 ` Amir Goldstein
2022-03-22 16:44 ` direct reclaim of fanotify evictable marks Amir Goldstein
2022-03-23 9:16 ` Amir Goldstein
2022-03-21 9:09 ` [PATCH 4/5] fanotify: add support for exclusive create of mark Jan Kara
2022-03-07 15:57 ` [PATCH 5/5] fanotify: add support for "volatile" inode marks Amir Goldstein
2022-03-17 14:12 ` [PATCH 0/5] Volatile fanotify marks Jan Kara
2022-03-17 15:14 ` Amir Goldstein
2022-03-20 12:54 ` Amir Goldstein
2022-06-13 5:40 ` LTP test for fanotify evictable marks Amir Goldstein
2022-06-13 11:59 ` Jan Kara
2022-06-13 14:16 ` Amir Goldstein
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=20220307155741.1352405-5-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mbobrowski@mbobrowski.org \
/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;
as well as URLs for NNTP newsgroup(s).