* [PATCH] fork: mark memcpy() in dup_mm() with data_race()
@ 2026-11-17 5:59 Muhammad Haris Awan
2026-11-17 8:59 ` David Hildenbrand (Arm)
2026-11-17 12:58 ` Lorenzo Stoakes (ARM)
0 siblings, 2 replies; 6+ messages in thread
From: Muhammad Haris Awan @ 2026-11-17 5:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Ingo Molnar, Peter Zijlstra, Kees Cook, David Hildenbrand,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-mm, linux-kernel,
syzkaller-bugs
KCSAN reported a data race between dup_mm() copying oldmm via
memcpy(mm, oldmm, sizeof(*mm)) and lru_gen_del_mm() modifying
oldmm->lru_gen.list when an adjacent mm_struct on the shared
mm_list->fifo is removed under mm_list->lock.
oldmm->lru_gen and oldmm->mmlist are protected by mm_list->lock /
mmlist_lock (or updated locklessly via lru_gen_use_mm()), not
oldmm->mmap_lock. Because struct mm_struct uses __randomize_layout and
mm_init() immediately reinitializes these fields on the new mm, wrap
the memcpy() in data_race(), matching dup_vma() in mm/vma_init.c.
Fixes: bd74fdaea146 ("mm: multi-gen LRU: support page table walks")
Reported-by: syzbot+c6e1b1b32ff2fc3b7d60@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c6e1b1b32ff2fc3b7d60
Signed-off-by: Muhammad Haris Awan <m.harisawan@icloud.com>
---
kernel/fork.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d5..14ac9a070 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1539,7 +1539,12 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,
goto fail_uprobe;
}
- memcpy(mm, oldmm, sizeof(*mm));
+ /*
+ * oldmm->lru_gen and oldmm->mmlist may be modified concurrently under
+ * mm_list->lock / mmlist_lock or locklessly via lru_gen_use_mm(),
+ * and mm_init() will immediately reinitialize them.
+ */
+ data_race(memcpy(mm, oldmm, sizeof(*mm)));
if (!mm_init(mm, tsk)) {
mmap_write_unlock(oldmm);
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
2026-11-17 5:59 [PATCH] fork: mark memcpy() in dup_mm() with data_race() Muhammad Haris Awan
@ 2026-11-17 8:59 ` David Hildenbrand (Arm)
2026-11-17 10:24 ` Muhammad Haris Awan
2026-11-17 12:58 ` Lorenzo Stoakes (ARM)
1 sibling, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-17 8:59 UTC (permalink / raw)
To: Muhammad Haris Awan, Andrew Morton
Cc: Ingo Molnar, Peter Zijlstra, Kees Cook, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-mm, linux-kernel,
syzkaller-bugs
On 11/17/26 06:59, Muhammad Haris Awan wrote:
> KCSAN reported a data race between dup_mm() copying oldmm via
> memcpy(mm, oldmm, sizeof(*mm)) and lru_gen_del_mm() modifying
> oldmm->lru_gen.list when an adjacent mm_struct on the shared
> mm_list->fifo is removed under mm_list->lock.
>
> oldmm->lru_gen and oldmm->mmlist are protected by mm_list->lock /
> mmlist_lock (or updated locklessly via lru_gen_use_mm()), not
> oldmm->mmap_lock. Because struct mm_struct uses __randomize_layout and
> mm_init() immediately reinitializes these fields on the new mm, wrap
> the memcpy() in data_race(), matching dup_vma() in mm/vma_init.c.
>
> Fixes: bd74fdaea146 ("mm: multi-gen LRU: support page table walks")
> Reported-by: syzbot+c6e1b1b32ff2fc3b7d60@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=c6e1b1b32ff2fc3b7d60
> Signed-off-by: Muhammad Haris Awan <m.harisawan@icloud.com>
> ---
> kernel/fork.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 5efceb8d5..14ac9a070 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1539,7 +1539,12 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,
> goto fail_uprobe;
> }
>
> - memcpy(mm, oldmm, sizeof(*mm));
> + /*
> + * oldmm->lru_gen and oldmm->mmlist may be modified concurrently under
> + * mm_list->lock / mmlist_lock or locklessly via lru_gen_use_mm(),
> + * and mm_init() will immediately reinitialize them.
> + */
> + data_race(memcpy(mm, oldmm, sizeof(*mm)));
>
> if (!mm_init(mm, tsk)) {
> mmap_write_unlock(oldmm);
I hate that lru_gen_del_mm() would have to mess with that.
Is there no way we can teach reclaim code to not mess with MMs that are being
initialized?
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
2026-11-17 8:59 ` David Hildenbrand (Arm)
@ 2026-11-17 10:24 ` Muhammad Haris Awan
2026-11-17 10:54 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 6+ messages in thread
From: Muhammad Haris Awan @ 2026-11-17 10:24 UTC (permalink / raw)
To: David Hildenbrand
Cc: Andrew Morton, Ingo Molnar, Peter Zijlstra, Kees Cook,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-mm, linux-kernel,
syzkaller-bugs
Hi David,
Reclaim isn't touching the new mm being initialized (which isn't added to
mm_list->fifo until lru_gen_add_mm() at the end of copy_process()).
The KCSAN read is on oldmm inside dup_mm()'s memcpy(mm, oldmm, sizeof(*mm)):
oldmm is an already-live mm sitting on mm_list->fifo, so when an adjacent
exiting mm calls lru_gen_del_mm(), list_del_init() updates
oldmm->lru_gen.list.next/.prev under mm_list->lock.
Since oldmm is live, lru_gen_del_mm() has to update those list pointers.
The alternatives in dup_mm() would be taking mm_list->lock (plus
mmlist_lock) during fork, or avoiding copying oldmm->lru_gen / oldmm->mmlist
(awkward because struct mm_struct uses __randomize_layout). Wrapping the
memcpy() in data_race() avoids locking on fork and matches dup_vma() in
mm/vma_init.c.
Thanks,
Muhammad Haris Awan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
2026-11-17 10:24 ` Muhammad Haris Awan
@ 2026-11-17 10:54 ` David Hildenbrand (Arm)
2026-11-17 13:02 ` Lorenzo Stoakes (ARM)
0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-17 10:54 UTC (permalink / raw)
To: Muhammad Haris Awan
Cc: Andrew Morton, Ingo Molnar, Peter Zijlstra, Kees Cook,
Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-mm, linux-kernel,
syzkaller-bugs
On 11/17/26 11:24, Muhammad Haris Awan wrote:
> Hi David,
>
> Reclaim isn't touching the new mm being initialized (which isn't added to
> mm_list->fifo until lru_gen_add_mm() at the end of copy_process()).
Oh, that makes sense.
>
> The KCSAN read is on oldmm inside dup_mm()'s memcpy(mm, oldmm, sizeof(*mm)):
> oldmm is an already-live mm sitting on mm_list->fifo, so when an adjacent
> exiting mm calls lru_gen_del_mm(), list_del_init() updates
> oldmm->lru_gen.list.next/.prev under mm_list->lock.
> > Since oldmm is live, lru_gen_del_mm() has to update those list pointers.
> The alternatives in dup_mm() would be taking mm_list->lock (plus
> mmlist_lock) during fork, or avoiding copying oldmm->lru_gen / oldmm->mmlist
> (awkward because struct mm_struct uses __randomize_layout). Wrapping the
> memcpy() in data_race() avoids locking on fork and matches dup_vma() in
> mm/vma_init.c.
Yeah, the only concern I have is that this is the big hammer for any members,
not just the ones where we expect races.
We hold the mmap lock in write mode, so one would assume that nothing can rally
modify it. Well, besides these list exceptions.
Let's see what others have to say, but I guess this is fine then, although a bit
suboptimal.
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
2026-11-17 10:54 ` David Hildenbrand (Arm)
@ 2026-11-17 13:02 ` Lorenzo Stoakes (ARM)
0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-17 13:02 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Muhammad Haris Awan, Andrew Morton, Ingo Molnar, Peter Zijlstra,
Kees Cook, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-mm, linux-kernel,
syzkaller-bugs
On Tue, Nov 17, 2026 at 11:54:28AM +0100, David Hildenbrand (Arm) wrote:
> On 11/17/26 11:24, Muhammad Haris Awan wrote:
> > Hi David,
> >
> > Reclaim isn't touching the new mm being initialized (which isn't added to
> > mm_list->fifo until lru_gen_add_mm() at the end of copy_process()).
>
> Oh, that makes sense.
>
> >
> > The KCSAN read is on oldmm inside dup_mm()'s memcpy(mm, oldmm, sizeof(*mm)):
> > oldmm is an already-live mm sitting on mm_list->fifo, so when an adjacent
> > exiting mm calls lru_gen_del_mm(), list_del_init() updates
> > oldmm->lru_gen.list.next/.prev under mm_list->lock.
> > > Since oldmm is live, lru_gen_del_mm() has to update those list pointers.
> > The alternatives in dup_mm() would be taking mm_list->lock (plus
> > mmlist_lock) during fork, or avoiding copying oldmm->lru_gen / oldmm->mmlist
> > (awkward because struct mm_struct uses __randomize_layout). Wrapping the
The focus on __randomize_layout is really weird. What, were you assuming you
could avoid it by using offsetof() or something? That'd be an awful solution
anyway?
> > memcpy() in data_race() avoids locking on fork and matches dup_vma() in
> > mm/vma_init.c.
(BTW this reads like it's an AI-generated reply... sigh.)
_My_ LLM says that lock thing wouldn't work without really fiddly changes as it
relies on memcg and you'd have to double-check a concurrent change didn't take
place and etc.
All to silence a once-in-4-year KCSAN report...
>
> Yeah, the only concern I have is that this is the big hammer for any members,
> not just the ones where we expect races.
>
> We hold the mmap lock in write mode, so one would assume that nothing can rally
> modify it. Well, besides these list exceptions.
>
> Let's see what others have to say, but I guess this is fine then, although a bit
> suboptimal.
Replied, but this for me is far from fine, since it means that we basically no
longer have any KCSAN protection against most of what fork does.
Since it's 1 report in 4 years, I think we can just live without it. And I don't
really trust the submitter to not try to slop some broken alternative solution.
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
2026-11-17 5:59 [PATCH] fork: mark memcpy() in dup_mm() with data_race() Muhammad Haris Awan
2026-11-17 8:59 ` David Hildenbrand (Arm)
@ 2026-11-17 12:58 ` Lorenzo Stoakes (ARM)
1 sibling, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-17 12:58 UTC (permalink / raw)
To: Muhammad Haris Awan
Cc: Andrew Morton, Ingo Molnar, Peter Zijlstra, Kees Cook,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, linux-mm,
linux-kernel, syzkaller-bugs
On Tue, Nov 17, 2026 at 10:59:56AM +0500, Muhammad Haris Awan wrote:
> KCSAN reported a data race between dup_mm() copying oldmm via
> memcpy(mm, oldmm, sizeof(*mm)) and lru_gen_del_mm() modifying
> oldmm->lru_gen.list when an adjacent mm_struct on the shared
> mm_list->fifo is removed under mm_list->lock.
>
> oldmm->lru_gen and oldmm->mmlist are protected by mm_list->lock /
> mmlist_lock (or updated locklessly via lru_gen_use_mm()), not
> oldmm->mmap_lock. Because struct mm_struct uses __randomize_layout and
Firstly what on earth does __randomize_layout have to do with anything?
Secondly, ef694e2d2101 takes the oldmm mmap_lock so what you're saying here is
wrong.
The problem is that you end up manipulating a neighbouring mm in the list.
> mm_init() immediately reinitializes these fields on the new mm, wrap
> the memcpy() in data_race(), matching dup_vma() in mm/vma_init.c.
>
> Fixes: bd74fdaea146 ("mm: multi-gen LRU: support page table walks")
> Reported-by: syzbot+c6e1b1b32ff2fc3b7d60@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=c6e1b1b32ff2fc3b7d60
> Signed-off-by: Muhammad Haris Awan <m.harisawan@icloud.com>
Given you're a complete newcomer to mm I do have to ask if you used an LLM, you
should mention that somewhere in the commit message or at least below the '---'
by convention.
And it's vital that you understand everything you submit as per
https://docs.kernel.org/process/generated-content.html
So what work are you doing with regard to KCSAN, data races and mm lifetime that
led you to this? And what expertise are you coming to it with?
> ---
> kernel/fork.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 5efceb8d5..14ac9a070 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1539,7 +1539,12 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,
> goto fail_uprobe;
> }
>
> - memcpy(mm, oldmm, sizeof(*mm));
> + /*
> + * oldmm->lru_gen and oldmm->mmlist may be modified concurrently under
> + * mm_list->lock / mmlist_lock or locklessly via lru_gen_use_mm(),
> + * and mm_init() will immediately reinitialize them.
> + */
I really don't like this comment that is begging to bit rot.
> + data_race(memcpy(mm, oldmm, sizeof(*mm)));
That's _really_ horrible.
That's now making it so any race that matters is ignored in a _super_ sensitive
part of mm, because MGLRU decided it was a special snowflake.
But I'm confused as to why in 4 years nobody reported a KCSAN issue with this?
Surely something increased the likelihood of this race?
In any case, this is MGLRU's fault. It's abusing the mm data structure and doing
something it shouldn't.
So any fix should be there. Similarly for other mmlist users.
Or really, given this seems to be a one-off, spurious, KCSAN report, do nothing
until it becomes clear this will be reported more than once in 4 years? :)
>
> if (!mm_init(mm, tsk)) {
> mmap_write_unlock(oldmm);
> --
> 2.56.0
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 13:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 5:59 [PATCH] fork: mark memcpy() in dup_mm() with data_race() Muhammad Haris Awan
2026-11-17 8:59 ` David Hildenbrand (Arm)
2026-11-17 10:24 ` Muhammad Haris Awan
2026-11-17 10:54 ` David Hildenbrand (Arm)
2026-11-17 13:02 ` Lorenzo Stoakes (ARM)
2026-11-17 12:58 ` Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox