linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF
@ 2021-08-24  2:04 Richard Guy Briggs
  2021-08-24  8:51 ` Jan Kara
  2021-08-24 22:58 ` Paul Moore
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Guy Briggs @ 2021-08-24  2:04 UTC (permalink / raw)
  To: Linux-Audit Mailing List, LKML
  Cc: Paul Moore, Eric Paris, Steve Grubb, Richard Guy Briggs,
	Jan Kara, Will Deacon, Alexander Viro, Seiji Nishikawa

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@redhat.com>
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>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF
  2021-08-24  2:04 [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF Richard Guy Briggs
@ 2021-08-24  8:51 ` Jan Kara
  2021-08-24 22:58 ` Paul Moore
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2021-08-24  8:51 UTC (permalink / raw)
  To: Richard Guy Briggs
  Cc: Linux-Audit Mailing List, LKML, Paul Moore, Eric Paris,
	Steve Grubb, Jan Kara, Will Deacon, Alexander Viro,
	Seiji Nishikawa

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@redhat.com>
> 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>

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@suse.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@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF
  2021-08-24  2:04 [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF Richard Guy Briggs
  2021-08-24  8:51 ` Jan Kara
@ 2021-08-24 22:58 ` Paul Moore
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Moore @ 2021-08-24 22:58 UTC (permalink / raw)
  To: Richard Guy Briggs
  Cc: Linux-Audit Mailing List, LKML, Eric Paris, Steve Grubb,
	Jan Kara, Will Deacon, Alexander Viro, Seiji Nishikawa

On Mon, Aug 23, 2021 at 10:05 PM Richard Guy Briggs <rgb@redhat.com> 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@redhat.com>
> 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>
> ---
>  kernel/audit_tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

First a quick comment about the commit description, when referencing
specific commits in the description please use the same format that
you used in the "Fixes:" tag; it makes the description easier to read.
No need to resend, I fixed it when I merged your patch, but something
to keep in mind for the future.

As for the patch itself, thanks for finding this and sending a fix.
Normally this is something I would send up to Linus at the end of the
week during the -rcX phase, but since we are currently at -rc7 I'm
going to simply add the -stable marking and merge it into audit/next
to get pushed up to Linus early next week, assuming we see v5.14
released this Sunday.  If for some reason we see a v5.14-rc8 next week
I'll adjust things and send it to Linus as a -stable patch.

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-24 22:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24  2:04 [ghak-trim PATCH v1] audit: move put_tree() to avoid trim_trees refcount underflow and UAF Richard Guy Briggs
2021-08-24  8:51 ` Jan Kara
2021-08-24 22:58 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).