fix braindamage in audit_tree.c untag_chunk()
commit591e4112cc4b18a1ad64241a589d3368d1c5ac3a
authorAl Viro <viro@ZenIV.linux.org.uk>
Sat, 19 Dec 2009 15:59:45 +0000 (19 15:59 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 18 Jan 2010 18:28:49 +0000 (18 10:28 -0800)
tree6bc792243fc2ceed11b56bb2f1cd5d7263233730
parente49ba5624b6524846876a4de8729a89f9dbcbac3
fix braindamage in audit_tree.c untag_chunk()

commit 6f5d51148921c242680a7a1d9913384a30ab3cbe upstream.

... 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: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
kernel/audit_tree.c