提交 6f5d5114 编写于 作者: A Al Viro 提交者: Linus Torvalds

fix braindamage in audit_tree.c untag_chunk()

... aka "Al had badly fscked up when writing that thing and nobody
noticed until Eric had fixed leaks that used to mask the breakage".

The function essentially creates a copy of old array sans one element
and replaces the references to elements of original (they are on cyclic
lists) with those to corresponding elements of new one.  After that the
old one is fair game for freeing.

First of all, there's a dumb braino: when we get to list_replace_init we
use indices for wrong arrays - position in new one with the old array
and vice versa.

Another bug is more subtle - termination condition is wrong if the
element to be excluded happens to be the last one.  We shouldn't go
until we fill the new array, we should go until we'd finished the old
one.  Otherwise the element we are trying to kill will remain on the
cyclic lists...

That crap used to be masked by several leaks, so it was not quite
trivial to hit.  Eric had fixed some of those leaks a while ago and the
shit had hit the fan...
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 9b0fd114
...@@ -277,7 +277,7 @@ static void untag_chunk(struct node *p) ...@@ -277,7 +277,7 @@ static void untag_chunk(struct node *p)
owner->root = NULL; owner->root = NULL;
} }
for (i = j = 0; i < size; i++, j++) { for (i = j = 0; j <= size; i++, j++) {
struct audit_tree *s; struct audit_tree *s;
if (&chunk->owners[j] == p) { if (&chunk->owners[j] == p) {
list_del_init(&p->list); list_del_init(&p->list);
...@@ -290,7 +290,7 @@ static void untag_chunk(struct node *p) ...@@ -290,7 +290,7 @@ static void untag_chunk(struct node *p)
if (!s) /* result of earlier fallback */ if (!s) /* result of earlier fallback */
continue; continue;
get_tree(s); get_tree(s);
list_replace_init(&chunk->owners[i].list, &new->owners[j].list); list_replace_init(&chunk->owners[j].list, &new->owners[i].list);
} }
list_replace_rcu(&chunk->hash, &new->hash); list_replace_rcu(&chunk->hash, &new->hash);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册