[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210824085132.GA12376@quack2.suse.cz>
Date: Tue, 24 Aug 2021 10:51:32 +0200
From: Jan Kara <jack@...e.cz>
To: Richard Guy Briggs <rgb@...hat.com>
Cc: Linux-Audit Mailing List <linux-audit@...hat.com>,
LKML <linux-kernel@...r.kernel.org>,
Paul Moore <paul@...l-moore.com>,
Eric Paris <eparis@...isplace.org>,
Steve Grubb <sgrubb@...hat.com>, Jan Kara <jack@...e.cz>,
Will Deacon <will@...nel.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Seiji Nishikawa <snishika@...hat.com>
Subject: Re: [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees
refcount underflow and UAF
On Mon 23-08-21 22:04:09, Richard Guy Briggs wrote:
> AUDIT_TRIM is expected to be idempotent, but multiple executions resulted in a
> refcount underflow and use-after-free.
>
> git bisect fingered commit fb041bb7c0a918b95c6889fc965cdc4a75b4c0ca (2019-11)
> ("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 8432c70062978d9a57bde6715496d585ec520c3e (2018-11)
> ("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.
>
> Fixes: 8432c7006297 ("audit: Simplify locking around untag_chunk()")
> Signed-off-by: Richard Guy Briggs <rgb@...hat.com>
> Cc: Jan Kara <jack@...e.cz>
> Cc: Will Deacon <will@...nel.org>
> Cc: Alexander Viro <viro@...iv.linux.org.uk>
> Cc: Seiji Nishikawa <snishika@...hat.com>
Ah, that was indeed a stupid mistake. Thanks for debugging this! The patch
looks good to me. You can add:
Reviewed-by: Jan Kara <jack@...e.cz>
Honza
> ---
> kernel/audit_tree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
> index b2be4e978ba3..2cd7b5694422 100644
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -593,7 +593,6 @@ static void prune_tree_chunks(struct audit_tree *victim, bool tagged)
> spin_lock(&hash_lock);
> }
> spin_unlock(&hash_lock);
> - put_tree(victim);
> }
>
> /*
> @@ -602,6 +601,7 @@ static void prune_tree_chunks(struct audit_tree *victim, bool tagged)
> static void prune_one(struct audit_tree *victim)
> {
> prune_tree_chunks(victim, false);
> + put_tree(victim);
> }
>
> /* trim the uncommitted chunks from tree */
> --
> 2.27.0
>
--
Jan Kara <jack@...e.com>
SUSE Labs, CR
Powered by blists - more mailing lists