linux/kernel
Waiman Long 279749d0d4 sched/debug: Fix cgroup_path[] serialization
[ Upstream commit ad789f84c9a145f8a18744c0387cec22ec51651e ]

The handling of sysrq key can be activated by echoing the key to
/proc/sysrq-trigger or via the magic key sequence typed into a terminal
that is connected to the system in some way (serial, USB or other mean).
In the former case, the handling is done in a user context. In the
latter case, it is likely to be in an interrupt context.

Currently in print_cpu() of kernel/sched/debug.c, sched_debug_lock is
taken with interrupt disabled for the whole duration of the calls to
print_*_stats() and print_rq() which could last for the quite some time
if the information dump happens on the serial console.

If the system has many cpus and the sched_debug_lock is somehow busy
(e.g. parallel sysrq-t), the system may hit a hard lockup panic
depending on the actually serial console implementation of the
system.

The purpose of sched_debug_lock is to serialize the use of the global
cgroup_path[] buffer in print_cpu(). The rests of the printk calls don't
need serialization from sched_debug_lock.

Calling printk() with interrupt disabled can still be problematic if
multiple instances are running. Allocating a stack buffer of PATH_MAX
bytes is not feasible because of the limited size of the kernel stack.

The solution implemented in this patch is to allow only one caller at a
time to use the full size group_path[], while other simultaneous callers
will have to use shorter stack buffers with the possibility of path
name truncation. A "..." suffix will be printed if truncation may have
happened.  The cgroup path name is provided for informational purpose
only, so occasional path name truncation should not be a big problem.

Fixes: efe25c2c7b ("sched: Reinstate group names in /proc/sched_debug")
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210415195426.6677-1-longman@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-05-14 09:44:26 +02:00
..
bpf bpf: Fix leakage of uninitialized bpf stack under speculation 2021-05-07 10:51:37 +02:00
cgroup cgroup: fix psi monitor for root cgroup 2021-02-17 10:35:14 +01:00
configs
debug kdb: Make memory allocations more robust 2021-03-04 10:26:10 +01:00
dma
events perf/core: Fix unconditional security_locked_down() call 2021-05-07 10:51:38 +02:00
gcov gcov: re-fix clang-11+ support 2021-04-14 08:24:10 +02:00
irq genirq/matrix: Prevent allocation counter corruption 2021-05-11 14:04:05 +02:00
livepatch
locking locking/qrwlock: Fix ordering in queued_write_lock_slowpath() 2021-04-28 13:19:14 +02:00
power PM: EM: postpone creating the debugfs dir till fs_initcall 2021-03-30 14:35:28 +02:00
printk printk: fix deadlock when kernel panic 2021-03-04 10:26:50 +01:00
rcu rcu/nocb: Perform deferred wake up before last idle's need_resched() check 2021-03-04 10:26:47 +01:00
sched sched/debug: Fix cgroup_path[] serialization 2021-05-14 09:44:26 +02:00
time posix-timers: Preserve return value in clock_adjtime32() 2021-05-11 14:04:04 +02:00
trace tracing: Restructure trace_clock_global() to never block 2021-05-11 14:04:18 +02:00
.gitignore kbuild: update config_data.gz only when the content of .config is changed 2021-05-11 14:04:16 +02:00
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
Makefile kbuild: update config_data.gz only when the content of .config is changed 2021-05-11 14:04:16 +02:00
acct.c
async.c
audit.c
audit.h
audit_fsnotify.c
audit_tree.c
audit_watch.c
auditfilter.c
auditsc.c
backtracetest.c
bounds.c
capability.c
compat.c
configs.c
context_tracking.c
cpu.c
cpu_pm.c
crash_core.c
crash_dump.c
cred.c
delayacct.c
dma.c
exec_domain.c
exit.c
extable.c
fail_function.c
fork.c exec: Transform exec_update_mutex into a rw_semaphore 2021-01-09 13:44:55 +01:00
freezer.c
futex.c Revert 337f13046f ("futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op") 2021-05-11 14:04:16 +02:00
gen_kheaders.sh
groups.c
hung_task.c
iomem.c
irq_work.c
jump_label.c
kallsyms.c
kcmp.c exec: Transform exec_update_mutex into a rw_semaphore 2021-01-09 13:44:55 +01:00
kcov.c
kexec.c
kexec_core.c kernel: kexec: remove the lock operation of system_transition_mutex 2021-02-03 23:25:56 +01:00
kexec_elf.c
kexec_file.c ima: Free IMA measurement buffer after kexec syscall 2021-03-04 10:26:25 +01:00
kexec_internal.h
kheaders.c
kmod.c
kprobes.c tracing/kprobe: Fix to support kretprobe events on unloaded modules 2021-02-13 13:52:54 +01:00
ksysfs.c
kthread.c kthread: Extract KTHREAD_IS_PER_CPU 2021-02-07 15:35:49 +01:00
latencytop.c
module-internal.h
module.c modules: inherit TAINT_PROPRIETARY_MODULE 2021-05-11 14:04:04 +02:00
module_signature.c module: harden ELF info handling 2021-04-07 14:47:38 +02:00
module_signing.c module: harden ELF info handling 2021-04-07 14:47:38 +02:00
notifier.c
nsproxy.c
padata.c
panic.c
params.c
pid.c
pid_namespace.c
profile.c
ptrace.c
range.c
reboot.c
relay.c
resource.c
rseq.c
seccomp.c seccomp: Add missing return in non-void function 2021-03-04 10:26:45 +01:00
signal.c
smp.c
smpboot.c kthread: Extract KTHREAD_IS_PER_CPU 2021-02-07 15:35:49 +01:00
smpboot.h
softirq.c
stackleak.c
stacktrace.c
stop_machine.c
sys.c
sys_ni.c
sysctl-test.c
sysctl.c sysctl.c: fix underflow value setting risk in vm_table 2021-03-17 17:03:45 +01:00
sysctl_binary.c
task_work.c
taskstats.c
test_kprobes.c
torture.c
tracepoint.c tracepoint: Do not fail unregistering a probe due to memory failure 2021-03-04 10:26:32 +01:00
tsacct.c
ucount.c
uid16.c
uid16.h
umh.c
up.c
user-return-notifier.c
user.c
user_namespace.c
utsname.c
utsname_sysctl.c
watchdog.c
watchdog_hld.c
workqueue.c workqueue: Move the position of debug_work_activate() in __queue_work() 2021-04-14 08:24:17 +02:00
workqueue_internal.h