OSDN Git Service

ARM: dts: at91: sama5d3: define clock rate range for tcb1
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / kernel / audit_watch.c
index 656c7e9..f45a9a5 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <linux/file.h>
 #include <linux/kernel.h>
 #include <linux/audit.h>
 #include <linux/kthread.h>
@@ -418,6 +419,13 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
        struct path parent_path;
        int h, ret = 0;
 
+       /*
+        * When we will be calling audit_add_to_parent, krule->watch might have
+        * been updated and watch might have been freed.
+        * So we need to keep a reference of watch.
+        */
+       audit_get_watch(watch);
+
        mutex_unlock(&audit_filter_mutex);
 
        /* Avoid calling path_lookup under audit_filter_mutex. */
@@ -426,8 +434,10 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
        /* caller expects mutex locked */
        mutex_lock(&audit_filter_mutex);
 
-       if (ret)
+       if (ret) {
+               audit_put_watch(watch);
                return ret;
+       }
 
        /* either find an old parent or attach a new one */
        parent = audit_find_parent(d_backing_inode(parent_path.dentry));
@@ -445,6 +455,7 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
        *list = &audit_inode_hash[h];
 error:
        path_put(&parent_path);
+       audit_put_watch(watch);
        return ret;
 }
 
@@ -456,13 +467,15 @@ void audit_remove_watch_rule(struct audit_krule *krule)
        list_del(&krule->rlist);
 
        if (list_empty(&watch->rules)) {
+               /*
+                * audit_remove_watch() drops our reference to 'parent' which
+                * can get freed. Grab our own reference to be safe.
+                */
+               audit_get_parent(parent);
                audit_remove_watch(watch);
-
-               if (list_empty(&parent->watches)) {
-                       audit_get_parent(parent);
+               if (list_empty(&parent->watches))
                        fsnotify_destroy_mark(&parent->mark, audit_watch_group);
-                       audit_put_parent(parent);
-               }
+               audit_put_parent(parent);
        }
 }
 
@@ -544,10 +557,11 @@ int audit_exe_compare(struct task_struct *tsk, struct audit_fsnotify_mark *mark)
        unsigned long ino;
        dev_t dev;
 
-       rcu_read_lock();
-       exe_file = rcu_dereference(tsk->mm->exe_file);
+       exe_file = get_task_exe_file(tsk);
+       if (!exe_file)
+               return 0;
        ino = exe_file->f_inode->i_ino;
        dev = exe_file->f_inode->i_sb->s_dev;
-       rcu_read_unlock();
+       fput(exe_file);
        return audit_mark_compare(mark, ino, dev);
 }