public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked
@ 2026-02-25  1:15 Chen Ridong
  2026-02-25  6:34 ` Waiman Long
  2026-02-25 17:40 ` Tejun Heo
  0 siblings, 2 replies; 4+ messages in thread
From: Chen Ridong @ 2026-02-25  1:15 UTC (permalink / raw)
  To: longman, chenridong, tj, hannes, mkoutny; +Cc: cgroups, linux-kernel, lujialin4

From: Chen Ridong <chenridong@huawei.com>

A null-pointer-dereference bug was reported by syzbot:

Oops: general protection fault, probably for address 0xdffffc0000000000:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: 0010:bitmap_subset include/linux/bitmap.h:433 [inline]
RIP: 0010:cpumask_subset include/linux/cpumask.h:836 [inline]
RIP: 0010:rebuild_sched_domains_locked kernel/cgroup/cpuset.c:967
RSP: 0018:ffffc90003ecfbc0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000020
RDX: ffff888028de0000 RSI: ffffffff8200f003 RDI: ffffffff8df14f28
RBP: 0000000000000000 R08: 0000000000000cc0 R09: 00000000ffffffff
R10: ffffffff8e7d95b3 R11: 0000000000000001 R12: 0000000000000000
R13: 00000000000f4240 R14: dffffc0000000000 R15: 0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2f463fff CR3: 000000003704c000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 rebuild_sched_domains_cpuslocked kernel/cgroup/cpuset.c:983 [inline]
 rebuild_sched_domains+0x21/0x40 kernel/cgroup/cpuset.c:990
 sched_rt_handler+0xb5/0xe0 kernel/sched/rt.c:2911
 proc_sys_call_handler+0x47f/0x5a0 fs/proc/proc_sysctl.c:600
 new_sync_write fs/read_write.c:595 [inline]
 vfs_write+0x6ac/0x1070 fs/read_write.c:688
 ksys_write+0x12a/0x250 fs/read_write.c:740
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The issue occurs when generate_sched_domains() returns ndoms = 1 and
doms = NULL due to a kmalloc failure. This leads to a null-pointer
dereference when accessing doms in rebuild_sched_domains_locked().

Fix this by adding a NULL check for doms before accessing it.

