linux/drivers/firmware/efi
Jann Horn 86a926c3f0 pstore: Don't use semaphores in always-atomic-context code
commit 8126b1c731 upstream.

pstore_dump() is *always* invoked in atomic context (nowadays in an RCU
read-side critical section, before that under a spinlock).
It doesn't make sense to try to use semaphores here.

This is mostly a revert of commit ea84b580b9 ("pstore: Convert buf_lock
to semaphore"), except that two parts aren't restored back exactly as they
were:

 - keep the lock initialization in pstore_register
 - in efi_pstore_write(), always set the "block" flag to false
 - omit "is_locked", that was unnecessary since
   commit 959217c84c ("pstore: Actually give up during locking failure")
 - fix the bailout message

The actual problem that the buggy commit was trying to address may have
been that the use of preemptible() in efi_pstore_write() was wrong - it
only looks at preempt_count() and the state of IRQs, but __rcu_read_lock()
doesn't touch either of those under CONFIG_PREEMPT_RCU.
(Sidenote: CONFIG_PREEMPT_RCU means that the scheduler can preempt tasks in
RCU read-side critical sections, but you're not allowed to actively
block/reschedule.)

Lockdep probably never caught the problem because it's very rare that you
actually hit the contended case, so lockdep always just sees the
down_trylock(), not the down_interruptible(), and so it can't tell that
there's a problem.

Fixes: ea84b580b9 ("pstore: Convert buf_lock to semaphore")
Cc: stable@vger.kernel.org
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220314185953.2068993-1-jannh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-08 14:39:56 +02:00
..
libstub riscv/efi_stub: Fix get_boot_hartid_from_fdt() return value 2022-03-08 19:09:31 +01:00
test
apple-properties.c efi: fix return value of __setup handlers 2022-03-23 09:13:27 +01:00
arm-runtime.c
capsule-loader.c
capsule.c
cper-arm.c
cper-x86.c
cper.c efi/cper: use stack buffer for error record decoding 2021-10-20 11:45:00 +02:00
dev-path-parser.c
earlycon.c
efi-bgrt.c
efi-init.c
efi-pstore.c pstore: Don't use semaphores in always-atomic-context code 2022-04-08 14:39:56 +02:00
efi.c efi: fix return value of __setup handlers 2022-03-23 09:13:27 +01:00
efibc.c
efivars.c
embedded-firmware.c
esrt.c
fake_mem.c
fake_mem.h
fdtparams.c efi/fdt: fix panic when no valid fdt found 2021-06-10 13:39:13 +02:00
Kconfig
Makefile
memattr.c efi: Allow EFI_MEMORY_XP and EFI_MEMORY_RO both to be cleared 2021-06-10 13:39:14 +02:00
memmap.c
mokvar-table.c efi/mokvar: Reserve the table only if it is in boot services data 2021-08-08 09:05:23 +02:00
rci2-table.c
reboot.c
riscv-runtime.c
runtime-map.c
runtime-wrappers.c efi: Change down_interruptible() in virt_efi_reset_system() to down_trylock() 2021-10-20 11:45:00 +02:00
tpm.c efi/tpm: Differentiate missing and invalid final event log table. 2021-07-28 14:35:38 +02:00
vars.c efivars: Respect "block" flag in efivar_entry_set_safe() 2022-03-08 19:09:35 +01:00
x86_fake_mem.c