Let illegal access to user-space memory die
v2 cover Let illegal access to user-space memory die
Accesses to user-space memory without calling uaccess routine leads to hanging in page fault handler. Like arm64, we let it die earlier in page fault handler.
Changes in v2:
-Add a die_kernel_fault() helper
-Split one long line code into two
Eric Lin (2):
riscv/mm: Introduce a die_kernel_fault() helper function riscv/mm: Prevent kernel module to access user memory without uaccess
routines
arch/riscv/mm/fault.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Signature · 1 line
2.17.0
PATCH v2 1/2 riscv/mm: Introduce a die_kernel_fault() helper function
Like arm64, this patch adds a die_kernel_fault() helper to ensure the same semantics for the different kernel faults.
--- arch/riscv/mm/fault.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/riscv/mm/fault.c +13 -0
@@ -19,6 +19,19 @@#include "../kernel/head.h" +static void die_kernel_fault (const char *msg,unsigned long addr, +struct pt_regs *regs) +{ +bust_spinlocks (1 ); + +pr_alert ("Unable to handle kernel %s at virtual address " REG_FMT "\n" , msg, + addr); + +bust_spinlocks (0 ); +die (regs,"Oops" ); +do_exit (SIGKILL ); +} +static inline void no_context (struct pt_regs *regs,unsigned long addr) {/* Are we prepared to handle this kernel fault? */
Signature · 1 line
2.17.0
PATCH v2 2/2 riscv/mm: Prevent kernel module to access user memory without uaccess routines
In reply to Eric LinWe found this issue in an legacy out-of-tree kernel module which didn't properly access user space pointer by get/put_user(). Such an illegal access loops in the page fault handler. To resolve this, let it die here.
--- arch/riscv/mm/fault.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/riscv/mm/fault.c +5 -0
@@ -245,6 +245,11 @@ asmlinkage void do_page_fault(struct pt_regs *regs)if (user_mode (regs)) flags |=FAULT_FLAG_USER ; +if (!user_mode (regs) && addr <TASK_SIZE && +unlikely (!(regs->status &SR_SUM ))) +die_kernel_fault ("access to user memory without uaccess routines" , + addr, regs); +perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, addr);if (cause ==EXC_STORE_PAGE_FAULT )
Signature · 1 line
2.17.0
Hi Eric,
Quoted 8 lines · Eric Lin
Accesses to user-space memory without calling uaccess routine leads to hanging in page fault handler. Like arm64, we let it die earlier in page fault handler.
Changes in v2:
-Add adie_kernel_fault()helper
-Split one long line code into two
Please also make no_context() use the new helper. Other than that:
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
On Thu, Dec 03, 2020 at 03:29:57PM +0800, Pekka Enberg wrote:
Hi Pekka,
Quoted 8 lines
Hi Eric,
Quoted 5 lines · Eric Lin
Accesses to user-space memory without calling uaccess routine leads to hanging in page fault handler. Like arm64, we let it die earlier in page fault handler.
Quoted 6 lines
Quoted 3 lines
Changes in v2:
-Add adie_kernel_fault()helper
-Split one long line code into twoPlease also make
no_context()use the new helper. Other than that:
OK, I'll make no_context() use the new helper in v3. Thanks for your review.
Quoted 1 line
Reviewed-by Pekka Enberg <[email protected]>