Fixes: 6ee43047e8ad ("cpuset: Remove unnecessary checks in rebuild_sched_domains_locked")
Reported-by: syzbot+460792609a79c085f79f@syzkaller.appspotmail.com
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 9faf34377a88..8ebf2ab8f0df 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -962,7 +962,8 @@ void rebuild_sched_domains_locked(void)
 	* prevent the panic.
 	*/
 	for (i = 0; i < ndoms; ++i) {
-		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
+		if (doms && WARN_ON_ONCE(!cpumask_subset(doms[i],
+					 cpu_active_mask)))
 			return;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked
  2026-02-25  1:15 [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked Chen Ridong
@ 2026-02-25  6:34 ` Waiman Long
  2026-02-25 17:40 ` Tejun Heo
  1 sibling, 0 replies; 4+ messages in thread
From: Waiman Long @ 2026-02-25  6:34 UTC (permalink / raw)
  To: Chen Ridong, tj, hannes, mkoutny; +Cc: cgroups, linux-kernel, lujialin4

On 2/24/26 8:15 PM, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> A null-pointer-dereference bug was reported by syzbot:
>
> Oops: general protection fault, probably for address 0xdffffc0000000000:
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> RIP: 0010:bitmap_subset include/linux/bitmap.h:433 [inline]
> RIP: 0010:cpumask_subset include/linux/cpumask.h:836 [inline]
> RIP: 0010:rebuild_sched_domains_locked kernel/cgroup/cpuset.c:967
> RSP: 0018:ffffc90003ecfbc0 EFLAGS: 00010246
> RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000020
> RDX: ffff888028de0000 RSI: ffffffff8200f003 RDI: ffffffff8df14f28
> RBP: 0000000000000000 R08: 0000000000000cc0 R09: 00000000ffffffff
> R10: ffffffff8e7d95b3 R11: 0000000000000001 R12: 0000000000000000
> R13: 00000000000f4240 R14: dffffc0000000000 R15: 0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000001b2f463fff CR3: 000000003704c000 CR4: 00000000003526f0
> Call Trace:
>   <TASK>
>   rebuild_sched_domains_cpuslocked kernel/cgroup/cpuset.c:983 [inline]
>   rebuild_sched_domains+0x21/0x40 kernel/cgroup/cpuset.c:990
>   sched_rt_handler+0xb5/0xe0 kernel/sched/rt.c:2911
>   proc_sys_call_handler+0x47f/0x5a0 fs/proc/proc_sysctl.c:600
>   new_sync_write fs/read_write.c:595 [inline]
>   vfs_write+0x6ac/0x1070 fs/read_write.c:688
>   ksys_write+0x12a/0x250 fs/read_write.c:740
>   do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
>   do_syscall_64+0x106/0xf80 arch/x86/entry/syscall_64.c:94
>   entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> The issue occurs when generate_sched_domains() returns ndoms = 1 and
> doms = NULL due to a kmalloc failure. This leads to a null-pointer
> dereference when accessing doms in rebuild_sched_domains_locked().
>
> Fix this by adding a NULL check for doms before accessing it.
>
> Fixes: 6ee43047e8ad ("cpuset: Remove unnecessary checks in rebuild_sched_domains_locked")
> Reported-by: syzbot+460792609a79c085f79f@syzkaller.appspotmail.com
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>   kernel/cgroup/cpuset.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 9faf34377a88..8ebf2ab8f0df 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -962,7 +962,8 @@ void rebuild_sched_domains_locked(void)
>   	* prevent the panic.
>   	*/
>   	for (i = 0; i < ndoms; ++i) {
> -		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
> +		if (doms && WARN_ON_ONCE(!cpumask_subset(doms[i],
> +					 cpu_active_mask)))
>   			return;
>   	}
>   

I would prefer putting the doms check in the for loop without the line 
wrap, but that will work too.

Acked-by: Waiman Long <longman@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked
  2026-02-25  1:15 [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked Chen Ridong
  2026-02-25  6:34 ` Waiman Long
@ 2026-02-25 17:40 ` Tejun Heo
  2026-02-26  0:40   ` Chen Ridong
  1 sibling, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2026-02-25 17:40 UTC (permalink / raw)
  To: Chen Ridong; +Cc: longman, hannes, mkoutny, cgroups, linux-kernel, lujialin4

Hello,

Applied to cgroup/for-7.0-fixes with the following modification:

- Moved the NULL check into the for-loop condition per Waiman's
  suggestion.

-	for (i = 0; i < ndoms; ++i) {
-		if (doms && WARN_ON_ONCE(!cpumask_subset(doms[i],
-					 cpu_active_mask)))
+	for (i = 0; doms && i < ndoms; i++) {
+		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked
  2026-02-25 17:40 ` Tejun Heo
@ 2026-02-26  0:40   ` Chen Ridong
  0 siblings, 0 replies; 4+ messages in thread
From: Chen Ridong @ 2026-02-26  0:40 UTC (permalink / raw)
  To: Tejun Heo; +Cc: longman, hannes, mkoutny, cgroups, linux-kernel, lujialin4



On 2026/2/26 1:40, Tejun Heo wrote:
> Hello,
> 
> Applied to cgroup/for-7.0-fixes with the following modification:
> 
> - Moved the NULL check into the for-loop condition per Waiman's
>   suggestion.
> 
> -	for (i = 0; i < ndoms; ++i) {
> -		if (doms && WARN_ON_ONCE(!cpumask_subset(doms[i],
> -					 cpu_active_mask)))
> +	for (i = 0; doms && i < ndoms; i++) {
> +		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
> 
> Thanks.
> 
> --
> tejun

Thank you.

-- 
Best regards,
Ridong


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-26  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25  1:15 [PATCH -next] cgroup/cpuset: fix null-ptr-deref in rebuild_sched_domains_cpuslocked Chen Ridong
2026-02-25  6:34 ` Waiman Long
2026-02-25 17:40 ` Tejun Heo
2026-02-26  0:40   ` Chen Ridong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox