linux-stable/drivers/firmware/efi
Zhang Jianhua 278e483dc7 efi: Change down_interruptible() in virt_efi_reset_system() to down_trylock()
commit 38fa3206bf upstream.

While reboot the system by sysrq, the following bug will be occur.

BUG: sleeping function called from invalid context at kernel/locking/semaphore.c:90
in_atomic(): 0, irqs_disabled(): 128, non_block: 0, pid: 10052, name: rc.shutdown
CPU: 3 PID: 10052 Comm: rc.shutdown Tainted: G        W O      5.10.0 #1
Call trace:
 dump_backtrace+0x0/0x1c8
 show_stack+0x18/0x28
 dump_stack+0xd0/0x110
 ___might_sleep+0x14c/0x160
 __might_sleep+0x74/0x88
 down_interruptible+0x40/0x118
 virt_efi_reset_system+0x3c/0xd0
 efi_reboot+0xd4/0x11c
 machine_restart+0x60/0x9c
 emergency_restart+0x1c/0x2c
 sysrq_handle_reboot+0x1c/0x2c
 __handle_sysrq+0xd0/0x194
 write_sysrq_trigger+0xbc/0xe4
 proc_reg_write+0xd4/0xf0
 vfs_write+0xa8/0x148
 ksys_write+0x6c/0xd8
 __arm64_sys_write+0x18/0x28
 el0_svc_common.constprop.3+0xe4/0x16c
 do_el0_svc+0x1c/0x2c
 el0_svc+0x20/0x30
 el0_sync_handler+0x80/0x17c
 el0_sync+0x158/0x180

The reason for this problem is that irq has been disabled in
machine_restart() and then it calls down_interruptible() in
virt_efi_reset_system(), which would occur sleep in irq context,
it is dangerous! Commit 99409b935c9a("locking/semaphore: Add
might_sleep() to down_*() family") add might_sleep() in
down_interruptible(), so the bug info is here. down_trylock()
can solve this problem, cause there is no might_sleep.

--------

Cc: <stable@vger.kernel.org>
Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-20 11:40:14 +02:00
..
libstub efi/libstub/x86: Work around LLVM ELF quirk build regression 2020-06-22 09:30:52 +02:00
test efi/efi_test: Lock down /dev/efi_test and require CAP_SYS_ADMIN 2019-10-31 09:40:21 +01:00
apple-properties.c
arm-init.c
arm-runtime.c efi: Unify DMI setup code over the arm/arm64, ia64 and x86 architectures 2019-03-29 07:35:00 +01:00
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:40:14 +02:00
dev-path-parser.c bus_find_device: Unify the match callback with class_find_device 2019-06-24 05:22:31 +02:00
earlycon.c efi/earlycon: Fix write-combine mapping on x86 2020-01-23 08:22:38 +01:00
efi-bgrt.c efi/bgrt: Drop BGRT status field reserved bits check 2019-06-11 16:13:05 +02:00
efi-pstore.c
efi.c firmware/efi: Tell memblock about EFI iomem reservations 2021-07-28 13:31:00 +02:00
efibc.c efibc: Replace variable set function in notifier call 2019-06-22 10:24:57 +02:00
efivars.c efi/efivars: Add missing kobject_put() in sysfs entry creation error path 2020-06-17 16:40:26 +02:00
esrt.c efi/esrt: Fix reference count leak in esre_create_sysfs_entry. 2020-06-30 15:36:54 -04:00
fake_mem.c
Kconfig efi: EFI_EARLYCON should depend on EFI 2020-12-02 08:49:53 +01:00
Makefile efi: Export Runtime Configuration Interface table to sysfs 2019-08-08 11:10:25 +03:00
memattr.c efi: Allow EFI_MEMORY_XP and EFI_MEMORY_RO both to be cleared 2021-06-10 13:37:02 +02:00
memmap.c
rci2-table.c efi: Don't attempt to map RCI2 config table if it doesn't exist 2020-01-09 10:20:07 +01:00
reboot.c
runtime-map.c
runtime-wrappers.c efi: Change down_interruptible() in virt_efi_reset_system() to down_trylock() 2021-10-20 11:40:14 +02:00
tpm.c efi/tpm: Differentiate missing and invalid final event log table. 2021-07-28 13:30:56 +02:00
vars.c