* [PATCH] riscv: misaligned: Restrict user access to kernel memory
@ 2024-08-15 0:57 Samuel Holland
2024-08-15 9:29 ` Alexandre Ghiti
2024-09-03 14:30 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Samuel Holland @ 2024-08-15 0:57 UTC (permalink / raw)
To: Palmer Dabbelt
Cc: Samuel Holland, stable, Albert Ou, Ben Dooks,
Björn Töpel, Charlie Jenkins, Clément Léger,
Conor Dooley, Evan Green, Paul Walmsley, linux-kernel,
linux-riscv
raw_copy_{to,from}_user() do not call access_ok(), so this code allowed
userspace to access any virtual memory address.
Cc: stable@vger.kernel.org
Fixes: 7c83232161f6 ("riscv: add support for misaligned trap handling in S-mode")
Fixes: 441381506ba7 ("riscv: misaligned: remove CONFIG_RISCV_M_MODE specific code")
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
---
arch/riscv/kernel/traps_misaligned.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
index b62d5a2f4541..1a76f99ff185 100644
--- a/arch/riscv/kernel/traps_misaligned.c
+++ b/arch/riscv/kernel/traps_misaligned.c
@@ -417,7 +417,7 @@ int handle_misaligned_load(struct pt_regs *regs)
val.data_u64 = 0;
if (user_mode(regs)) {
- if (raw_copy_from_user(&val, (u8 __user *)addr, len))
+ if (copy_from_user(&val, (u8 __user *)addr, len))
return -1;
} else {
memcpy(&val, (u8 *)addr, len);
@@ -515,7 +515,7 @@ int handle_misaligned_store(struct pt_regs *regs)
return -EOPNOTSUPP;
if (user_mode(regs)) {
- if (raw_copy_to_user((u8 __user *)addr, &val, len))
+ if (copy_to_user((u8 __user *)addr, &val, len))
return -1;
} else {
memcpy((u8 *)addr, &val, len);
--
2.45.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] riscv: misaligned: Restrict user access to kernel memory
2024-08-15 0:57 [PATCH] riscv: misaligned: Restrict user access to kernel memory Samuel Holland
@ 2024-08-15 9:29 ` Alexandre Ghiti
2024-09-03 14:30 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Ghiti @ 2024-08-15 9:29 UTC (permalink / raw)
To: Samuel Holland, Palmer Dabbelt
Cc: stable, Albert Ou, Ben Dooks, Björn Töpel,
Charlie Jenkins, Clément Léger, Conor Dooley,
Evan Green, Paul Walmsley, linux-kernel, linux-riscv
Hi Samuel,
On 15/08/2024 02:57, Samuel Holland wrote:
> raw_copy_{to,from}_user() do not call access_ok(), so this code allowed
> userspace to access any virtual memory address.
>
> Cc: stable@vger.kernel.org
> Fixes: 7c83232161f6 ("riscv: add support for misaligned trap handling in S-mode")
> Fixes: 441381506ba7 ("riscv: misaligned: remove CONFIG_RISCV_M_MODE specific code")
> Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
> ---
>
> arch/riscv/kernel/traps_misaligned.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
> index b62d5a2f4541..1a76f99ff185 100644
> --- a/arch/riscv/kernel/traps_misaligned.c
> +++ b/arch/riscv/kernel/traps_misaligned.c
> @@ -417,7 +417,7 @@ int handle_misaligned_load(struct pt_regs *regs)
>
> val.data_u64 = 0;
> if (user_mode(regs)) {
> - if (raw_copy_from_user(&val, (u8 __user *)addr, len))
> + if (copy_from_user(&val, (u8 __user *)addr, len))
> return -1;
> } else {
> memcpy(&val, (u8 *)addr, len);
> @@ -515,7 +515,7 @@ int handle_misaligned_store(struct pt_regs *regs)
> return -EOPNOTSUPP;
>
> if (user_mode(regs)) {
> - if (raw_copy_to_user((u8 __user *)addr, &val, len))
> + if (copy_to_user((u8 __user *)addr, &val, len))
> return -1;
> } else {
> memcpy((u8 *)addr, &val, len);
We could even do the access_ok() *before* even calling
handle_misaligned_load() in do_trap_load_misaligned() to back off
earlier. But unless you think it is important, I'm fine with this patch,
it's on my list for -fixes!
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Thanks,
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] riscv: misaligned: Restrict user access to kernel memory
2024-08-15 0:57 [PATCH] riscv: misaligned: Restrict user access to kernel memory Samuel Holland
2024-08-15 9:29 ` Alexandre Ghiti
@ 2024-09-03 14:30 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-09-03 14:30 UTC (permalink / raw)
To: Samuel Holland
Cc: linux-riscv, palmer, stable, aou, ben.dooks, bjorn, charlie,
cleger, conor.dooley, evan, paul.walmsley, linux-kernel
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Wed, 14 Aug 2024 17:57:03 -0700 you wrote:
> raw_copy_{to,from}_user() do not call access_ok(), so this code allowed
> userspace to access any virtual memory address.
>
> Cc: stable@vger.kernel.org
> Fixes: 7c83232161f6 ("riscv: add support for misaligned trap handling in S-mode")
> Fixes: 441381506ba7 ("riscv: misaligned: remove CONFIG_RISCV_M_MODE specific code")
> Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
>
> [...]
Here is the summary with links:
- riscv: misaligned: Restrict user access to kernel memory
https://git.kernel.org/riscv/c/b686ecdeacf6
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-03 14:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15 0:57 [PATCH] riscv: misaligned: Restrict user access to kernel memory Samuel Holland
2024-08-15 9:29 ` Alexandre Ghiti
2024-09-03 14:30 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox