extern struct list_head audit_filter_list[];
 
 /* audit watch functions */
-extern unsigned long audit_watch_inode(struct audit_watch *watch);
-extern dev_t audit_watch_dev(struct audit_watch *watch);
 extern void audit_put_watch(struct audit_watch *watch);
 extern void audit_get_watch(struct audit_watch *watch);
 extern int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op);
-extern int audit_add_watch(struct audit_krule *krule);
-extern void audit_remove_watch(struct audit_watch *watch);
+extern int audit_add_watch(struct audit_krule *krule, struct list_head **list);
 extern void audit_remove_watch_rule(struct audit_krule *krule, struct list_head *list);
-extern void audit_inotify_unregister(struct list_head *in_list);
+extern void audit_watch_inotify_unregister(struct list_head *in_list);
 extern char *audit_watch_path(struct audit_watch *watch);
-extern struct list_head *audit_watch_rules(struct audit_watch *watch);
-
-extern struct audit_entry *audit_dupe_rule(struct audit_krule *old,
-                                          struct audit_watch *watch);
+extern int audit_watch_compare(struct audit_watch *watch, unsigned long ino, dev_t dev);
+extern struct audit_entry *audit_dupe_rule(struct audit_krule *old);
 
 #ifdef CONFIG_AUDIT_TREE
 extern struct audit_chunk *audit_tree_lookup(const struct inode *);
 
        unsigned long           ino;    /* associated inode number */
        struct audit_parent     *parent; /* associated parent */
        struct list_head        wlist;  /* entry in parent->watches list */
-       struct list_head        rules;  /* associated rules */
+       struct list_head        rules;  /* anchor for krule->rlist */
 };
 
 struct audit_parent {
-       struct list_head        ilist;  /* entry in inotify registration list */
-       struct list_head        watches; /* associated watches */
+       struct list_head        ilist;  /* tmp list used to free parents */
+       struct list_head        watches; /* anchor for audit_watch->wlist */
        struct inotify_watch    wdata;  /* inotify watch data */
        unsigned                flags;  /* status flags */
 };
 /* Inotify events we care about. */
 #define AUDIT_IN_WATCH IN_MOVE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF
 
-static void audit_free_parent(struct inotify_watch *i_watch)
+static void audit_free_parent(struct audit_parent *parent)
+{
+       WARN_ON(!list_empty(&parent->watches));
+       kfree(parent);
+}
+
+static void audit_destroy_watch(struct inotify_watch *i_watch)
 {
        struct audit_parent *parent;
 
        parent = container_of(i_watch, struct audit_parent, wdata);
-       WARN_ON(!list_empty(&parent->watches));
-       kfree(parent);
+       audit_free_parent(parent);
 }
 
 void audit_get_watch(struct audit_watch *watch)
        return watch->path;
 }
 
-struct list_head *audit_watch_rules(struct audit_watch *watch)
+int audit_watch_compare(struct audit_watch *watch, unsigned long ino, dev_t dev)
 {
-       return &watch->rules;
-}
-
-unsigned long audit_watch_inode(struct audit_watch *watch)
-{
-       return watch->ino;
-}
-
-dev_t audit_watch_dev(struct audit_watch *watch)
-{
-       return watch->dev;
+       return (watch->ino != (unsigned long)-1) &&
+               (watch->ino == ino) &&
+               (watch->dev == dev);
 }
 
 /* Initialize a parent watch entry. */
        wd = inotify_add_watch(audit_ih, &parent->wdata,
                               ndp->path.dentry->d_inode, AUDIT_IN_WATCH);
        if (wd < 0) {
-               audit_free_parent(&parent->wdata);
+               audit_free_parent(parent);
                return ERR_PTR(wd);
        }
 
        struct audit_entry *oentry, *nentry;
 
        mutex_lock(&audit_filter_mutex);
