[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201204054259.32684-3-tesheng@andestech.com>
Date: Fri, 4 Dec 2020 13:42:59 +0800
From: Eric Lin <tesheng@...estech.com>
To: <linux-kernel@...r.kernel.org>, <linux-riscv@...ts.infradead.org>,
<walken@...gle.com>, <vbabka@...e.cz>, <peterx@...hat.com>,
<akpm@...ux-foundation.org>, <penberg@...nel.org>,
<aou@...s.berkeley.edu>, <palmer@...belt.com>,
<paul.walmsley@...ive.com>
CC: Eric Lin <tesheng@...estech.com>, Alan Kao <alankao@...estech.com>
Subject: [PATCH v3 2/2] riscv/mm: Prevent kernel module to access user memory without uaccess routines
We 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.
Signed-off-by: Eric Lin <tesheng@...estech.com>
Cc: Alan Kao <alankao@...estech.com>
Reviewed-by: Pekka Enberg <penberg@...nel.org>
---
arch/riscv/mm/fault.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 0d5f06d6e3c7..33d284188f9a 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -243,6 +243,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)
--
2.17.0
Powered by blists - more mailing lists