linux-uconsole/arch
haibinzhang (张海斌) 41cbbe08f9 FROMGIT: arm64: fix oops in concurrently setting insn_emulation sysctls
emulation_proc_handler() changes table->data for proc_dointvec_minmax
and can generate the following Oops if called concurrently with itself:

 | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010
 | Internal error: Oops: 96000006 [#1] SMP
 | Call trace:
 | update_insn_emulation_mode+0xc0/0x148
 | emulation_proc_handler+0x64/0xb8
 | proc_sys_call_handler+0x9c/0xf8
 | proc_sys_write+0x18/0x20
 | __vfs_write+0x20/0x48
 | vfs_write+0xe4/0x1d0
 | ksys_write+0x70/0xf8
 | __arm64_sys_write+0x20/0x28
 | el0_svc_common.constprop.0+0x7c/0x1c0
 | el0_svc_handler+0x2c/0xa0
 | el0_svc+0x8/0x200

To fix this issue, keep the table->data as &insn->current_mode and
use container_of() to retrieve the insn pointer. Another mutex is
used to protect against the current_mode update but not for retrieving
insn_emulation as table->data is no longer changing.

Bug: 237540956
Co-developed-by: hewenliang <hewenliang4@huawei.com>
Signed-off-by: hewenliang <hewenliang4@huawei.com>
Signed-off-by: Haibin Zhang <haibinzhang@tencent.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20220128090324.2727688-1-hewenliang4@huawei.com
Link: https://lore.kernel.org/r/9A004C03-250B-46C5-BF39-782D7551B00E@tencent.com
Signed-off-by: Will Deacon <will@kernel.org>
[Lee: Added Fixes: tag]
(cherry picked from commit af483947d4
git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core)
Fixes: 587064b610 ("arm64: Add framework for legacy instruction emulation")
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: If9b96bb79c79903f9d8292e719b06fdef57ef1c5
2022-07-22 13:19:11 +00:00
..
alpha Merge tag 'android12-5.10.81_r00' into android12-5.10 2022-01-21 09:35:04 +01:00
arc uaccess: fix type mismatch warnings from access_ok() 2022-04-08 14:40:35 +02:00
arm This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
arm64 FROMGIT: arm64: fix oops in concurrently setting insn_emulation sysctls 2022-07-22 13:19:11 +00:00
c6x
csky This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
h8300
hexagon hexagon: clean up timer-regs.h 2021-11-26 10:39:19 +01:00
ia64 This is the 5.10.104 stable release 2022-03-12 13:57:09 +01:00
m68k This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
microblaze This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
mips This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
nds32 nds32: fix access_ok() checks in get/put_user 2022-03-28 09:57:10 +02:00
nios2 uaccess: fix type mismatch warnings from access_ok() 2022-04-08 14:40:35 +02:00
openrisc openrisc: Add clone3 ABI wrapper 2022-01-27 10:54:06 +01:00
parisc This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
powerpc This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
riscv This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
s390 This is the 5.10.104 stable release 2022-03-12 13:57:09 +01:00
sh Merge tag 'android12-5.10.81_r00' into android12-5.10 2022-01-21 09:35:04 +01:00
sparc This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
um This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
x86 Merge tag 'android12-5.10.110_r01' into android12-5.10 2022-05-27 09:24:14 -07:00
xtensa This is the 5.10.110 stable release 2022-04-18 17:41:18 +02:00
.gitignore
Kconfig This is the 5.10.80 stable release 2021-11-19 11:50:41 +01:00