Skip to content

Commit 7294fbd

Browse files
committed
Merge tag 'fsnotify_for_v5.1-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull fsnotify fixes from Jan Kara: "One inotify and one fanotify fix" * tag 'fsnotify_for_v5.1-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: fanotify: Allow copying of file handle to userspace inotify: Fix fsnotify_mark refcount leak in inotify_update_existing_watch()
2 parents 54c4901 + b2d22b6 commit 7294fbd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
208208
{
209209
struct fanotify_event_info_fid info = { };
210210
struct file_handle handle = { };
211+
unsigned char bounce[FANOTIFY_INLINE_FH_LEN], *fh;
211212
size_t fh_len = event->fh_len;
212213
size_t len = fanotify_event_info_len(event);
213214

@@ -233,7 +234,16 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
233234

234235
buf += sizeof(handle);
235236
len -= sizeof(handle);
236-
if (copy_to_user(buf, fanotify_event_fh(event), fh_len))
237+
/*
238+
* For an inline fh, copy through stack to exclude the copy from
239+
* usercopy hardening protections.
240+
*/
241+
fh = fanotify_event_fh(event);
242+
if (fh_len <= FANOTIFY_INLINE_FH_LEN) {
243+
memcpy(bounce, fh, fh_len);
244+
fh = bounce;
245+
}
246+
if (copy_to_user(buf, fh, fh_len))
237247
return -EFAULT;
238248

239249
/* Pad with 0's */

fs/notify/inotify/inotify_user.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
519519
fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
520520
if (!fsn_mark)
521521
return -ENOENT;
522-
else if (create)
523-
return -EEXIST;
522+
else if (create) {
523+
ret = -EEXIST;
524+
goto out;
525+
}
524526

525527
i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
526528

@@ -548,6 +550,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
548550
/* return the wd */
549551
ret = i_mark->wd;
550552

553+
out:
551554
/* match the get from fsnotify_find_mark() */
552555
fsnotify_put_mark(fsn_mark);
553556

0 commit comments

Comments
 (0)