Commit 830cd761 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Greg Kroah-Hartman

audit: fix refcounting in audit-tree

commit a2140fc0 upstream.

Refcounting of fsnotify_mark in audit tree is broken.  E.g:

                              refcount
create_chunk
  alloc_chunk                 1
  fsnotify_add_mark           2

untag_chunk
  fsnotify_get_mark           3
  fsnotify_destroy_mark
    audit_tree_freeing_mark   2
  fsnotify_put_mark           1
  fsnotify_put_mark           0
  via destroy_list
    fsnotify_mark_destroy    -1

This was reported by various people as triggering Oops when stopping auditd.

We could just remove the put_mark from audit_tree_freeing_mark() but that would
break freeing via inode destruction.  So this patch simply omits a put_mark
after calling destroy_mark or adds a get_mark before.

The additional get_mark is necessary where there's no other put_mark after
fsnotify_destroy_mark() since it assumes that the caller is holding a reference
(or the inode is keeping the mark pinned, not the case here AFAICS).
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
Reported-by: default avatarValentin Avram <aval13@gmail.com>
Reported-by: default avatarPeter Moody <pmoody@google.com>
Acked-by: default avatarEric Paris <eparis@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 56e4562b
...@@ -256,7 +256,6 @@ static void untag_chunk(struct node *p) ...@@ -256,7 +256,6 @@ static void untag_chunk(struct node *p)
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
spin_unlock(&entry->lock); spin_unlock(&entry->lock);
fsnotify_destroy_mark(entry); fsnotify_destroy_mark(entry);
fsnotify_put_mark(entry);
goto out; goto out;
} }
...@@ -299,7 +298,6 @@ static void untag_chunk(struct node *p) ...@@ -299,7 +298,6 @@ static void untag_chunk(struct node *p)
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
spin_unlock(&entry->lock); spin_unlock(&entry->lock);
fsnotify_destroy_mark(entry); fsnotify_destroy_mark(entry);
fsnotify_put_mark(entry);
goto out; goto out;
Fallback: Fallback:
...@@ -338,6 +336,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) ...@@ -338,6 +336,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
chunk->dead = 1; chunk->dead = 1;
spin_unlock(&entry->lock); spin_unlock(&entry->lock);
fsnotify_get_mark(entry);
fsnotify_destroy_mark(entry); fsnotify_destroy_mark(entry);
fsnotify_put_mark(entry); fsnotify_put_mark(entry);
return 0; return 0;
...@@ -418,6 +417,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) ...@@ -418,6 +417,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
spin_unlock(&chunk_entry->lock); spin_unlock(&chunk_entry->lock);
spin_unlock(&old_entry->lock); spin_unlock(&old_entry->lock);
fsnotify_get_mark(chunk_entry);
fsnotify_destroy_mark(chunk_entry); fsnotify_destroy_mark(chunk_entry);
fsnotify_put_mark(chunk_entry); fsnotify_put_mark(chunk_entry);
...@@ -451,7 +451,6 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) ...@@ -451,7 +451,6 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
spin_unlock(&old_entry->lock); spin_unlock(&old_entry->lock);
fsnotify_destroy_mark(old_entry); fsnotify_destroy_mark(old_entry);
fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */ fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */
fsnotify_put_mark(old_entry); /* and kill it */
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment