Skip to content

Commit

Permalink
Merge tag 'fsnotify_for_v5.1-rc2' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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()
  • Loading branch information
torvalds committed Mar 21, 2019
2 parents 54c4901 + b2d22b6 commit 7294fbd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 11 additions & 1 deletion fs/notify/fanotify/fanotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
{
struct fanotify_event_info_fid info = { };
struct file_handle handle = { };
unsigned char bounce[FANOTIFY_INLINE_FH_LEN], *fh;
size_t fh_len = event->fh_len;
size_t len = fanotify_event_info_len(event);

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

buf += sizeof(handle);
len -= sizeof(handle);
if (copy_to_user(buf, fanotify_event_fh(event), fh_len))
/*
* For an inline fh, copy through stack to exclude the copy from
* usercopy hardening protections.
*/
fh = fanotify_event_fh(event);
if (fh_len <= FANOTIFY_INLINE_FH_LEN) {
memcpy(bounce, fh, fh_len);
fh = bounce;
}
if (copy_to_user(buf, fh, fh_len))
return -EFAULT;

/* Pad with 0's */
Expand Down
7 changes: 5 additions & 2 deletions fs/notify/inotify/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
if (!fsn_mark)
return -ENOENT;
else if (create)
return -EEXIST;
else if (create) {
ret = -EEXIST;
goto out;
}

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

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

out:
/* match the get from fsnotify_find_mark() */
fsnotify_put_mark(fsn_mark);

Expand Down

0 comments on commit 7294fbd

Please sign in to comment.