Skip to content

Commit b8a6c3a

Browse files
amir73iljankara
authored andcommitted
fanotify: create overflow event type
The special overflow event is allocated as struct fanotify_path_event, but with a null path. Use a special event type to identify the overflow event, so the helper fanotify_has_event_path() will always indicate a non null path. Allocating the overflow event doesn't need any of the fancy stuff in fanotify_alloc_event(), so create a simplified helper for allocating the overflow event. There is also no need to store and report the pid with an overflow event. Link: https://lore.kernel.org/r/[email protected] Suggested-by: Jan Kara <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 956235a commit b8a6c3a

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask,
344344
return fsnotify_data_inode(data, data_type);
345345
}
346346

347-
struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
348-
struct inode *inode, u32 mask,
349-
const void *data, int data_type,
350-
const struct qstr *file_name,
351-
__kernel_fsid_t *fsid)
347+
static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
348+
struct inode *inode, u32 mask,
349+
const void *data, int data_type,
350+
const struct qstr *file_name,
351+
__kernel_fsid_t *fsid)
352352
{
353353
struct fanotify_event *event = NULL;
354354
struct fanotify_fid_event *ffe = NULL;
@@ -426,8 +426,7 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
426426
* event queue, so event reported on parent is merged with event
427427
* reported on child when both directory and child watches exist.
428428
*/
429-
fsnotify_init_event(&event->fse, (unsigned long)id);
430-
event->mask = mask;
429+
fanotify_init_event(event, (unsigned long)id, mask);
431430
if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
432431
event->pid = get_pid(task_pid(current));
433432
else
@@ -443,15 +442,8 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
443442
fanotify_encode_fh(fanotify_event_dir_fh(event), id, gfp);
444443

445444
if (fanotify_event_has_path(event)) {
446-
struct path *p = fanotify_event_path(event);
447-
448-
if (path) {
449-
*p = *path;
450-
path_get(path);
451-
} else {
452-
p->mnt = NULL;
453-
p->dentry = NULL;
454-
}
445+
*fanotify_event_path(event) = *path;
446+
path_get(path);
455447
}
456448
out:
457449
memalloc_unuse_memcg();
@@ -640,6 +632,9 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event)
640632
case FANOTIFY_EVENT_TYPE_FID_NAME:
641633
fanotify_free_name_event(event);
642634
break;
635+
case FANOTIFY_EVENT_TYPE_OVERFLOW:
636+
kfree(event);
637+
break;
643638
default:
644639
WARN_ON_ONCE(1);
645640
}

fs/notify/fanotify/fanotify.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum fanotify_event_type {
6363
FANOTIFY_EVENT_TYPE_FID_NAME, /* variable length */
6464
FANOTIFY_EVENT_TYPE_PATH,
6565
FANOTIFY_EVENT_TYPE_PATH_PERM,
66+
FANOTIFY_EVENT_TYPE_OVERFLOW, /* struct fanotify_event */
6667
};
6768

6869
struct fanotify_event {
@@ -72,6 +73,14 @@ struct fanotify_event {
7273
struct pid *pid;
7374
};
7475

76+
static inline void fanotify_init_event(struct fanotify_event *event,
77+
unsigned long id, u32 mask)
78+
{
79+
fsnotify_init_event(&event->fse, id);
80+
event->mask = mask;
81+
event->pid = NULL;
82+
}
83+
7584
struct fanotify_fid_event {
7685
struct fanotify_event fae;
7786
__kernel_fsid_t fsid;
@@ -202,9 +211,3 @@ static inline struct path *fanotify_event_path(struct fanotify_event *event)
202211
else
203212
return NULL;
204213
}
205-
206-
struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
207-
struct inode *inode, u32 mask,
208-
const void *data, int data_type,
209-
const struct qstr *file_name,
210-
__kernel_fsid_t *fsid);

fs/notify/fanotify/fanotify_user.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,26 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
836836
FSNOTIFY_OBJ_TYPE_INODE, mask, flags, fsid);
837837
}
838838

839+
static struct fsnotify_event *fanotify_alloc_overflow_event(void)
840+
{
841+
struct fanotify_event *oevent;
842+
843+
oevent = kmalloc(sizeof(*oevent), GFP_KERNEL_ACCOUNT);
844+
if (!oevent)
845+
return NULL;
846+
847+
fanotify_init_event(oevent, 0, FS_Q_OVERFLOW);
848+
oevent->type = FANOTIFY_EVENT_TYPE_OVERFLOW;
849+
850+
return &oevent->fse;
851+
}
852+
839853
/* fanotify syscalls */
840854
SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
841855
{
842856
struct fsnotify_group *group;
843857
int f_flags, fd;
844858
struct user_struct *user;
845-
struct fanotify_event *oevent;
846859

847860
pr_debug("%s: flags=%x event_f_flags=%x\n",
848861
__func__, flags, event_f_flags);
@@ -897,13 +910,11 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
897910
atomic_inc(&user->fanotify_listeners);
898911
group->memcg = get_mem_cgroup_from_mm(current->mm);
899912

900-
oevent = fanotify_alloc_event(group, NULL, FS_Q_OVERFLOW, NULL,
901-
FSNOTIFY_EVENT_NONE, NULL, NULL);
902-
if (unlikely(!oevent)) {
913+
group->overflow_event = fanotify_alloc_overflow_event();
914+
if (unlikely(!group->overflow_event)) {
903915
fd = -ENOMEM;
904916
goto out_destroy_group;
905917
}
906-
group->overflow_event = &oevent->fse;
907918

908919
if (force_o_largefile())
909920
event_f_flags |= O_LARGEFILE;

0 commit comments

Comments
 (0)