Ubuntu-focal-kernel/kernel
Sergey Senozhatsky 95edc24649 printk: queue wake_up_klogd irq_work only if per-CPU areas are ready
BugLink: https://bugs.launchpad.net/bugs/1876765

commit ab6f762f0f upstream.

printk_deferred(), similarly to printk_safe/printk_nmi, does not
immediately attempt to print a new message on the consoles, avoiding
calls into non-reentrant kernel paths, e.g. scheduler or timekeeping,
which potentially can deadlock the system.

Those printk() flavors, instead, rely on per-CPU flush irq_work to print
messages from safer contexts.  For same reasons (recursive scheduler or
timekeeping calls) printk() uses per-CPU irq_work in order to wake up
user space syslog/kmsg readers.

However, only printk_safe/printk_nmi do make sure that per-CPU areas
have been initialised and that it's safe to modify per-CPU irq_work.
This means that, for instance, should printk_deferred() be invoked "too
early", that is before per-CPU areas are initialised, printk_deferred()
will perform illegal per-CPU access.

Lech Perczak [0] reports that after commit 1b710b1b10 ("char/random:
silence a lockdep splat with printk()") user-space syslog/kmsg readers
are not able to read new kernel messages.

The reason is printk_deferred() being called too early (as was pointed
out by Petr and John).

Fix printk_deferred() and do not queue per-CPU irq_work before per-CPU
areas are initialized.

Link: https://lore.kernel.org/lkml/aa0732c6-5c4e-8a8b-a1c1-75ebe3dca05b@camlintechnologies.com/
Reported-by: Lech Perczak <l.perczak@camlintechnologies.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Jann Horn <jannh@google.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2020-05-25 10:42:00 +02:00
..
bpf bpf: fix buggy r0 retval refinement for tracing helpers 2020-05-25 10:41:30 +02:00
cgroup cgroup1: don't call release_agent when it is "" 2020-04-03 15:17:23 +02:00
configs
debug
dma dma-direct: fix data truncation in dma_direct_get_required_mask() 2020-05-25 10:41:36 +02:00
events perf/core: Disable page faults when getting phys address 2020-05-25 10:41:38 +02:00
gcov kernel/gcov/fs.c: gcov_seq_next() should increase position index 2020-05-25 10:41:36 +02:00
irq genirq/debugfs: Add missing sanity checks to interrupt injection 2020-05-05 12:32:22 +02:00
livepatch
locking locktorture: Print ratio of acquisitions, not failures 2020-05-25 10:41:28 +02:00
power
printk printk: queue wake_up_klogd irq_work only if per-CPU areas are ready 2020-05-25 10:42:00 +02:00
rcu rcu: Allow only one expedited GP to run concurrently with wakeups 2020-03-06 14:05:59 +01:00
sched sched/core: Remove duplicate assignment in sched_tick_remote() 2020-05-05 12:32:22 +02:00
time time/sched_clock: Expire timer in hardirq context 2020-05-05 12:32:22 +02:00
trace tracing: Fix the race between registering 'snapshot' event trigger and triggering 'snapshot' operation 2020-05-05 12:32:22 +02:00
.gitignore
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
Makefile
acct.c
async.c
audit.c audit: check the length of userspace generated audit records 2020-05-25 10:41:52 +02:00
audit.h
audit_fsnotify.c
audit_tree.c
audit_watch.c
auditfilter.c audit: fix error handling in audit_data_to_entry() 2020-03-06 12:38:20 +01:00
auditsc.c
backtracetest.c
bounds.c
capability.c
compat.c
configs.c
context_tracking.c
cpu.c cpu/hotplug: Ignore pm_wakeup_pending() for disable_nonboot_cpus() 2020-05-05 12:32:22 +02:00
cpu_pm.c
crash_core.c
crash_dump.c
cred.c
delayacct.c
dma.c
elfcore.c
exec_domain.c
exit.c
extable.c
fail_function.c
fork.c mm: fork: fix kernel_stack memcg stats for various stack implementations 2020-04-03 15:17:23 +02:00
freezer.c
futex.c futex: Unbreak futex hashing 2020-04-03 15:17:23 +02:00
gen_kheaders.sh
groups.c
hung_task.c
iomem.c
irq_work.c
jump_label.c
kallsyms.c
kcmp.c
kcov.c
kexec.c
kexec_core.c
kexec_elf.c
kexec_file.c
kexec_internal.h
kheaders.c
kmod.c kmod: make request_module() return an error when autoloading is disabled 2020-05-05 12:32:22 +02:00
kprobes.c kprobes: Fix optimize_kprobe()/unoptimize_kprobe() cancellation logic 2020-03-12 18:01:58 +01:00
ksysfs.c
kthread.c
latencytop.c
module-internal.h
module.c module: avoid setting info->name early in case we can fall back to info->mod->name 2020-02-24 16:20:02 +01:00
module_signature.c
module_signing.c
notifier.c x86/mm: split vmalloc_sync_all() 2020-04-03 15:17:23 +02:00
nsproxy.c
padata.c padata: always acquire cpu_hotplug_lock before pinst->lock 2020-05-05 12:32:22 +02:00
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 compat_ioctl for notify 2020-05-05 12:32:22 +02:00
signal.c signal: Avoid corrupting si_pid and si_uid in do_notify_parent 2020-05-25 10:41:52 +02:00
smp.c
smpboot.c
smpboot.h
softirq.c
stackleak.c
stacktrace.c
stop_machine.c
sys.c
sys_ni.c
sysctl.c
sysctl_binary.c
task_work.c
taskstats.c
test_kprobes.c
torture.c
tracepoint.c
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/softlockup: Enforce that timestamp is valid on boot 2020-02-24 16:20:00 +01:00
watchdog_hld.c
workqueue.c workqueue: don't use wq_select_unbound_cpu() for bound works 2020-03-18 11:39:15 +01:00
workqueue_internal.h