Merge tag 'selinux-pr-20190917' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / fs / notify / dnotify / dnotify.c
index c03758c9148171a865ef81a988b1c6082db63c5c..7a42c2ebe28d76c1d376e9192ae0373412dc3bac 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/sched/signal.h>
 #include <linux/dnotify.h>
 #include <linux/init.h>
+#include <linux/security.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/fdtable.h>
@@ -279,6 +280,17 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
                goto out_err;
        }
 
+       /*
+        * convert the userspace DN_* "arg" to the internal FS_*
+        * defined in fsnotify
+        */
+       mask = convert_arg(arg);
+
+       error = security_path_notify(&filp->f_path, mask,
+                       FSNOTIFY_OBJ_TYPE_INODE);
+       if (error)
+               goto out_err;
+
        /* expect most fcntl to add new rather than augment old */
        dn = kmem_cache_alloc(dnotify_struct_cache, GFP_KERNEL);
        if (!dn) {
@@ -293,9 +305,6 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
                goto out_err;
        }
 
-       /* convert the userspace DN_* "arg" to the internal FS_* defines in fsnotify */
-       mask = convert_arg(arg);
-
        /* set up the new_fsn_mark and new_dn_mark */
        new_fsn_mark = &new_dn_mark->fsn_mark;
        fsnotify_init_mark(new_fsn_mark, dnotify_group);