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 v3 09/11] fanotify: record either old name new name or both for FAN_RENAME
Date: Mon, 29 Nov 2021 22:15:35 +0200 [thread overview]
Message-ID: <20211129201537.1932819-10-amir73il@gmail.com> (raw)
In-Reply-To: <20211129201537.1932819-1-amir73il@gmail.com>
We do not want to report the dirfid+name of a directory whose
inode/sb are not watched, because watcher may not have permissions
to see the directory content.
Use an internal iter_info to indicate to fanotify_alloc_event()
which marks of this group are watching FAN_RENAME, so it can decide
if we need to record only the old parent+name, new parent+name or both.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fanotify/fanotify.c | 59 +++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 13 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index db81eab90544..050f0fa79079 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -284,6 +284,7 @@ static int fanotify_get_response(struct fsnotify_group *group,
*/
static u32 fanotify_group_event_mask(struct fsnotify_group *group,
struct fsnotify_iter_info *iter_info,
+ struct fsnotify_iter_info *match_info,
u32 event_mask, const void *data,
int data_type, struct inode *dir)
{
@@ -335,6 +336,9 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
continue;
marks_mask |= mark->mask;
+
+ /* Record the mark types of this group that matched the event */
+ fsnotify_iter_set_report_type(match_info, type);
}
test_mask = event_mask & marks_mask & ~marks_ignored_mask;
@@ -701,11 +705,12 @@ static struct fanotify_event *fanotify_alloc_error_event(
return &fee->fae;
}
-static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
- u32 mask, const void *data,
- int data_type, struct inode *dir,
- const struct qstr *file_name,
- __kernel_fsid_t *fsid)
+static struct fanotify_event *fanotify_alloc_event(
+ struct fsnotify_group *group,
+ u32 mask, const void *data, int data_type,
+ struct inode *dir, const struct qstr *file_name,
+ __kernel_fsid_t *fsid,
+ struct fsnotify_iter_info *match_info)
{
struct fanotify_event *event = NULL;
gfp_t gfp = GFP_KERNEL_ACCOUNT;
@@ -753,13 +758,39 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
}
/*
- * In the special case of FAN_RENAME event, we record both
- * old and new parent+name.
+ * In the special case of FAN_RENAME event, use the match_info
+ * to determine if we need to report only the old parent+name,
+ * only the new parent+name or both.
* 'dirid' and 'file_name' are the old parent+name and
* 'moved' has the new parent+name.
*/
- if (mask & FAN_RENAME)
- moved = fsnotify_data_dentry(data, data_type);
+ if (mask & FAN_RENAME) {
+ bool report_old, report_new;
+
+ if (WARN_ON_ONCE(!(match_info.report_mask)))
+ return NULL;
+
+ /* Report both old and new parent+name if sb watching */
+ report_old = report_new =
+ fsnotify_iter_should_report_type(match_info,
+ FSNOTIFY_ITER_TYPE_SB);
+ report_old |=
+ fsnotify_iter_should_report_type(match_info,
+ FSNOTIFY_ITER_TYPE_INODE);
+ report_new |=
+ fsnotify_iter_should_report_type(match_info,
+ FSNOTIFY_ITER_TYPE_INODE2);
+
+ if (!report_old) {
+ /* Do not report old parent+name */
+ dirid = NULL;
+ file_name = NULL;
+ }
+ if (report_new) {
+ /* Report new parent+name */
+ moved = fsnotify_data_dentry(data, data_type);
+ }
+ }
}
/*
@@ -872,6 +903,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
struct fanotify_event *event;
struct fsnotify_event *fsn_event;
__kernel_fsid_t fsid = {};
+ struct fsnotify_iter_info match_info = {};
BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS);
BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY);
@@ -897,12 +929,13 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 20);
- mask = fanotify_group_event_mask(group, iter_info, mask, data,
- data_type, dir);
+ mask = fanotify_group_event_mask(group, iter_info, &match_info,
+ mask, data, data_type, dir);
if (!mask)
return 0;
- pr_debug("%s: group=%p mask=%x\n", __func__, group, mask);
+ pr_debug("%s: group=%p mask=%x report_mask=%x\n", __func__,
+ group, mask, match_info.report_mask);
if (fanotify_is_perm_event(mask)) {
/*
@@ -921,7 +954,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
}
event = fanotify_alloc_event(group, mask, data, data_type, dir,
- file_name, &fsid);
+ file_name, &fsid, &match_info);
ret = -ENOMEM;
if (unlikely(!event)) {
/*
--
2.33.1
next prev parent reply other threads:[~2021-11-29 22:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-29 20:15 [PATCH v3 00/11] Extend fanotify dirent events Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 01/11] fsnotify: clarify object type argument Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 02/11] fsnotify: separate mark iterator type from object type enum Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 03/11] fanotify: introduce group flag FAN_REPORT_TARGET_FID Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 04/11] fsnotify: generate FS_RENAME event with rich information Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 05/11] fanotify: use macros to get the offset to fanotify_info buffer Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 06/11] fanotify: use helpers to parcel " Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 07/11] fanotify: support secondary dir fh and name in fanotify_info Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 08/11] fanotify: record old and new parent and name in FAN_RENAME event Amir Goldstein
2021-11-29 20:15 ` Amir Goldstein [this message]
2021-11-29 20:15 ` [PATCH v3 10/11] fanotify: report old and/or new parent+name " Amir Goldstein
2021-11-29 20:15 ` [PATCH v3 11/11] fanotify: wire up " Amir Goldstein
2021-12-15 17:45 ` [PATCH v3 00/11] Extend fanotify dirent events Jan Kara
2021-12-15 18:49 ` 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=20211129201537.1932819-10-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).