Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/notify
Browse files Browse the repository at this point in the history
* 'for-linus' of git://git.infradead.org/users/eparis/notify:
  inotify: update the group mask on mark addition
  inotify: fix length reporting and size checking
  inotify: do not send a block of zeros when no pathname is available
  • Loading branch information
Linus Torvalds committed Aug 29, 2009
2 parents 825e1e2 + 750a887 commit 8442edc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions fs/notify/inotify/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ static struct fsnotify_event *get_one_event(struct fsnotify_group *group,

event = fsnotify_peek_notify_event(group);

event_size += roundup(event->name_len, event_size);
if (event->name_len)
event_size += roundup(event->name_len + 1, event_size);

if (event_size > count)
return ERR_PTR(-EINVAL);
Expand All @@ -180,7 +181,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
struct fsnotify_event_private_data *fsn_priv;
struct inotify_event_private_data *priv;
size_t event_size = sizeof(struct inotify_event);
size_t name_len;
size_t name_len = 0;

/* we get the inotify watch descriptor from the event private data */
spin_lock(&event->lock);
Expand All @@ -196,10 +197,12 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
inotify_free_event_priv(fsn_priv);
}

/* round up event->name_len so it is a multiple of event_size
/*
* round up event->name_len so it is a multiple of event_size
* plus an extra byte for the terminating '\0'.
*/
name_len = roundup(event->name_len + 1, event_size);
if (event->name_len)
name_len = roundup(event->name_len + 1, event_size);
inotify_event.len = name_len;

inotify_event.mask = inotify_mask_to_arg(event->mask);
Expand Down Expand Up @@ -325,8 +328,9 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
list_for_each_entry(holder, &group->notification_list, event_list) {
event = holder->event;
send_len += sizeof(struct inotify_event);
send_len += roundup(event->name_len,
sizeof(struct inotify_event));
if (event->name_len)
send_len += roundup(event->name_len + 1,
sizeof(struct inotify_event));
}
mutex_unlock(&group->notification_mutex);
ret = put_user(send_len, (int __user *) p);
Expand Down Expand Up @@ -587,6 +591,10 @@ static int inotify_new_watch(struct fsnotify_group *group,
/* match the ref from fsnotify_init_markentry() */
fsnotify_put_mark(&tmp_ientry->fsn_entry);

/* if this mark added a new event update the group mask */
if (mask & ~group->mask)
fsnotify_recalc_group_mask(group);

out_err:
if (ret < 0)
kmem_cache_free(inotify_inode_mark_cachep, tmp_ientry);
Expand Down

0 comments on commit 8442edc

Please sign in to comment.