Linux Security Modules development
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Jann Horn <jannh@google.com>, Serge Hallyn <sergeh@kernel.org>
Cc: Eric Paris <eparis@redhat.com>, James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, audit@vger.kernel.org,
	Jann Horn <jannh@google.com>
Subject: Re: [PATCH] cred: clarify that task_struct::cred is only for the  current task
Date: Mon, 10 Aug 2026 15:41:54 -0400	[thread overview]
Message-ID: <2bdf79f45c5eb2ea66d59904418081c5@paul-moore.com> (raw)
In-Reply-To: <20260806-cred-nonrcu-annotation-fix-v1-1-5fd149b2ab54@google.com>

On Aug  6, 2026 Jann Horn <jannh@google.com> wrote:
> 
> The `cred` field in task_struct is currently marked as __rcu, but that's
> not true: It can point to credentials from access_override_creds(), which
> do not get freed with RCU delay.
> 
> What actually protects task_struct::cred is that accessing it is only
> permitted for the current task (except for setting up a child during fork()
> or tearing down a dead process).
> (There is currently code in Smack that violates this rule, but that's a bug
> and causes UAF, I have sent a separate fix for that.)
> 
> Clarify this, remove the __rcu marker, and remove RCU helpers from all
> accesses to this field.
> 
> Signed-off-by: Jann Horn <jannh@google.com>
> ---
> For context:
> There have been at least two UAFs of struct cred that I'm aware of, both
> caused by wrong use of task_struct::cred:
> 
>  - https://git.kernel.org/linus/a3727a8bac0a9e77c70820655fd8715523ba3db7
>  - https://lore.kernel.org/all/20260806-smack-uaf-fix-v1-1-26426d389a26@google.com/
> ---
>  include/linux/cred.h  | 17 +++++++++++------
>  include/linux/sched.h |  8 ++++++--
>  kernel/auditsc.c      |  5 +++--
>  kernel/cred.c         |  2 +-
>  security/lsm_init.c   |  2 +-
>  5 files changed, 22 insertions(+), 12 deletions(-)

This looks good to me, with one small nit below, but as we are at -rc7
I think this is best kept until after the upcoming merge window so it
has more than a few days in linux-next.  I'm going to merge this into
lsm/dev-staging with the expectation of merging it into lsm/dev after
the upcoming merge window closes.  If anyone wishes to object to this
patch or add their own review/ACK/test tag before then, please do.

Thanks Jann.

> diff --git a/security/lsm_init.c b/security/lsm_init.c
> index 7c0fd17f1601..1328a2ceef4b 100644
> --- a/security/lsm_init.c
> +++ b/security/lsm_init.c
> @@ -476,7 +476,7 @@ int __init security_init(void)
>  						    blob_sizes.lbs_inode, 0,
>  						    SLAB_PANIC, NULL);
>  
> -	if (lsm_cred_alloc((struct cred *)unrcu_pointer(current->cred),
> +	if (lsm_cred_alloc((struct cred *)current->cred,
>  			   GFP_KERNEL))

Just a FYI, but I pulled the GFP_KERNEL up on the line above while
merging since it now fits.

--
paul-moore.com

      reply	other threads:[~2026-08-10 19:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 20:15 [PATCH] cred: clarify that task_struct::cred is only for the current task Jann Horn
2026-08-10 19:41 ` Paul Moore [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2bdf79f45c5eb2ea66d59904418081c5@paul-moore.com \
    --to=paul@paul-moore.com \
    --cc=audit@vger.kernel.org \
    --cc=eparis@redhat.com \
    --cc=jannh@google.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=sergeh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox