From: Bradley Morgan <brads@mainlining.org>
To: bbnpreetsingh@gmail.com
Cc: linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, paul@paul-moore.com,
sergeh@kernel.org,
syzbot+557fdc985d6ac3831e14@syzkaller.appspotmail.com,
syzbot+ee58b040032d8bed63d9@syzkaller.appspotmail.com
Subject: Re: [PATCH] cred: mark the copy in prepare_creds() as a data race
Date: Sun, 01 Nov 2026 02:25:23 +0000 [thread overview]
Message-ID: <A25971F6-A534-495D-A115-72B4BAF7EFE4@mainlining.org> (raw)
In-Reply-To: <20261030033308.7-1-bbnpreetsingh@gmail.com>
On 30 October 2026 03:33:08 GMT, Babanpreet Singh <bbnpreetsingh@gmail.com>
wrote:
Well! Okay then. Nearly missed this (sigh)
>prepare_creds() copies the old cred while other tasks may be changing
>its refcount. Mark as data race.
It's not the ref count,
Both reports show a 4 byte write 168 bytes into the object:
write to 0xffff888103d7fbe8 of 4 bytes
read to 0xffff888103d7fb40 of 184 bytes
0xfbe8 - 0xfb40 = 0xa8. usage is an atomic_long_t at offset 0, so a hit
there would be 8 bytes at the very start of the struct. What actually
raced is this line of get_cred_many(),
nonconst_cred->non_rcu = 0;
a plain write to a published cred. The atomic_long_add() under it never
shows up, iirc KCSAN models the atomic fine. So non_rcu in the subject
and the description, thats what the fix is about.
>
>Reported-by: syzbot+ee58b040032d8bed63d9@syzkaller.appspotmail.com
>Closes: https://syzkaller.appspot.com/bug?extid=ee58b040032d8bed63d9
>Reported-by: syzbot+557fdc985d6ac3831e14@syzkaller.appspotmail.com
>Closes: https://syzkaller.appspot.com/bug?extid=557fdc985d6ac3831e14
>Assisted-by: Claude:claude-opus-5-5
>Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
>---
>Compile tested with gcc and clang; the KCSAN instrumentation of
>kernel/cred.o was checked before and after.
Sooo? What was the after? Could you have said something like "This bug
isn't reproduced any longer, tested by soandso"
> kernel/cred.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/kernel/cred.c b/kernel/cred.c
>index d01df40a9a386..d212db445c138 100644
>--- a/kernel/cred.c
>+++ b/kernel/cred.c
>@@ -189,7 +189,7 @@ struct cred *prepare_creds(void)
> kdebug("prepare_creds() alloc %p", new);
>
> old = task->cred;
>- memcpy(new, old, sizeof(struct cred));
>+ data_race(memcpy(new, old, sizeof(struct cred)));
Hmmm. Comment..?
WARNING: data_race without comment
#12: FILE: kernel/cred.c:192:
+ data_race(memcpy(new, old, sizeof(struct cred)));
The docs says it plain: "Applications of
data_race() should have a comment so as to document the reasoning behind
why it was deemed safe."
I suggest
/*
* The only fields a published cred can still change are non_rcu and
* usage, and both get set fresh just below. Keeping a copied non_rcu
* would be wrong anyway, __put_cred() then skips the grace period.
*/
data_race(memcpy(new, old, sizeof(struct cred)));
Feel free to bikeshed
prepare_kernel_cred() ALSO does the same copy further down the same file,
*new = *old, off get_task_cred(daemon). Same race, untouched. Did you mean
to leave it out, or has syzbot just not hit it yet?
>
> new->non_rcu = 0;
> atomic_long_set(&new->usage, 1);
>
>base-commit: 881f19c2ffbc73f351b257e09c71e6059939b770
>
--- Thanks!
prev parent reply other threads:[~2026-11-01 2:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 3:33 Babanpreet Singh
2026-11-01 2:25 ` Bradley Morgan [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=A25971F6-A534-495D-A115-72B4BAF7EFE4@mainlining.org \
--to=brads@mainlining.org \
--cc=bbnpreetsingh@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sergeh@kernel.org \
--cc=syzbot+557fdc985d6ac3831e14@syzkaller.appspotmail.com \
--cc=syzbot+ee58b040032d8bed63d9@syzkaller.appspotmail.com \
/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
all inboxes | Powered by JetHome®