blob: 6c80083a984fc192ebc73bad2a2edc86b4c25e11 [file] [log] [blame]
Andreas Gruenbacher33d3dff2009-12-17 21:24:29 -05001#include <linux/fanotify.h>
Eric Paris11637e42009-12-17 21:24:25 -05002#include <linux/fcntl.h>
Eric Paris2a3edf82009-12-17 21:24:26 -05003#include <linux/file.h>
Eric Paris11637e42009-12-17 21:24:25 -05004#include <linux/fs.h>
Eric Paris52c923d2009-12-17 21:24:26 -05005#include <linux/anon_inodes.h>
Eric Paris11637e42009-12-17 21:24:25 -05006#include <linux/fsnotify_backend.h>
Eric Paris2a3edf82009-12-17 21:24:26 -05007#include <linux/init.h>
Eric Parisa1014f12009-12-17 21:24:26 -05008#include <linux/mount.h>
Eric Paris2a3edf82009-12-17 21:24:26 -05009#include <linux/namei.h>
Eric Parisa1014f12009-12-17 21:24:26 -050010#include <linux/poll.h>
Eric Paris11637e42009-12-17 21:24:25 -050011#include <linux/security.h>
12#include <linux/syscalls.h>
Tejun Heoe4e047a2010-05-20 01:36:28 +100013#include <linux/slab.h>
Eric Paris2a3edf82009-12-17 21:24:26 -050014#include <linux/types.h>
Eric Parisa1014f12009-12-17 21:24:26 -050015#include <linux/uaccess.h>
Al Viro91c2e0b2013-03-05 20:10:59 -050016#include <linux/compat.h>
Eric Parisa1014f12009-12-17 21:24:26 -050017
18#include <asm/ioctls.h>
Eric Paris11637e42009-12-17 21:24:25 -050019
Al Viroc63181e2011-11-25 02:35:16 -050020#include "../../mount.h"
Cyrill Gorcunovbe771962012-12-17 16:05:12 -080021#include "../fdinfo.h"
Al Viroc63181e2011-11-25 02:35:16 -050022
Eric Paris2529a0d2010-10-28 17:21:57 -040023#define FANOTIFY_DEFAULT_MAX_EVENTS 16384
Eric Parise7099d82010-10-28 17:21:57 -040024#define FANOTIFY_DEFAULT_MAX_MARKS 8192
Eric Paris4afeff82010-10-28 17:21:58 -040025#define FANOTIFY_DEFAULT_MAX_LISTENERS 128
Eric Paris2529a0d2010-10-28 17:21:57 -040026
Andreas Gruenbacher33d3dff2009-12-17 21:24:29 -050027extern const struct fsnotify_ops fanotify_fsnotify_ops;
Eric Paris11637e42009-12-17 21:24:25 -050028
Eric Paris2a3edf82009-12-17 21:24:26 -050029static struct kmem_cache *fanotify_mark_cache __read_mostly;
Eric Parisb2d87902009-12-17 21:24:34 -050030static struct kmem_cache *fanotify_response_event_cache __read_mostly;
31
32struct fanotify_response_event {
33 struct list_head list;
34 __s32 fd;
35 struct fsnotify_event *event;
36};
Eric Paris2a3edf82009-12-17 21:24:26 -050037
Eric Parisa1014f12009-12-17 21:24:26 -050038/*
39 * Get an fsnotify notification event if one exists and is small
40 * enough to fit in "count". Return an error pointer if the count
41 * is not large enough.
42 *
43 * Called with the group->notification_mutex held.
44 */
45static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
46 size_t count)
47{
48 BUG_ON(!mutex_is_locked(&group->notification_mutex));
49
50 pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
51
52 if (fsnotify_notify_queue_is_empty(group))
53 return NULL;
54
55 if (FAN_EVENT_METADATA_LEN > count)
56 return ERR_PTR(-EINVAL);
57
58 /* held the notification_mutex the whole time, so this is the
59 * same event we peeked above */
60 return fsnotify_remove_notify_event(group);
61}
62
Al Viro352e3b22012-08-19 12:30:45 -040063static int create_fd(struct fsnotify_group *group,
64 struct fsnotify_event *event,
65 struct file **file)
Eric Parisa1014f12009-12-17 21:24:26 -050066{
67 int client_fd;
Eric Parisa1014f12009-12-17 21:24:26 -050068 struct file *new_file;
69
Andreas Gruenbacher22aa4252009-12-17 21:24:26 -050070 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
Eric Parisa1014f12009-12-17 21:24:26 -050071
72 client_fd = get_unused_fd();
73 if (client_fd < 0)
74 return client_fd;
75
Linus Torvalds20696012010-08-12 14:23:04 -070076 if (event->data_type != FSNOTIFY_EVENT_PATH) {
Eric Parisa1014f12009-12-17 21:24:26 -050077 WARN_ON(1);
78 put_unused_fd(client_fd);
79 return -EINVAL;
80 }
81
82 /*
83 * we need a new file handle for the userspace program so it can read even if it was
84 * originally opened O_WRONLY.
85 */
Eric Parisa1014f12009-12-17 21:24:26 -050086 /* it's possible this event was an overflow event. in that case dentry and mnt
87 * are NULL; That's fine, just don't call dentry open */
Al Viro765927b2012-06-26 21:58:53 +040088 if (event->path.dentry && event->path.mnt)
89 new_file = dentry_open(&event->path,
Eric Paris80af2582010-07-28 10:18:37 -040090 group->fanotify_data.f_flags | FMODE_NONOTIFY,
Eric Parisa1014f12009-12-17 21:24:26 -050091 current_cred());
92 else
93 new_file = ERR_PTR(-EOVERFLOW);
94 if (IS_ERR(new_file)) {
95 /*
96 * we still send an event even if we can't open the file. this
97 * can happen when say tasks are gone and we try to open their
98 * /proc files or we try to open a WRONLY file like in sysfs
99 * we just send the errno to userspace since there isn't much
100 * else we can do.
101 */
102 put_unused_fd(client_fd);
103 client_fd = PTR_ERR(new_file);
104 } else {
Al Viro352e3b22012-08-19 12:30:45 -0400105 *file = new_file;
Eric Parisa1014f12009-12-17 21:24:26 -0500106 }
107
Andreas Gruenbacher22aa4252009-12-17 21:24:26 -0500108 return client_fd;
Eric Parisa1014f12009-12-17 21:24:26 -0500109}
110
Eric Parisecf6f5e2010-11-08 18:08:14 -0500111static int fill_event_metadata(struct fsnotify_group *group,
Eric Parisa1014f12009-12-17 21:24:26 -0500112 struct fanotify_event_metadata *metadata,
Al Viro352e3b22012-08-19 12:30:45 -0400113 struct fsnotify_event *event,
114 struct file **file)
Eric Parisa1014f12009-12-17 21:24:26 -0500115{
Lino Sanfilippofdbf3ce2010-11-24 18:26:04 +0100116 int ret = 0;
117
Eric Parisa1014f12009-12-17 21:24:26 -0500118 pr_debug("%s: group=%p metadata=%p event=%p\n", __func__,
119 group, metadata, event);
120
Al Viro352e3b22012-08-19 12:30:45 -0400121 *file = NULL;
Eric Parisa1014f12009-12-17 21:24:26 -0500122 metadata->event_len = FAN_EVENT_METADATA_LEN;
Eric Paris7d131622010-12-07 15:27:57 -0500123 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
Eric Parisa1014f12009-12-17 21:24:26 -0500124 metadata->vers = FANOTIFY_METADATA_VERSION;
Andreas Gruenbacher33d3dff2009-12-17 21:24:29 -0500125 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
Andreas Gruenbacher32c32632009-12-17 21:24:27 -0500126 metadata->pid = pid_vnr(event->tgid);
Lino Sanfilippofdbf3ce2010-11-24 18:26:04 +0100127 if (unlikely(event->mask & FAN_Q_OVERFLOW))
128 metadata->fd = FAN_NOFD;
129 else {
Al Viro352e3b22012-08-19 12:30:45 -0400130 metadata->fd = create_fd(group, event, file);
Lino Sanfilippofdbf3ce2010-11-24 18:26:04 +0100131 if (metadata->fd < 0)
132 ret = metadata->fd;
133 }
Eric Parisa1014f12009-12-17 21:24:26 -0500134
Lino Sanfilippofdbf3ce2010-11-24 18:26:04 +0100135 return ret;
Eric Parisa1014f12009-12-17 21:24:26 -0500136}
137
Eric Parisb2d87902009-12-17 21:24:34 -0500138#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
139static struct fanotify_response_event *dequeue_re(struct fsnotify_group *group,
140 __s32 fd)
141{
142 struct fanotify_response_event *re, *return_re = NULL;
143
144 mutex_lock(&group->fanotify_data.access_mutex);
145 list_for_each_entry(re, &group->fanotify_data.access_list, list) {
146 if (re->fd != fd)
147 continue;
148
149 list_del_init(&re->list);
150 return_re = re;
151 break;
152 }
153 mutex_unlock(&group->fanotify_data.access_mutex);
154
155 pr_debug("%s: found return_re=%p\n", __func__, return_re);
156
157 return return_re;
158}
159
160static int process_access_response(struct fsnotify_group *group,
161 struct fanotify_response *response_struct)
162{
163 struct fanotify_response_event *re;
164 __s32 fd = response_struct->fd;
165 __u32 response = response_struct->response;
166
167 pr_debug("%s: group=%p fd=%d response=%d\n", __func__, group,
168 fd, response);
169 /*
170 * make sure the response is valid, if invalid we do nothing and either
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300171 * userspace can send a valid response or we will clean it up after the
Eric Parisb2d87902009-12-17 21:24:34 -0500172 * timeout
173 */
174 switch (response) {
175 case FAN_ALLOW:
176 case FAN_DENY:
177 break;
178 default:
179 return -EINVAL;
180 }
181
182 if (fd < 0)
183 return -EINVAL;
184
185 re = dequeue_re(group, fd);
186 if (!re)
187 return -ENOENT;
188
189 re->event->response = response;
190
191 wake_up(&group->fanotify_data.access_waitq);
192
193 kmem_cache_free(fanotify_response_event_cache, re);
194
195 return 0;
196}
197
198static int prepare_for_access_response(struct fsnotify_group *group,
199 struct fsnotify_event *event,
200 __s32 fd)
201{
202 struct fanotify_response_event *re;
203
204 if (!(event->mask & FAN_ALL_PERM_EVENTS))
205 return 0;
206
207 re = kmem_cache_alloc(fanotify_response_event_cache, GFP_KERNEL);
208 if (!re)
209 return -ENOMEM;
210
211 re->event = event;
212 re->fd = fd;
213
214 mutex_lock(&group->fanotify_data.access_mutex);
Eric Paris2eebf582010-08-18 12:25:50 -0400215
Lino Sanfilippo09e5f142010-11-19 10:58:07 +0100216 if (atomic_read(&group->fanotify_data.bypass_perm)) {
Eric Paris2eebf582010-08-18 12:25:50 -0400217 mutex_unlock(&group->fanotify_data.access_mutex);
218 kmem_cache_free(fanotify_response_event_cache, re);
219 event->response = FAN_ALLOW;
220 return 0;
221 }
222
Eric Parisb2d87902009-12-17 21:24:34 -0500223 list_add_tail(&re->list, &group->fanotify_data.access_list);
224 mutex_unlock(&group->fanotify_data.access_mutex);
225
226 return 0;
227}
228
Eric Parisb2d87902009-12-17 21:24:34 -0500229#else
230static int prepare_for_access_response(struct fsnotify_group *group,
231 struct fsnotify_event *event,
232 __s32 fd)
233{
234 return 0;
235}
236
Eric Parisb2d87902009-12-17 21:24:34 -0500237#endif
238
Eric Parisa1014f12009-12-17 21:24:26 -0500239static ssize_t copy_event_to_user(struct fsnotify_group *group,
240 struct fsnotify_event *event,
241 char __user *buf)
242{
243 struct fanotify_event_metadata fanotify_event_metadata;
Al Viro352e3b22012-08-19 12:30:45 -0400244 struct file *f;
Eric Parisb2d87902009-12-17 21:24:34 -0500245 int fd, ret;
Eric Parisa1014f12009-12-17 21:24:26 -0500246
247 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
248
Al Viro352e3b22012-08-19 12:30:45 -0400249 ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
Eric Parisecf6f5e2010-11-08 18:08:14 -0500250 if (ret < 0)
251 goto out;
Eric Parisa1014f12009-12-17 21:24:26 -0500252
Lino Sanfilippofdbf3ce2010-11-24 18:26:04 +0100253 fd = fanotify_event_metadata.fd;
Al Viro352e3b22012-08-19 12:30:45 -0400254 ret = -EFAULT;
255 if (copy_to_user(buf, &fanotify_event_metadata,
256 fanotify_event_metadata.event_len))
257 goto out_close_fd;
258
Eric Parisb2d87902009-12-17 21:24:34 -0500259 ret = prepare_for_access_response(group, event, fd);
260 if (ret)
261 goto out_close_fd;
262
Al Viro3587b1b2012-11-18 19:19:00 +0000263 if (fd != FAN_NOFD)
264 fd_install(fd, f);
Eric Paris7d131622010-12-07 15:27:57 -0500265 return fanotify_event_metadata.event_len;
Eric Parisb2d87902009-12-17 21:24:34 -0500266
Eric Parisb2d87902009-12-17 21:24:34 -0500267out_close_fd:
Al Viro352e3b22012-08-19 12:30:45 -0400268 if (fd != FAN_NOFD) {
269 put_unused_fd(fd);
270 fput(f);
271 }
Eric Parisecf6f5e2010-11-08 18:08:14 -0500272out:
273#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
274 if (event->mask & FAN_ALL_PERM_EVENTS) {
275 event->response = FAN_DENY;
276 wake_up(&group->fanotify_data.access_waitq);
277 }
278#endif
Eric Parisb2d87902009-12-17 21:24:34 -0500279 return ret;
Eric Parisa1014f12009-12-17 21:24:26 -0500280}
281
282/* intofiy userspace file descriptor functions */
283static unsigned int fanotify_poll(struct file *file, poll_table *wait)
284{
285 struct fsnotify_group *group = file->private_data;
286 int ret = 0;
287
288 poll_wait(file, &group->notification_waitq, wait);
289 mutex_lock(&group->notification_mutex);
290 if (!fsnotify_notify_queue_is_empty(group))
291 ret = POLLIN | POLLRDNORM;
292 mutex_unlock(&group->notification_mutex);
293
294 return ret;
295}
296
297static ssize_t fanotify_read(struct file *file, char __user *buf,
298 size_t count, loff_t *pos)
299{
300 struct fsnotify_group *group;
301 struct fsnotify_event *kevent;
302 char __user *start;
303 int ret;
304 DEFINE_WAIT(wait);
305
306 start = buf;
307 group = file->private_data;
308
309 pr_debug("%s: group=%p\n", __func__, group);
310
311 while (1) {
312 prepare_to_wait(&group->notification_waitq, &wait, TASK_INTERRUPTIBLE);
313
314 mutex_lock(&group->notification_mutex);
315 kevent = get_one_event(group, count);
316 mutex_unlock(&group->notification_mutex);
317
318 if (kevent) {
319 ret = PTR_ERR(kevent);
320 if (IS_ERR(kevent))
321 break;
322 ret = copy_event_to_user(group, kevent, buf);
323 fsnotify_put_event(kevent);
324 if (ret < 0)
325 break;
326 buf += ret;
327 count -= ret;
328 continue;
329 }
330
331 ret = -EAGAIN;
332 if (file->f_flags & O_NONBLOCK)
333 break;
Lino Sanfilippo1a5cea72010-10-29 12:06:42 +0200334 ret = -ERESTARTSYS;
Eric Parisa1014f12009-12-17 21:24:26 -0500335 if (signal_pending(current))
336 break;
337
338 if (start != buf)
339 break;
340
341 schedule();
342 }
343
344 finish_wait(&group->notification_waitq, &wait);
345 if (start != buf && ret != -EFAULT)
346 ret = buf - start;
347 return ret;
348}
349
Eric Parisb2d87902009-12-17 21:24:34 -0500350static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
351{
352#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
353 struct fanotify_response response = { .fd = -1, .response = -1 };
354 struct fsnotify_group *group;
355 int ret;
356
357 group = file->private_data;
358
359 if (count > sizeof(response))
360 count = sizeof(response);
361
362 pr_debug("%s: group=%p count=%zu\n", __func__, group, count);
363
364 if (copy_from_user(&response, buf, count))
365 return -EFAULT;
366
367 ret = process_access_response(group, &response);
368 if (ret < 0)
369 count = ret;
370
371 return count;
372#else
373 return -EINVAL;
374#endif
375}
376
Eric Paris52c923d2009-12-17 21:24:26 -0500377static int fanotify_release(struct inode *ignored, struct file *file)
378{
379 struct fsnotify_group *group = file->private_data;
Eric Paris52c923d2009-12-17 21:24:26 -0500380
Eric Paris2eebf582010-08-18 12:25:50 -0400381#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
Andrew Morton19ba54f2010-10-28 17:21:59 -0400382 struct fanotify_response_event *re, *lre;
383
Eric Paris2eebf582010-08-18 12:25:50 -0400384 mutex_lock(&group->fanotify_data.access_mutex);
385
Lino Sanfilippo09e5f142010-11-19 10:58:07 +0100386 atomic_inc(&group->fanotify_data.bypass_perm);
Eric Paris2eebf582010-08-18 12:25:50 -0400387
388 list_for_each_entry_safe(re, lre, &group->fanotify_data.access_list, list) {
389 pr_debug("%s: found group=%p re=%p event=%p\n", __func__, group,
390 re, re->event);
391
392 list_del_init(&re->list);
393 re->event->response = FAN_ALLOW;
394
395 kmem_cache_free(fanotify_response_event_cache, re);
396 }
397 mutex_unlock(&group->fanotify_data.access_mutex);
398
399 wake_up(&group->fanotify_data.access_waitq);
400#endif
Eric Paris0a6b6bd2011-10-14 17:43:39 -0400401
402 if (file->f_flags & FASYNC)
403 fsnotify_fasync(-1, file, 0);
404
Eric Paris52c923d2009-12-17 21:24:26 -0500405 /* matches the fanotify_init->fsnotify_alloc_group */
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200406 fsnotify_destroy_group(group);
Eric Paris52c923d2009-12-17 21:24:26 -0500407
408 return 0;
409}
410
Eric Parisa1014f12009-12-17 21:24:26 -0500411static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
412{
413 struct fsnotify_group *group;
414 struct fsnotify_event_holder *holder;
415 void __user *p;
416 int ret = -ENOTTY;
417 size_t send_len = 0;
418
419 group = file->private_data;
420
421 p = (void __user *) arg;
422
423 switch (cmd) {
424 case FIONREAD:
425 mutex_lock(&group->notification_mutex);
426 list_for_each_entry(holder, &group->notification_list, event_list)
427 send_len += FAN_EVENT_METADATA_LEN;
428 mutex_unlock(&group->notification_mutex);
429 ret = put_user(send_len, (int __user *) p);
430 break;
431 }
432
433 return ret;
434}
435
Eric Paris52c923d2009-12-17 21:24:26 -0500436static const struct file_operations fanotify_fops = {
Cyrill Gorcunovbe771962012-12-17 16:05:12 -0800437 .show_fdinfo = fanotify_show_fdinfo,
Eric Parisa1014f12009-12-17 21:24:26 -0500438 .poll = fanotify_poll,
439 .read = fanotify_read,
Eric Parisb2d87902009-12-17 21:24:34 -0500440 .write = fanotify_write,
Eric Paris52c923d2009-12-17 21:24:26 -0500441 .fasync = NULL,
442 .release = fanotify_release,
Eric Parisa1014f12009-12-17 21:24:26 -0500443 .unlocked_ioctl = fanotify_ioctl,
444 .compat_ioctl = fanotify_ioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200445 .llseek = noop_llseek,
Eric Paris52c923d2009-12-17 21:24:26 -0500446};
447
Eric Paris2a3edf82009-12-17 21:24:26 -0500448static void fanotify_free_mark(struct fsnotify_mark *fsn_mark)
449{
450 kmem_cache_free(fanotify_mark_cache, fsn_mark);
451}
452
453static int fanotify_find_path(int dfd, const char __user *filename,
454 struct path *path, unsigned int flags)
455{
456 int ret;
457
458 pr_debug("%s: dfd=%d filename=%p flags=%x\n", __func__,
459 dfd, filename, flags);
460
461 if (filename == NULL) {
Al Viro2903ff02012-08-28 12:52:22 -0400462 struct fd f = fdget(dfd);
Eric Paris2a3edf82009-12-17 21:24:26 -0500463
464 ret = -EBADF;
Al Viro2903ff02012-08-28 12:52:22 -0400465 if (!f.file)
Eric Paris2a3edf82009-12-17 21:24:26 -0500466 goto out;
467
468 ret = -ENOTDIR;
469 if ((flags & FAN_MARK_ONLYDIR) &&
Al Viro496ad9a2013-01-23 17:07:38 -0500470 !(S_ISDIR(file_inode(f.file)->i_mode))) {
Al Viro2903ff02012-08-28 12:52:22 -0400471 fdput(f);
Eric Paris2a3edf82009-12-17 21:24:26 -0500472 goto out;
473 }
474
Al Viro2903ff02012-08-28 12:52:22 -0400475 *path = f.file->f_path;
Eric Paris2a3edf82009-12-17 21:24:26 -0500476 path_get(path);
Al Viro2903ff02012-08-28 12:52:22 -0400477 fdput(f);
Eric Paris2a3edf82009-12-17 21:24:26 -0500478 } else {
479 unsigned int lookup_flags = 0;
480
481 if (!(flags & FAN_MARK_DONT_FOLLOW))
482 lookup_flags |= LOOKUP_FOLLOW;
483 if (flags & FAN_MARK_ONLYDIR)
484 lookup_flags |= LOOKUP_DIRECTORY;
485
486 ret = user_path_at(dfd, filename, lookup_flags, path);
487 if (ret)
488 goto out;
489 }
490
491 /* you can only watch an inode if you have read permissions on it */
492 ret = inode_permission(path->dentry->d_inode, MAY_READ);
493 if (ret)
494 path_put(path);
495out:
496 return ret;
497}
498
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500499static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark,
500 __u32 mask,
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200501 unsigned int flags,
502 int *destroy)
Andreas Gruenbacher088b09b2009-12-17 21:24:28 -0500503{
504 __u32 oldmask;
505
506 spin_lock(&fsn_mark->lock);
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500507 if (!(flags & FAN_MARK_IGNORED_MASK)) {
508 oldmask = fsn_mark->mask;
509 fsnotify_set_mark_mask_locked(fsn_mark, (oldmask & ~mask));
510 } else {
511 oldmask = fsn_mark->ignored_mask;
512 fsnotify_set_mark_ignored_mask_locked(fsn_mark, (oldmask & ~mask));
513 }
Andreas Gruenbacher088b09b2009-12-17 21:24:28 -0500514 spin_unlock(&fsn_mark->lock);
515
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200516 *destroy = !(oldmask & ~mask);
Andreas Gruenbacher088b09b2009-12-17 21:24:28 -0500517
518 return mask & oldmask;
519}
520
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500521static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500522 struct vfsmount *mnt, __u32 mask,
523 unsigned int flags)
Eric Paris88826272009-12-17 21:24:28 -0500524{
525 struct fsnotify_mark *fsn_mark = NULL;
Andreas Gruenbacher088b09b2009-12-17 21:24:28 -0500526 __u32 removed;
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200527 int destroy_mark;
Eric Paris88826272009-12-17 21:24:28 -0500528
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500529 fsn_mark = fsnotify_find_vfsmount_mark(group, mnt);
530 if (!fsn_mark)
531 return -ENOENT;
Eric Paris88826272009-12-17 21:24:28 -0500532
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200533 removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
534 &destroy_mark);
535 if (destroy_mark)
Lino Sanfilippoe2a29942011-06-14 17:29:51 +0200536 fsnotify_destroy_mark(fsn_mark, group);
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200537
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500538 fsnotify_put_mark(fsn_mark);
Al Viroc63181e2011-11-25 02:35:16 -0500539 if (removed & real_mount(mnt)->mnt_fsnotify_mask)
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500540 fsnotify_recalc_vfsmount_mask(mnt);
Eric Paris88826272009-12-17 21:24:28 -0500541
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500542 return 0;
543}
544
545static int fanotify_remove_inode_mark(struct fsnotify_group *group,
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500546 struct inode *inode, __u32 mask,
547 unsigned int flags)
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500548{
549 struct fsnotify_mark *fsn_mark = NULL;
550 __u32 removed;
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200551 int destroy_mark;
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500552
553 fsn_mark = fsnotify_find_inode_mark(group, inode);
Eric Paris88826272009-12-17 21:24:28 -0500554 if (!fsn_mark)
555 return -ENOENT;
556
Lino Sanfilippo6dfbd142011-06-14 17:29:49 +0200557 removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
558 &destroy_mark);
559 if (destroy_mark)
Lino Sanfilippoe2a29942011-06-14 17:29:51 +0200560 fsnotify_destroy_mark(fsn_mark, group);
Eric Paris5444e292009-12-17 21:24:27 -0500561 /* matches the fsnotify_find_inode_mark() */
Eric Paris2a3edf82009-12-17 21:24:26 -0500562 fsnotify_put_mark(fsn_mark);
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500563 if (removed & inode->i_fsnotify_mask)
564 fsnotify_recalc_inode_mask(inode);
Andreas Gruenbacher088b09b2009-12-17 21:24:28 -0500565
Eric Paris2a3edf82009-12-17 21:24:26 -0500566 return 0;
567}
568
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500569static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
570 __u32 mask,
571 unsigned int flags)
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500572{
Eric Paris192ca4d2010-10-28 17:21:59 -0400573 __u32 oldmask = -1;
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500574
575 spin_lock(&fsn_mark->lock);
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500576 if (!(flags & FAN_MARK_IGNORED_MASK)) {
577 oldmask = fsn_mark->mask;
578 fsnotify_set_mark_mask_locked(fsn_mark, (oldmask | mask));
579 } else {
Eric Paris192ca4d2010-10-28 17:21:59 -0400580 __u32 tmask = fsn_mark->ignored_mask | mask;
581 fsnotify_set_mark_ignored_mask_locked(fsn_mark, tmask);
Eric Parisc9778a92009-12-17 21:24:33 -0500582 if (flags & FAN_MARK_IGNORED_SURV_MODIFY)
583 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY;
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500584 }
Eric Paris8fcd6522010-10-28 17:21:59 -0400585
586 if (!(flags & FAN_MARK_ONDIR)) {
587 __u32 tmask = fsn_mark->ignored_mask | FAN_ONDIR;
588 fsnotify_set_mark_ignored_mask_locked(fsn_mark, tmask);
589 }
590
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500591 spin_unlock(&fsn_mark->lock);
592
593 return mask & ~oldmask;
594}
595
Andreas Gruenbacher52202df2009-12-17 21:24:28 -0500596static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500597 struct vfsmount *mnt, __u32 mask,
598 unsigned int flags)
Eric Paris2a3edf82009-12-17 21:24:26 -0500599{
600 struct fsnotify_mark *fsn_mark;
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500601 __u32 added;
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100602 int ret = 0;
Eric Paris2a3edf82009-12-17 21:24:26 -0500603
Eric Paris88826272009-12-17 21:24:28 -0500604 fsn_mark = fsnotify_find_vfsmount_mark(group, mnt);
605 if (!fsn_mark) {
Eric Parise7099d82010-10-28 17:21:57 -0400606 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
607 return -ENOSPC;
608
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500609 fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
610 if (!fsn_mark)
Andreas Gruenbacher52202df2009-12-17 21:24:28 -0500611 return -ENOMEM;
Eric Paris88826272009-12-17 21:24:28 -0500612
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500613 fsnotify_init_mark(fsn_mark, fanotify_free_mark);
614 ret = fsnotify_add_mark(fsn_mark, group, NULL, mnt, 0);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100615 if (ret)
616 goto err;
Eric Paris88826272009-12-17 21:24:28 -0500617 }
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500618 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100619
Al Viroc63181e2011-11-25 02:35:16 -0500620 if (added & ~real_mount(mnt)->mnt_fsnotify_mask)
Eric Paris43709a22010-07-28 10:18:39 -0400621 fsnotify_recalc_vfsmount_mask(mnt);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100622err:
623 fsnotify_put_mark(fsn_mark);
624 return ret;
Eric Paris88826272009-12-17 21:24:28 -0500625}
626
Andreas Gruenbacher52202df2009-12-17 21:24:28 -0500627static int fanotify_add_inode_mark(struct fsnotify_group *group,
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500628 struct inode *inode, __u32 mask,
629 unsigned int flags)
Eric Paris88826272009-12-17 21:24:28 -0500630{
631 struct fsnotify_mark *fsn_mark;
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500632 __u32 added;
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100633 int ret = 0;
Eric Paris88826272009-12-17 21:24:28 -0500634
635 pr_debug("%s: group=%p inode=%p\n", __func__, group, inode);
Eric Paris2a3edf82009-12-17 21:24:26 -0500636
Eric Paris5322a592010-10-28 17:21:57 -0400637 /*
638 * If some other task has this inode open for write we should not add
639 * an ignored mark, unless that ignored mark is supposed to survive
640 * modification changes anyway.
641 */
642 if ((flags & FAN_MARK_IGNORED_MASK) &&
643 !(flags & FAN_MARK_IGNORED_SURV_MODIFY) &&
644 (atomic_read(&inode->i_writecount) > 0))
645 return 0;
646
Eric Paris5444e292009-12-17 21:24:27 -0500647 fsn_mark = fsnotify_find_inode_mark(group, inode);
Eric Paris2a3edf82009-12-17 21:24:26 -0500648 if (!fsn_mark) {
Eric Parise7099d82010-10-28 17:21:57 -0400649 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
650 return -ENOSPC;
651
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500652 fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
653 if (!fsn_mark)
Andreas Gruenbacher52202df2009-12-17 21:24:28 -0500654 return -ENOMEM;
Eric Paris2a3edf82009-12-17 21:24:26 -0500655
Andreas Gruenbacher912ee39462009-12-17 21:24:28 -0500656 fsnotify_init_mark(fsn_mark, fanotify_free_mark);
657 ret = fsnotify_add_mark(fsn_mark, group, inode, NULL, 0);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100658 if (ret)
659 goto err;
Eric Paris2a3edf82009-12-17 21:24:26 -0500660 }
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500661 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100662
Eric Paris43709a22010-07-28 10:18:39 -0400663 if (added & ~inode->i_fsnotify_mask)
664 fsnotify_recalc_inode_mask(inode);
Lino Sanfilippofa218ab2010-11-09 18:18:16 +0100665err:
666 fsnotify_put_mark(fsn_mark);
667 return ret;
Eric Paris88826272009-12-17 21:24:28 -0500668}
Eric Paris2a3edf82009-12-17 21:24:26 -0500669
Eric Paris52c923d2009-12-17 21:24:26 -0500670/* fanotify syscalls */
Eric Paris08ae8932010-05-27 09:41:40 -0400671SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
Eric Paris11637e42009-12-17 21:24:25 -0500672{
Eric Paris52c923d2009-12-17 21:24:26 -0500673 struct fsnotify_group *group;
674 int f_flags, fd;
Eric Paris4afeff82010-10-28 17:21:58 -0400675 struct user_struct *user;
Eric Paris52c923d2009-12-17 21:24:26 -0500676
Eric Paris08ae8932010-05-27 09:41:40 -0400677 pr_debug("%s: flags=%d event_f_flags=%d\n",
678 __func__, flags, event_f_flags);
Eric Paris52c923d2009-12-17 21:24:26 -0500679
Eric Paris52c923d2009-12-17 21:24:26 -0500680 if (!capable(CAP_SYS_ADMIN))
Andreas Gruenbachera2f13ad2010-08-24 12:58:54 +0200681 return -EPERM;
Eric Paris52c923d2009-12-17 21:24:26 -0500682
683 if (flags & ~FAN_ALL_INIT_FLAGS)
684 return -EINVAL;
685
Eric Paris4afeff82010-10-28 17:21:58 -0400686 user = get_current_user();
687 if (atomic_read(&user->fanotify_listeners) > FANOTIFY_DEFAULT_MAX_LISTENERS) {
688 free_uid(user);
689 return -EMFILE;
690 }
691
Eric Parisb2d87902009-12-17 21:24:34 -0500692 f_flags = O_RDWR | FMODE_NONOTIFY;
Eric Paris52c923d2009-12-17 21:24:26 -0500693 if (flags & FAN_CLOEXEC)
694 f_flags |= O_CLOEXEC;
695 if (flags & FAN_NONBLOCK)
696 f_flags |= O_NONBLOCK;
697
698 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
699 group = fsnotify_alloc_group(&fanotify_fsnotify_ops);
Eric Paris26379192010-11-23 23:48:26 -0500700 if (IS_ERR(group)) {
701 free_uid(user);
Eric Paris52c923d2009-12-17 21:24:26 -0500702 return PTR_ERR(group);
Eric Paris26379192010-11-23 23:48:26 -0500703 }
Eric Paris52c923d2009-12-17 21:24:26 -0500704
Eric Paris4afeff82010-10-28 17:21:58 -0400705 group->fanotify_data.user = user;
706 atomic_inc(&user->fanotify_listeners);
707
Eric Paris80af2582010-07-28 10:18:37 -0400708 group->fanotify_data.f_flags = event_f_flags;
Eric Paris9e66e422009-12-17 21:24:34 -0500709#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
710 mutex_init(&group->fanotify_data.access_mutex);
711 init_waitqueue_head(&group->fanotify_data.access_waitq);
712 INIT_LIST_HEAD(&group->fanotify_data.access_list);
Lino Sanfilippo09e5f142010-11-19 10:58:07 +0100713 atomic_set(&group->fanotify_data.bypass_perm, 0);
Eric Paris9e66e422009-12-17 21:24:34 -0500714#endif
Eric Paris4231a232010-10-28 17:21:56 -0400715 switch (flags & FAN_ALL_CLASS_BITS) {
716 case FAN_CLASS_NOTIF:
717 group->priority = FS_PRIO_0;
718 break;
719 case FAN_CLASS_CONTENT:
720 group->priority = FS_PRIO_1;
721 break;
722 case FAN_CLASS_PRE_CONTENT:
723 group->priority = FS_PRIO_2;
724 break;
725 default:
726 fd = -EINVAL;
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200727 goto out_destroy_group;
Eric Paris4231a232010-10-28 17:21:56 -0400728 }
Eric Pariscb2d4292009-12-17 21:24:34 -0500729
Eric Paris5dd03f52010-10-28 17:21:57 -0400730 if (flags & FAN_UNLIMITED_QUEUE) {
731 fd = -EPERM;
732 if (!capable(CAP_SYS_ADMIN))
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200733 goto out_destroy_group;
Eric Paris5dd03f52010-10-28 17:21:57 -0400734 group->max_events = UINT_MAX;
735 } else {
736 group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS;
737 }
Eric Paris2529a0d2010-10-28 17:21:57 -0400738
Eric Parisac7e22d2010-10-28 17:21:58 -0400739 if (flags & FAN_UNLIMITED_MARKS) {
740 fd = -EPERM;
741 if (!capable(CAP_SYS_ADMIN))
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200742 goto out_destroy_group;
Eric Parisac7e22d2010-10-28 17:21:58 -0400743 group->fanotify_data.max_marks = UINT_MAX;
744 } else {
745 group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS;
746 }
Eric Parise7099d82010-10-28 17:21:57 -0400747
Eric Paris52c923d2009-12-17 21:24:26 -0500748 fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
749 if (fd < 0)
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200750 goto out_destroy_group;
Eric Paris52c923d2009-12-17 21:24:26 -0500751
752 return fd;
753
Lino Sanfilippod8153d42011-06-14 17:29:45 +0200754out_destroy_group:
755 fsnotify_destroy_group(group);
Eric Paris52c923d2009-12-17 21:24:26 -0500756 return fd;
Eric Paris11637e42009-12-17 21:24:25 -0500757}
Eric Parisbbaa4162009-12-17 21:24:26 -0500758
Al Viro4a0fd5b2013-01-21 15:16:58 -0500759SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
760 __u64, mask, int, dfd,
761 const char __user *, pathname)
Eric Parisbbaa4162009-12-17 21:24:26 -0500762{
Eric Paris0ff21db2009-12-17 21:24:29 -0500763 struct inode *inode = NULL;
764 struct vfsmount *mnt = NULL;
Eric Paris2a3edf82009-12-17 21:24:26 -0500765 struct fsnotify_group *group;
Al Viro2903ff02012-08-28 12:52:22 -0400766 struct fd f;
Eric Paris2a3edf82009-12-17 21:24:26 -0500767 struct path path;
Al Viro2903ff02012-08-28 12:52:22 -0400768 int ret;
Eric Paris2a3edf82009-12-17 21:24:26 -0500769
770 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
771 __func__, fanotify_fd, flags, dfd, pathname, mask);
772
773 /* we only use the lower 32 bits as of right now. */
774 if (mask & ((__u64)0xffffffff << 32))
775 return -EINVAL;
776
Andreas Gruenbacher88380fe2009-12-17 21:24:29 -0500777 if (flags & ~FAN_ALL_MARK_FLAGS)
778 return -EINVAL;
Eric Paris4d926042009-12-17 21:24:34 -0500779 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) {
Lino Sanfilippo1734dee2010-11-22 18:46:33 +0100780 case FAN_MARK_ADD: /* fallthrough */
Andreas Gruenbacher88380fe2009-12-17 21:24:29 -0500781 case FAN_MARK_REMOVE:
Lino Sanfilippo1734dee2010-11-22 18:46:33 +0100782 if (!mask)
783 return -EINVAL;
Eric Paris4d926042009-12-17 21:24:34 -0500784 case FAN_MARK_FLUSH:
Andreas Gruenbacher88380fe2009-12-17 21:24:29 -0500785 break;
786 default:
787 return -EINVAL;
788 }
Eric Paris8fcd6522010-10-28 17:21:59 -0400789
790 if (mask & FAN_ONDIR) {
791 flags |= FAN_MARK_ONDIR;
792 mask &= ~FAN_ONDIR;
793 }
794
Eric Parisb2d87902009-12-17 21:24:34 -0500795#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
796 if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD))
797#else
Andreas Gruenbacher88380fe2009-12-17 21:24:29 -0500798 if (mask & ~(FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD))
Eric Parisb2d87902009-12-17 21:24:34 -0500799#endif
Eric Paris2a3edf82009-12-17 21:24:26 -0500800 return -EINVAL;
801
Al Viro2903ff02012-08-28 12:52:22 -0400802 f = fdget(fanotify_fd);
803 if (unlikely(!f.file))
Eric Paris2a3edf82009-12-17 21:24:26 -0500804 return -EBADF;
805
806 /* verify that this is indeed an fanotify instance */
807 ret = -EINVAL;
Al Viro2903ff02012-08-28 12:52:22 -0400808 if (unlikely(f.file->f_op != &fanotify_fops))
Eric Paris2a3edf82009-12-17 21:24:26 -0500809 goto fput_and_out;
Al Viro2903ff02012-08-28 12:52:22 -0400810 group = f.file->private_data;
Eric Paris4231a232010-10-28 17:21:56 -0400811
812 /*
813 * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not
814 * allowed to set permissions events.
815 */
816 ret = -EINVAL;
817 if (mask & FAN_ALL_PERM_EVENTS &&
818 group->priority == FS_PRIO_0)
819 goto fput_and_out;
Eric Paris2a3edf82009-12-17 21:24:26 -0500820
821 ret = fanotify_find_path(dfd, pathname, &path, flags);
822 if (ret)
823 goto fput_and_out;
824
825 /* inode held in place by reference to path; group by fget on fd */
Andreas Gruenbachereac8e9e2009-12-17 21:24:29 -0500826 if (!(flags & FAN_MARK_MOUNT))
Eric Paris0ff21db2009-12-17 21:24:29 -0500827 inode = path.dentry->d_inode;
828 else
829 mnt = path.mnt;
Eric Paris2a3edf82009-12-17 21:24:26 -0500830
831 /* create/update an inode mark */
Eric Paris4d926042009-12-17 21:24:34 -0500832 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) {
Andreas Gruenbacherc6223f42009-12-17 21:24:28 -0500833 case FAN_MARK_ADD:
Andreas Gruenbachereac8e9e2009-12-17 21:24:29 -0500834 if (flags & FAN_MARK_MOUNT)
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500835 ret = fanotify_add_vfsmount_mark(group, mnt, mask, flags);
Eric Paris0ff21db2009-12-17 21:24:29 -0500836 else
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500837 ret = fanotify_add_inode_mark(group, inode, mask, flags);
Andreas Gruenbacherc6223f42009-12-17 21:24:28 -0500838 break;
839 case FAN_MARK_REMOVE:
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500840 if (flags & FAN_MARK_MOUNT)
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500841 ret = fanotify_remove_vfsmount_mark(group, mnt, mask, flags);
Andreas Gruenbacherf3640192009-12-17 21:24:29 -0500842 else
Eric Parisb9e4e3b2009-12-17 21:24:33 -0500843 ret = fanotify_remove_inode_mark(group, inode, mask, flags);
Andreas Gruenbacherc6223f42009-12-17 21:24:28 -0500844 break;
Eric Paris4d926042009-12-17 21:24:34 -0500845 case FAN_MARK_FLUSH:
846 if (flags & FAN_MARK_MOUNT)
847 fsnotify_clear_vfsmount_marks_by_group(group);
848 else
849 fsnotify_clear_inode_marks_by_group(group);
Eric Paris4d926042009-12-17 21:24:34 -0500850 break;
Andreas Gruenbacherc6223f42009-12-17 21:24:28 -0500851 default:
852 ret = -EINVAL;
853 }
Eric Paris2a3edf82009-12-17 21:24:26 -0500854
855 path_put(&path);
856fput_and_out:
Al Viro2903ff02012-08-28 12:52:22 -0400857 fdput(f);
Eric Paris2a3edf82009-12-17 21:24:26 -0500858 return ret;
Eric Parisbbaa4162009-12-17 21:24:26 -0500859}
Eric Paris2a3edf82009-12-17 21:24:26 -0500860
Al Viro91c2e0b2013-03-05 20:10:59 -0500861#ifdef CONFIG_COMPAT
862COMPAT_SYSCALL_DEFINE6(fanotify_mark,
863 int, fanotify_fd, unsigned int, flags,
864 __u32, mask0, __u32, mask1, int, dfd,
865 const char __user *, pathname)
866{
867 return sys_fanotify_mark(fanotify_fd, flags,
868#ifdef __BIG_ENDIAN
869 ((__u64)mask1 << 32) | mask0,
870#else
871 ((__u64)mask0 << 32) | mask1,
872#endif
873 dfd, pathname);
874}
875#endif
876
Eric Paris2a3edf82009-12-17 21:24:26 -0500877/*
Justin P. Mattockae0e47f2011-03-01 15:06:02 +0100878 * fanotify_user_setup - Our initialization function. Note that we cannot return
Eric Paris2a3edf82009-12-17 21:24:26 -0500879 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
880 * must result in panic().
881 */
882static int __init fanotify_user_setup(void)
883{
884 fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC);
Eric Parisb2d87902009-12-17 21:24:34 -0500885 fanotify_response_event_cache = KMEM_CACHE(fanotify_response_event,
886 SLAB_PANIC);
Eric Paris2a3edf82009-12-17 21:24:26 -0500887
888 return 0;
889}
890device_initcall(fanotify_user_setup);