+       /* Run all of the watches on this parent looking for the one that
+        * matches the given dname */
        list_for_each_entry_safe(owatch, nextw, &parent->watches, wlist) {
                if (audit_compare_dname_path(dname, owatch->path, NULL))
                        continue;
 
                /* If the update involves invalidating rules, do the inode-based
                 * filtering now, so we don't omit records. */
-               if (invalidating && current->audit_context)
+               if (invalidating && !audit_dummy_context())
                        audit_filter_inodes(current, current->audit_context);
 
+               /* updating ino will likely change which audit_hash_list we
+                * are on so we need a new watch for the new list */
                nwatch = audit_dupe_watch(owatch);
                if (IS_ERR(nwatch)) {
                        mutex_unlock(&audit_filter_mutex);
                        list_del(&oentry->rule.rlist);
                        list_del_rcu(&oentry->list);
 
-                       nentry = audit_dupe_rule(&oentry->rule, nwatch);
+                       nentry = audit_dupe_rule(&oentry->rule);
                        if (IS_ERR(nentry)) {
                                list_del(&oentry->rule.list);
                                audit_panic("error updating watch, removing");
                        } else {
                                int h = audit_hash_ino((u32)ino);
+
+                               /*
+                                * nentry->rule.watch == oentry->rule.watch so
+                                * we must drop that reference and set it to our
+                                * new watch.
+                                */
+                               audit_put_watch(nentry->rule.watch);
+                               audit_get_watch(nwatch);
+                               nentry->rule.watch = nwatch;
                                list_add(&nentry->rule.rlist, &nwatch->rules);
                                list_add_rcu(&nentry->list, &audit_inode_hash[h]);
                                list_replace(&oentry->rule.list,
 
 /* Unregister inotify watches for parents on in_list.
  * Generates an IN_IGNORED event. */
-void audit_inotify_unregister(struct list_head *in_list)
+void audit_watch_inotify_unregister(struct list_head *in_list)
 {
        struct audit_parent *p, *n;
 
        list_for_each_entry_safe(p, n, in_list, ilist) {
                list_del(&p->ilist);
                inotify_rm_watch(audit_ih, &p->wdata);
-               /* the unpin matching the pin in audit_do_del_rule() */
+               /* the unpin matching the pin in audit_remove_watch_rule() */
                unpin_inotify_watch(&p->wdata);
        }
 }
 
 /* Find a matching watch entry, or add this one.
  * Caller must hold audit_filter_mutex. */
-int audit_add_watch(struct audit_krule *krule)
+int audit_add_watch(struct audit_krule *krule, struct list_head **list)
 {
        struct audit_watch *watch = krule->watch;
        struct inotify_watch *i_watch;
        struct audit_parent *parent;
        struct nameidata *ndp = NULL, *ndw = NULL;
-       int ret = 0;
+       int h, ret = 0;
 
        mutex_unlock(&audit_filter_mutex);
 
        /* match get in audit_init_parent or inotify_find_watch */
        put_inotify_watch(&parent->wdata);
 
+       h = audit_hash_ino((u32)watch->ino);
+       *list = &audit_inode_hash[h];
 error:
        audit_put_nd(ndp, ndw);         /* NULL args OK */
        return ret;
        parent = container_of(i_watch, struct audit_parent, wdata);
 
        if (mask & (IN_CREATE|IN_MOVED_TO) && inode)
-               audit_update_watch(parent, dname, inode->i_sb->s_dev,
-                                  inode->i_ino, 0);
+               audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
        else if (mask & (IN_DELETE|IN_MOVED_FROM))
                audit_update_watch(parent, dname, (dev_t)-1, (unsigned long)-1, 1);
        /* inotify automatically removes the watch and sends IN_IGNORED */
 
 static const struct inotify_operations audit_inotify_ops = {
        .handle_event   = audit_handle_ievent,
-       .destroy_watch  = audit_free_parent,
+       .destroy_watch  = audit_destroy_watch,
 };
 
 static int __init audit_watch_init(void)
 
 {
        int i;
        struct audit_krule *erule = &e->rule;
+
        /* some rules don't have associated watches */
        if (erule->watch)
                audit_put_watch(erule->watch);
  * rule with the new rule in the filterlist, then free the old rule.
  * The rlist element is undefined; list manipulations are handled apart from
  * the initial copy. */
-struct audit_entry *audit_dupe_rule(struct audit_krule *old,
-                                   struct audit_watch *watch)
+struct audit_entry *audit_dupe_rule(struct audit_krule *old)
 {
        u32 fcount = old->field_count;
        struct audit_entry *entry;
        new->prio = old->prio;
        new->buflen = old->buflen;
        new->inode_f = old->inode_f;
-       new->watch = NULL;
        new->field_count = old->field_count;
+
        /*
         * note that we are OK with not refcounting here; audit_match_tree()
         * never dereferences tree and we can't get false positives there
                }
        }
 
-       if (watch) {
-               audit_get_watch(watch);
-               new->watch = watch;
+       if (old->watch) {
+               audit_get_watch(old->watch);
+               new->watch = old->watch;
        }
 
        return entry;
        struct audit_watch *watch = entry->rule.watch;
        struct audit_tree *tree = entry->rule.tree;
        struct list_head *list;
-       int h, err;
+       int err;
 #ifdef CONFIG_AUDITSYSCALL
        int dont_count = 0;
 
 
        if (watch) {
                /* audit_filter_mutex is dropped and re-taken during this call */
-               err = audit_add_watch(&entry->rule);
+               err = audit_add_watch(&entry->rule, &list);
                if (err) {
                        mutex_unlock(&audit_filter_mutex);
                        goto error;
                }
-               /* entry->rule.watch may have changed during audit_add_watch() */
-               watch = entry->rule.watch;
-               h = audit_hash_ino((u32)audit_watch_inode(watch));
-               list = &audit_inode_hash[h];
        }
        if (tree) {
                err = audit_add_tree_rule(&entry->rule);
        struct audit_watch *watch = entry->rule.watch;
        struct audit_tree *tree = entry->rule.tree;
        struct list_head *list;
-       LIST_HEAD(inotify_list);
+       LIST_HEAD(inotify_unregister_list);
        int ret = 0;
 #ifdef CONFIG_AUDITSYSCALL
        int dont_count = 0;
        }
 
        if (e->rule.watch)
-               audit_remove_watch_rule(&e->rule, &inotify_list);
+               audit_remove_watch_rule(&e->rule, &inotify_unregister_list);
 
        if (e->rule.tree)
                audit_remove_tree_rule(&e->rule);
 #endif
        mutex_unlock(&audit_filter_mutex);
 
-       if (!list_empty(&inotify_list))
-               audit_inotify_unregister(&inotify_list);
+       if (!list_empty(&inotify_unregister_list))
+               audit_watch_inotify_unregister(&inotify_unregister_list);
 
 out:
        if (watch)
 {
        struct audit_entry *entry = container_of(r, struct audit_entry, rule);
        struct audit_entry *nentry;
-       struct audit_watch *watch;
-       struct audit_tree *tree;
        int err = 0;
 
        if (!security_audit_rule_known(r))
                return 0;
 
-       watch = r->watch;
-       tree = r->tree;
-       nentry = audit_dupe_rule(r, watch);
+       nentry = audit_dupe_rule(r);
        if (IS_ERR(nentry)) {
                /* save the first error encountered for the
                 * return value */
                err = PTR_ERR(nentry);
                audit_panic("error updating LSM filters");
-               if (watch)
+               if (r->watch)
                        list_del(&r->rlist);
                list_del_rcu(&entry->list);
                list_del(&r->list);
        } else {
-               if (watch) {
-                       list_add(&nentry->rule.rlist, audit_watch_rules(watch));
-                       list_del(&r->rlist);
-               } else if (tree)
+               if (r->watch || r->tree)
                        list_replace_init(&r->rlist, &nentry->rule.rlist);
                list_replace_rcu(&entry->list, &nentry->list);
                list_replace(&r->list, &nentry->rule.list);