From: Eric Lin <tesheng@andestech.com>
To: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<walken@google.com>, <vbabka@suse.cz>, <peterx@redhat.com>,
<akpm@linux-foundation.org>, <penberg@kernel.org>,
<aou@eecs.berkeley.edu>, <palmer@dabbelt.com>,
<paul.walmsley@sifive.com>, <hch@infradead.org>
Cc: Eric Lin <tesheng@andestech.com>, Alan Kao <alankao@andestech.com>
Subject: [PATCH v2 2/2] riscv/mm: Prevent kernel module to access user memory without uaccess routines
Date: Thu, 3 Dec 2020 14:48:26 +0800 [thread overview]
Message-ID: <20201203064826.30832-3-tesheng@andestech.com> (raw)
In-Reply-To: <20201203064826.30832-1-tesheng@andestech.com>
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@andestech.com>
Cc: Alan Kao <alankao@andestech.com>
---
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 0bcfd0e1b39e..00884c1bac28 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -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)
--
2.17.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2020-12-03 6:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 6:48 [PATCH v2 0/2] Let illegal access to user-space memory die Eric Lin
2020-12-03 6:48 ` [PATCH v2 1/2] riscv/mm: Introduce a die_kernel_fault() helper function Eric Lin
2020-12-03 6:48 ` Eric Lin [this message]
2020-12-03 7:29 ` [PATCH v2 0/2] Let illegal access to user-space memory die Pekka Enberg
2020-12-03 8:16 ` Eric Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201203064826.30832-3-tesheng@andestech.com \
--to=tesheng@andestech.com \
--cc=akpm@linux-foundation.org \
--cc=alankao@andestech.com \
--cc=aou@eecs.berkeley.edu \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=penberg@kernel.org \
--cc=peterx@redhat.com \
--cc=vbabka@suse.cz \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox