linux-stable/kernel
Waiman Long 357f3f0e52 sched, cpuset: Fix dl_cpu_busy() panic due to empty cs->cpus_allowed
[ Upstream commit b6e8d40d43 ]

With cgroup v2, the cpuset's cpus_allowed mask can be empty indicating
that the cpuset will just use the effective CPUs of its parent. So
cpuset_can_attach() can call task_can_attach() with an empty mask.
This can lead to cpumask_any_and() returns nr_cpu_ids causing the call
to dl_bw_of() to crash due to percpu value access of an out of bound
CPU value. For example:

	[80468.182258] BUG: unable to handle page fault for address: ffffffff8b6648b0
	  :
	[80468.191019] RIP: 0010:dl_cpu_busy+0x30/0x2b0
	  :
	[80468.207946] Call Trace:
	[80468.208947]  cpuset_can_attach+0xa0/0x140
	[80468.209953]  cgroup_migrate_execute+0x8c/0x490
	[80468.210931]  cgroup_update_dfl_csses+0x254/0x270
	[80468.211898]  cgroup_subtree_control_write+0x322/0x400
	[80468.212854]  kernfs_fop_write_iter+0x11c/0x1b0
	[80468.213777]  new_sync_write+0x11f/0x1b0
	[80468.214689]  vfs_write+0x1eb/0x280
	[80468.215592]  ksys_write+0x5f/0xe0
	[80468.216463]  do_syscall_64+0x5c/0x80
	[80468.224287]  entry_SYSCALL_64_after_hwframe+0x44/0xae

Fix that by using effective_cpus instead. For cgroup v1, effective_cpus
is the same as cpus_allowed. For v2, effective_cpus is the real cpumask
to be used by tasks within the cpuset anyway.

Also update task_can_attach()'s 2nd argument name to cs_effective_cpus to
reflect the change. In addition, a check is added to task_can_attach()
to guard against the possibility that cpumask_any_and() may return a
value >= nr_cpu_ids.

