Skip to content

Commit 4638e0f

Browse files
amir73ilgregkh
authored andcommitted
fsnotify: replace inode pointer with an object id
[ Upstream commit dfc2d25 ] The event inode field is used only for comparison in queue merges and cannot be dereferenced after handle_event(), because it does not hold a refcount on the inode. Replace it with an abstract id to do the same thing. Link: https://lore.kernel.org/r/20200319151022.31456-8-amir73il@gmail.com Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0344752 commit 4638e0f

4 files changed

Lines changed: 8 additions & 9 deletions

File tree

fs/notify/fanotify/fanotify.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static bool should_merge(struct fsnotify_event *old_fsn,
2626
old = FANOTIFY_E(old_fsn);
2727
new = FANOTIFY_E(new_fsn);
2828

29-
if (old_fsn->inode != new_fsn->inode || old->pid != new->pid ||
29+
if (old_fsn->objectid != new_fsn->objectid || old->pid != new->pid ||
3030
old->fh_type != new->fh_type || old->fh_len != new->fh_len)
3131
return false;
3232

@@ -314,7 +314,7 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
314314
if (!event)
315315
goto out;
316316
init: __maybe_unused
317-
fsnotify_init_event(&event->fse, inode);
317+
fsnotify_init_event(&event->fse, (unsigned long)inode);
318318
event->mask = mask;
319319
if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
320320
event->pid = get_pid(task_pid(current));

fs/notify/inotify/inotify_fsnotify.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool event_compare(struct fsnotify_event *old_fsn,
3939
if (old->mask & FS_IN_IGNORED)
4040
return false;
4141
if ((old->mask == new->mask) &&
42-
(old_fsn->inode == new_fsn->inode) &&
42+
(old_fsn->objectid == new_fsn->objectid) &&
4343
(old->name_len == new->name_len) &&
4444
(!old->name_len || !strcmp(old->name, new->name)))
4545
return true;
@@ -118,7 +118,7 @@ int inotify_handle_event(struct fsnotify_group *group,
118118
mask &= ~IN_ISDIR;
119119

120120
fsn_event = &event->fse;
121-
fsnotify_init_event(fsn_event, inode);
121+
fsnotify_init_event(fsn_event, (unsigned long)inode);
122122
event->mask = mask;
123123
event->wd = i_mark->wd;
124124
event->sync_cookie = cookie;

fs/notify/inotify/inotify_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ static struct fsnotify_group *inotify_new_group(unsigned int max_events)
635635
return ERR_PTR(-ENOMEM);
636636
}
637637
group->overflow_event = &oevent->fse;
638-
fsnotify_init_event(group->overflow_event, NULL);
638+
fsnotify_init_event(group->overflow_event, 0);
639639
oevent->mask = FS_Q_OVERFLOW;
640640
oevent->wd = -1;
641641
oevent->sync_cookie = 0;

include/linux/fsnotify_backend.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ struct fsnotify_ops {
133133
*/
134134
struct fsnotify_event {
135135
struct list_head list;
136-
/* inode may ONLY be dereferenced during handle_event(). */
137-
struct inode *inode; /* either the inode the event happened to or its parent */
136+
unsigned long objectid; /* identifier for queue merges */
138137
};
139138

140139
/*
@@ -500,10 +499,10 @@ extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info);
500499
extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info);
501500

502501
static inline void fsnotify_init_event(struct fsnotify_event *event,
503-
struct inode *inode)
502+
unsigned long objectid)
504503
{
505504
INIT_LIST_HEAD(&event->list);
506-
event->inode = inode;
505+
event->objectid = objectid;
507506
}
508507

509508
#else

0 commit comments

Comments
 (0)