* [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)
0 siblings, 1 reply; 2+ 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 [flat|nested] 2+ 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)
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-11-17 9:00 UTC | newest]
Thread overview: 2+ 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)
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®