Fixes: 7f51412a41 ("sched/deadline: Fix bandwidth check/update when migrating tasks between exclusive cpusets")
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Juri Lelli <juri.lelli@redhat.com>
Link: https://lore.kernel.org/r/20220803015451.2219567-1-longman@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 14:42:15 +02:00
..
bpf bpf: fix potential 32-bit overflow when accessing ARRAY map element 2022-08-17 14:41:08 +02:00
cgroup sched, cpuset: Fix dl_cpu_busy() panic due to empty cs->cpus_allowed 2022-08-17 14:42:15 +02:00
configs Char/Misc and other driver updates for 5.18-rc1 2022-03-28 12:27:35 -07:00
debug lockdown: also lock down previous kgdb use 2022-05-30 09:24:03 +02:00
dma swiotlb: fail map correctly with failed io_tlb_default_mem 2022-08-17 14:42:05 +02:00
entry entry/kvm: Exit to user mode when TIF_NOTIFY_SIGNAL is set 2022-08-11 13:20:41 +02:00
events perf/core: Fix data race between perf_event_set_output() and perf_mmap_close() 2022-07-29 17:27:59 +02:00
futex mm/truncate: Inline invalidate_complete_page() into its one caller 2022-03-21 12:59:01 -04:00
gcov gcov: Remove compiler version check 2021-12-02 17:25:21 +09:00
irq irqdomain: Report irq number for NOMAP domains 2022-08-17 14:40:41 +02:00
kcsan KCSAN updates for v5.17 2022-01-11 09:51:26 -08:00
livepatch ptrace: Cleanups for v5.18 2022-03-28 17:29:53 -07:00
locking locking/lockdep: Fix lockdep_init_map_*() confusion 2022-08-17 14:40:30 +02:00
power PM: hibernate: defer device probing when resuming from hibernation 2022-08-17 14:40:26 +02:00
printk printk: wake waiters for safe and NMI contexts 2022-06-09 10:30:01 +02:00
rcu rcutorture: Fix ksoftirqd boosting timing and iteration 2022-08-17 14:40:52 +02:00
sched sched, cpuset: Fix dl_cpu_busy() panic due to empty cs->cpus_allowed 2022-08-17 14:42:15 +02:00
time wireguard: ratelimiter: use hrtimer in selftest 2022-08-17 14:41:16 +02:00
trace blktrace: Trace remapped requests correctly 2022-08-17 14:40:39 +02:00
.gitignore
acct.c kernel: remove spurious blkdev.h includes 2021-10-18 06:17:01 -06:00
async.c Revert "module, async: async_synchronize_full() on module init iff async is used" 2022-02-03 11:20:34 -08:00
audit.c audit: improve audit queue handling when "audit=1" on cmdline 2022-01-25 13:22:51 -05:00
audit.h audit: log AUDIT_TIME_* records only from rules 2022-02-22 13:51:40 -05:00
audit_fsnotify.c fsnotify: clarify contract for create event hooks 2021-10-27 12:32:34 +02:00
audit_tree.c audit: use struct_size() helper in kmalloc() 2021-12-14 17:39:42 -05:00
audit_watch.c \n 2021-11-06 16:43:20 -07:00
auditfilter.c audit/stable-5.17 PR 20220110 2022-01-11 13:08:21 -08:00
auditsc.c audit: free module name 2022-06-22 14:28:09 +02:00
backtracetest.c
bounds.c
capability.c xfs: don't generate selinux audit messages for capability testing 2022-03-09 10:32:06 -08:00
cfi.c cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle 2022-06-22 14:28:10 +02:00
compat.c
configs.c
context_tracking.c
cpu.c cpu/hotplug: Remove the 'cpu' member of cpuhp_cpu_state 2022-04-13 21:25:40 +02:00
cpu_pm.c
crash_core.c kernel/crash_core: suppress unknown crashkernel parameter warning 2021-12-25 12:20:55 -08:00
crash_dump.c
cred.c x86: Mark __invalid_creds() __noreturn 2022-03-15 10:32:44 +01:00
delayacct.c delayacct: track delays from memory compact 2022-01-20 08:52:55 +02:00
dma.c
exec_domain.c
exit.c fix race between exit_itimers() and /proc/pid/timers 2022-07-22 10:21:18 +02:00
extable.c lkdtm: Really write into kernel text in WRITE_KERN 2022-02-16 23:25:12 +11:00
fail_function.c
fork.c kthread: Don't allocate kthread_struct for init and umh 2022-06-09 10:29:30 +02:00
freezer.c
gen_kheaders.sh
groups.c
hung_task.c hung_task: move hung_task sysctl interface to hung_task.c 2022-01-22 08:33:34 +02:00
iomem.c
irq_work.c irq_work: use kasan_record_aux_stack_noalloc() record callstack 2022-04-15 14:49:55 -07:00
jump_label.c
kallsyms.c kallsyms: Skip the name search for empty string 2022-03-17 20:17:18 -07:00
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt Revert "signal, x86: Delay calling signals in atomic on RT enabled kernels" 2022-03-31 10:36:55 +02:00
kcov.c kcov: don't generate a warning on vm_insert_page()'s failure 2022-04-21 20:01:10 -07:00
kexec.c
kexec_core.c exit: Move oops specific logic from do_exit into make_task_dead 2021-12-13 12:04:45 -06:00
kexec_elf.c
kexec_file.c ima: force signature verification when CONFIG_KEXEC_SIG is configured 2022-07-22 10:21:40 +02:00
kexec_internal.h
kheaders.c
kmod.c
kprobes.c kprobes: Forbid probing on trampoline and BPF code areas 2022-08-17 14:42:14 +02:00
ksysfs.c kernel/ksysfs.c: use helper macro __ATTR_RW 2022-03-23 19:00:33 -07:00
kthread.c asm-generic updates for 5.18 2022-03-23 18:03:08 -07:00
latencytop.c
Makefile static_call: Don't make __static_call_return0 static 2022-04-05 09:59:38 +02:00
module-internal.h module: add in-kernel support for decompressing 2022-01-11 18:45:02 -08:00
module.c module: fix [e_shstrndx].sh_size=0 OOB access 2022-06-09 10:30:30 +02:00
module_decompress.c module: fix building with sysfs disabled 2022-02-16 12:51:32 -08:00
module_signature.c
module_signing.c
notifier.c notifier: Return an error when a callback has already been registered 2021-12-29 10:37:33 +01:00
nsproxy.c
padata.c padata: replace cpumask_weight with cpumask_empty in padata.c 2022-01-31 11:21:46 +11:00
panic.c panic: move panic_print before kmsg dumpers 2022-03-23 19:00:35 -07:00
params.c kobject: remove kset from struct kset_uevent_ops callbacks 2021-12-28 11:26:18 +01:00
pid.c pid: add pidfd_get_task() helper 2021-10-14 13:29:18 +02:00
pid_namespace.c
profile.c profiling: fix shift too large makes kernel panic 2022-08-17 14:42:00 +02:00
ptrace.c ptrace: Reimplement PTRACE_KILL by always sending SIGKILL 2022-06-09 10:29:30 +02:00
range.c
reboot.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2021-11-12 11:53:16 -08:00
regset.c
relay.c
resource.c kernel/resource: fix kfree() of bootmem memory again 2022-03-23 19:00:35 -07:00
resource_kunit.c
rseq.c rseq: Remove broken uapi field layout on 32-bit little endian 2022-02-02 13:11:34 +01:00
scftorture.c scftorture: Fix distribution of short handler delays 2022-06-09 10:29:58 +02:00
scs.c kasan, vmalloc: only tag normal vmalloc allocations 2022-03-24 19:06:48 -07:00
seccomp.c ptrace: Cleanups for v5.18 2022-03-28 17:29:53 -07:00
signal.c signal handling: don't use BUG_ON() for debugging 2022-07-22 10:21:56 +02:00
smp.c smp: Fix offline cpu check in flush_smp_call_function_queue() 2022-04-13 18:44:35 +02:00
smpboot.c
smpboot.h
softirq.c genirq, softirq: Use in_hardirq() instead of in_irq() 2022-02-02 21:34:19 +01:00
stackleak.c gcc-plugins/stackleak: Use noinstr in favor of notrace 2022-02-03 17:02:21 -08:00
stacktrace.c uaccess: remove CONFIG_SET_FS 2022-02-25 09:36:06 +01:00
static_call.c static_call: Don't make __static_call_return0 static 2022-04-05 09:59:38 +02:00
static_call_inline.c static_call: Don't make __static_call_return0 static 2022-04-05 09:59:38 +02:00
stop_machine.c
sys.c prlimit: do not grab the tasklist_lock 2022-03-08 14:33:36 -06:00
sys_ni.c mm/mempolicy: wire up syscall set_mempolicy_home_node 2022-01-15 16:30:30 +02:00
sysctl-test.c
sysctl.c mm: sysctl: fix missing numa_stat when !CONFIG_HUGETLB_PAGE 2022-07-22 10:21:44 +02:00
task_work.c resume_user_mode: Move to resume_user_mode.h 2022-03-10 16:51:50 -06:00
taskstats.c taskstats: remove unneeded dead assignment 2022-03-23 19:00:35 -07:00
torture.c torture: Wake up kthreads after storing task_struct pointer 2022-02-01 17:24:39 -08:00
tracepoint.c
tsacct.c taskstats: Cleanup the use of task->exit_code 2022-01-08 12:43:57 -06:00
ucount.c ucounts: Handle wrapping in is_ucounts_overlimit 2022-02-17 09:11:57 -06:00
uid16.c
uid16.h
umh.c kthread: Don't allocate kthread_struct for init and umh 2022-06-09 10:29:30 +02:00
up.c
user-return-notifier.c
user.c
user_namespace.c ucounts: Fix systemd LimitNPROC with private users regression 2022-02-25 10:40:14 -06:00
usermode_driver.c
utsname.c
utsname_sysctl.c
watch_queue.c watch_queue: Fix missing locking in add_watch_to_object() 2022-08-03 12:05:19 +02:00
watchdog.c sched/isolation: Use single feature type while referring to housekeeping cpumask 2022-02-16 15:57:55 +01:00
watchdog_hld.c
workqueue.c Merge branch 'for-5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq 2022-03-23 12:40:51 -07:00
workqueue_internal.h