Skip to content

Commit d766b55

Browse files
amir73iljankara
authored andcommitted
fanotify: prepare to report both parent and child fid's
For some events, we are going to report both child and parent fid's, so pass fsid and file handle as arguments to copy_fid_to_user(), which is going to be called with parent and child file handles. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 9e2ba2c commit d766b55

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,21 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
5252

5353
#define FANOTIFY_EVENT_ALIGN 4
5454

55+
static int fanotify_fid_info_len(int fh_len)
56+
{
57+
return roundup(sizeof(struct fanotify_event_info_fid) +
58+
sizeof(struct file_handle) + fh_len,
59+
FANOTIFY_EVENT_ALIGN);
60+
}
61+
5562
static int fanotify_event_info_len(struct fanotify_event *event)
5663
{
5764
int fh_len = fanotify_event_object_fh_len(event);
5865

5966
if (!fh_len)
6067
return 0;
6168

62-
return roundup(sizeof(struct fanotify_event_info_fid) +
63-
sizeof(struct file_handle) + fh_len,
64-
FANOTIFY_EVENT_ALIGN);
69+
return fanotify_fid_info_len(fh_len);
6570
}
6671

6772
/*
@@ -199,14 +204,14 @@ static int process_access_response(struct fsnotify_group *group,
199204
return -ENOENT;
200205
}
201206

202-
static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
207+
static int copy_fid_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
208+
char __user *buf)
203209
{
204210
struct fanotify_event_info_fid info = { };
205211
struct file_handle handle = { };
206212
unsigned char bounce[FANOTIFY_INLINE_FH_LEN], *fh_buf;
207-
struct fanotify_fh *fh = fanotify_event_object_fh(event);
208213
size_t fh_len = fh->len;
209-
size_t len = fanotify_event_info_len(event);
214+
size_t len = fanotify_fid_info_len(fh_len);
210215

211216
if (!len)
212217
return 0;
@@ -217,7 +222,7 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
217222
/* Copy event info fid header followed by vaiable sized file handle */
218223
info.hdr.info_type = FAN_EVENT_INFO_TYPE_FID;
219224
info.hdr.len = len;
220-
info.fsid = *fanotify_event_fsid(event);
225+
info.fsid = *fsid;
221226
if (copy_to_user(buf, &info, sizeof(info)))
222227
return -EFAULT;
223228

@@ -296,7 +301,9 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
296301
if (f) {
297302
fd_install(fd, f);
298303
} else if (fanotify_event_has_fid(event)) {
299-
ret = copy_fid_to_user(event, buf + FAN_EVENT_METADATA_LEN);
304+
ret = copy_fid_to_user(fanotify_event_fsid(event),
305+
fanotify_event_object_fh(event),
306+
buf + FAN_EVENT_METADATA_LEN);
300307
if (ret < 0)
301308
return ret;
302309
}

0 commit comments

Comments
 (0)