cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michal Koutný" <mkoutny@suse.com>
To: syzbot <syzbot+f3188428a0ed36870056@syzkaller.appspotmail.com>
Cc: cgroups@vger.kernel.org, hannes@cmpxchg.org,
	 linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	tj@kernel.org
Subject: Re: [syzbot] [cgroups?] KCSAN: data-race in cgroup_migrate_execute / memcpy_and_pad
Date: Thu, 10 Jul 2025 18:27:41 +0200	[thread overview]
Message-ID: <wuoepqhwfz3akami7wigstoszqhmb6t5tflnso47kedxrtg23m@qofn6qxq3tyn> (raw)
In-Reply-To: <686bb62b.a00a0220.c7b3.0083.GAE@google.com>

[-- Attachment #1: Type: text/plain, Size: 3130 bytes --]

On Mon, Jul 07, 2025 at 04:57:31AM -0700, syzbot <syzbot+f3188428a0ed36870056@syzkaller.appspotmail.com> wrote:
> ==================================================================
> BUG: KCSAN: data-race in cgroup_migrate_execute / memcpy_and_pad
> 
> write to 0xffff888133646ad0 of 8 bytes by task 4554 on cpu 1:
>  __list_splice include/linux/list.h:533 [inline]
>  list_splice_tail_init include/linux/list.h:589 [inline]
>  cgroup_migrate_execute+0x6b5/0x7f0 kernel/cgroup/cgroup.c:2689
>  cgroup_update_dfl_csses kernel/cgroup/cgroup.c:3135 [inline]
>  cgroup_apply_control+0x3ab/0x410 kernel/cgroup/cgroup.c:3375
>  cgroup_subtree_control_write+0x7d5/0xb80 kernel/cgroup/cgroup.c:3520
>  cgroup_file_write+0x194/0x350 kernel/cgroup/cgroup.c:4183
>  kernfs_fop_write_iter+0x1be/0x2d0 fs/kernfs/file.c:334
>  new_sync_write fs/read_write.c:593 [inline]
>  vfs_write+0x49d/0x8e0 fs/read_write.c:686
>  ksys_write+0xda/0x1a0 fs/read_write.c:738
>  __do_sys_write fs/read_write.c:749 [inline]
>  __se_sys_write fs/read_write.c:746 [inline]
>  __x64_sys_write+0x40/0x50 fs/read_write.c:746
>  x64_sys_call+0x2cdd/0x2fb0 arch/x86/include/generated/asm/syscalls_64.h:2
>  do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
>  do_syscall_64+0xd2/0x200 arch/x86/entry/syscall_64.c:94
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> 
> read to 0xffff888133646180 of 3200 bytes by task 4561 on cpu 0:
>  memcpy_and_pad+0x48/0x80 lib/string_helpers.c:1007
>  arch_dup_task_struct+0x2c/0x40 arch/x86/kernel/process.c:98
>  dup_task_struct+0x83/0x6a0 kernel/fork.c:873
>  copy_process+0x399/0x1f90 kernel/fork.c:1999
>  kernel_clone+0x16c/0x5b0 kernel/fork.c:2599
>  __do_sys_clone3 kernel/fork.c:2903 [inline]
>  __se_sys_clone3+0x1c2/0x200 kernel/fork.c:2882
>  __x64_sys_clone3+0x31/0x40 kernel/fork.c:2882
>  x64_sys_call+0x10c9/0x2fb0 arch/x86/include/generated/asm/syscalls_64.h:436
>  do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
>  do_syscall_64+0xd2/0x200 arch/x86/entry/syscall_64.c:94
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f

I assume the data race on parent->cg_list (not child->cg_list because
the parent is read).
The clone vs migration should be synchronized via
cgroup_threadgroup_rwsem but there's a window for the race:

	copy_process
	  dup_task_struct
	    child->cg_list = parent->cg_list
	  ...
	  [race window]
	  ...
	  cgroup_can_fork
	    cgroup_css_set_fork
	      cgroup_threadgroup_change_begin

	  ...
	  cgroup_post_fork
	    css_set_move_task
	      list_del_init(&child->cg_list);
	      list_add_tail(&child->cg_list, cset->tasks)
	    cgroup_threadgroup_change_end

The writer is
	list_splice_tail_init(&cset->mg_tasks, &cset->tasks);
i.e. the parent is either migrated itself or it's the last (tail) task
in destination css_set of another migration.

But whatever value child copied over from parent doesn't matter because
it is overwritten when the child is inserted into appropriate cset in
cgroup_post_fork (properly synced via css_set_lock).

I.e. I'm not overexcited about this race but thanks syzbot.

Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

      reply	other threads:[~2025-07-10 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 11:57 [syzbot] [cgroups?] KCSAN: data-race in cgroup_migrate_execute / memcpy_and_pad syzbot
2025-07-10 16:27 ` Michal Koutný [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=wuoepqhwfz3akami7wigstoszqhmb6t5tflnso47kedxrtg23m@qofn6qxq3tyn \
    --to=mkoutny@suse.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+f3188428a0ed36870056@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tj@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;
as well as URLs for NNTP newsgroup(s).