[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <25a402bb9ddfecba22b5b24684d950494fc7410d@linux.dev>
Date: Wed, 23 Apr 2025 14:33:37 +0000
From: "Jiayuan Chen" <jiayuan.chen@...ux.dev>
To: "Oleg Nesterov" <oleg@...hat.com>
Cc: linux-kernel@...r.kernel.org, mrpre@....com, mkoutny@...e.com,
syzbot+adcaa842b762a1762e7d@...kaller.appspotmail.com,
syzbot+fab52e3459fa2f95df57@...kaller.appspotmail.com,
syzbot+0718f65353d72efaac1e@...kaller.appspotmail.com, "Andrew Morton"
<akpm@...ux-foundation.org>, "Christian Brauner" <brauner@...nel.org>,
"Lorenzo Stoakes" <lorenzo.stoakes@...cle.com>, "Liam R. Howlett"
<Liam.Howlett@...cle.com>, "Suren Baghdasaryan" <surenb@...gle.com>, "Wei
Yang" <richard.weiyang@...il.com>, "David Hildenbrand"
<david@...hat.com>, "Al Viro" <viro@...iv.linux.org.uk>, "Mateusz Guzik"
<mjguzik@...il.com>, "Joel Granados" <joel.granados@...nel.org>, "Jens
Axboe" <axboe@...nel.dk>, "Wei Liu" <wei.liu@...nel.org>, "Frederic
Weisbecker" <frederic@...nel.org>
Subject: Re: [PATCH v1] pid: annotate data-races around pid_ns->pid_allocated
April 23, 2025 at 21:51, "Oleg Nesterov" <oleg@...hat.com> wrote:
>
> On 04/23, Jiayuan Chen wrote:
>
> >
> > Suppress syzbot reports by annotating these accesses using
> >
> > READ_ONCE() / WRITE_ONCE().
> >
>
> ...
>
> >
> > --- a/kernel/pid.c
> >
> > +++ b/kernel/pid.c
> >
> > @@ -122,7 +122,8 @@ void free_pid(struct pid *pid)
> >
> > for (i = 0; i <= pid->level; i++) {
> >
> > struct upid *upid = pid->numbers + i;
> >
> > struct pid_namespace *ns = upid->ns;
> >
> > - switch (--ns->pid_allocated) {
> >
> > + WRITE_ONCE(ns->pid_allocated, READ_ONCE(ns->pid_allocated) - 1);
> >
> > + switch (READ_ONCE(ns->pid_allocated)) {
> >
>
> I keep forgetting how kcsan works, but we don't need
>
> READ_ONCE(ns->pid_allocated) under pidmap_lock?
>
> Same for other functions which read/modify ->pid_allocated with
>
> this lock held.
>
> Oleg.
>
However, not all places that read/write pid_allocated are locked,
for example:
https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/pid_namespace.c#n271
https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/fork.c#n2602
So, in fact, the pidmap_lock is not effective. And if we were to add locks
to all these places, it would be too heavy.
There's no actual impact on usage without locks, so I think it might be more
suitable to add these macros, KASAN can recognize READ_ONCE and WRITE_ONCE
and suppress warnings.
Thanks.
Powered by blists - more mailing lists