Skip to content

Commit e019873

Browse files
nylon7gregkh
authored andcommitted
riscv: misaligned: fix sleeping function called during misaligned access handling
[ Upstream commit 61a74ad ] Use copy_from_user_nofault() and copy_to_user_nofault() instead of copy_from/to_user functions in the misaligned access trap handlers. The following bug report was found when executing misaligned memory accesses: BUG: sleeping function called from invalid context at ./include/linux/uaccess.h:162 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 115, name: two preempt_count: 0, expected: 0 CPU: 0 UID: 0 PID: 115 Comm: two Not tainted 6.14.0-rc5 #24 Hardware name: riscv-virtio,qemu (DT) Call Trace: [<ffffffff800160ea>] dump_backtrace+0x1c/0x24 [<ffffffff80002304>] show_stack+0x28/0x34 [<ffffffff80010fae>] dump_stack_lvl+0x4a/0x68 [<ffffffff80010fe0>] dump_stack+0x14/0x1c [<ffffffff8004e44e>] __might_resched+0xfa/0x104 [<ffffffff8004e496>] __might_sleep+0x3e/0x62 [<ffffffff801963c4>] __might_fault+0x1c/0x24 [<ffffffff80425352>] _copy_from_user+0x28/0xaa [<ffffffff8000296c>] handle_misaligned_store+0x204/0x254 [<ffffffff809eae82>] do_trap_store_misaligned+0x24/0xee [<ffffffff809f4f1a>] handle_exception+0x146/0x152 Fixes: b686ecd ("riscv: misaligned: Restrict user access to kernel memory") Fixes: 4413815 ("riscv: misaligned: remove CONFIG_RISCV_M_MODE specific code") Signed-off-by: Zong Li <[email protected]> Signed-off-by: Nylon Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d5d9fd1 commit e019873

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/kernel/traps_misaligned.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ int handle_misaligned_load(struct pt_regs *regs)
429429

430430
val.data_u64 = 0;
431431
if (user_mode(regs)) {
432-
if (copy_from_user(&val, (u8 __user *)addr, len))
432+
if (copy_from_user_nofault(&val, (u8 __user *)addr, len))
433433
return -1;
434434
} else {
435435
memcpy(&val, (u8 *)addr, len);
@@ -530,7 +530,7 @@ int handle_misaligned_store(struct pt_regs *regs)
530530
return -EOPNOTSUPP;
531531

532532
if (user_mode(regs)) {
533-
if (copy_to_user((u8 __user *)addr, &val, len))
533+
if (copy_to_user_nofault((u8 __user *)addr, &val, len))
534534
return -1;
535535
} else {
536536
memcpy((u8 *)addr, &val, len);

0 commit comments

Comments
 (0)