]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
audit: move put_tree() to avoid trim_trees refcount underflow and UAF
authorRichard Guy Briggs <rgb@redhat.com>
Tue, 24 Aug 2021 02:04:09 +0000 (22:04 -0400)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 24 Sep 2021 09:58:54 +0000 (11:58 +0200)
commitcd073d0c68de988b6fb6229389832bca334571bf
treee21e3c6f91c60892b1e5d7e960411d9649d2d4fd
parente0b899bbdcc63b4050f60f1c5a41dd7db38f4eca
audit: move put_tree() to avoid trim_trees refcount underflow and UAF

BugLink: https://bugs.launchpad.net/bugs/1944610
commit 67d69e9d1a6c889d98951c1d74b19332ce0565af upstream.

AUDIT_TRIM is expected to be idempotent, but multiple executions resulted
in a refcount underflow and use-after-free.

git bisect fingered commit fb041bb7c0a9 ("locking/refcount: Consolidate
implementations of refcount_t") but this patch with its more thorough
checking that wasn't in the x86 assembly code merely exposed a previously
existing tree refcount imbalance in the case of tree trimming code that
was refactored with prune_one() to remove a tree introduced in
commit 8432c7006297 ("audit: Simplify locking around untag_chunk()")

Move the put_tree() to cover only the prune_one() case.

Passes audit-testsuite and 3 passes of "auditctl -t" with at least one
directory watch.

Cc: Jan Kara <jack@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Seiji Nishikawa <snishika@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 8432c7006297 ("audit: Simplify locking around untag_chunk()")
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
[PM: reformatted/cleaned-up the commit description]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
kernel/audit_tree.c