linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines
@ 2020-11-30  5:30 Eric Lin
  2020-11-30  8:07 ` Pekka Enberg
  2020-11-30  8:30 ` Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Lin @ 2020-11-30  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-riscv, walken, daniel.m.jordan, peterx, akpm,
	penberg, aou, palmer, paul.walmsley
  Cc: Eric Lin, dslin1010, Alan Kao

In the page fault handler, an access to user-space memory
without get/put_user() or copy_from/to_user() routines is
not resolved properly. Like arm and other architectures,
we need to let it die earlier in page fault handler.

Signed-off-by: Eric Lin <tesheng@andestech.com>
Cc: Alan Kao <alankao@andestech.com>
---
 arch/riscv/mm/fault.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 3c8b9e433c67..a452cfa266a2 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -232,6 +232,9 @@ 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(regs, "Accessing user space memory without uaccess routines\n");
+
 	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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines
  2020-11-30  5:30 [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines Eric Lin
@ 2020-11-30  8:07 ` Pekka Enberg
  2020-12-01  5:32   ` Eric Lin
  2020-11-30  8:30 ` Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2020-11-30  8:07 UTC (permalink / raw)
  To: Eric Lin
  Cc: Albert Ou, dslin1010, Alan Kao, LKML, Peter Xu, Daniel Jordan,
	Palmer Dabbelt, Paul Walmsley, Andrew Morton, Michel Lespinasse,
	linux-riscv

On Mon, Nov 30, 2020 at 7:33 AM Eric Lin <tesheng@andestech.com> wrote:
>
> In the page fault handler, an access to user-space memory
> without get/put_user() or copy_from/to_user() routines is
> not resolved properly. Like arm and other architectures,
> we need to let it die earlier in page fault handler.

Fix looks good to me. Can you elaborate on how you found the issue and
how the bug manifests itself?

>
> Signed-off-by: Eric Lin <tesheng@andestech.com>
> Cc: Alan Kao <alankao@andestech.com>
> ---
>  arch/riscv/mm/fault.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
> index 3c8b9e433c67..a452cfa266a2 100644
> --- a/arch/riscv/mm/fault.c
> +++ b/arch/riscv/mm/fault.c
> @@ -232,6 +232,9 @@ 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(regs, "Accessing user space memory without uaccess routines\n");

Let's introduce a die_kernel_fault() helper (similar to arm64, for
example) to ensure same semantics for the different kernel faults. You
can extract the helper from no_context().

> +
>         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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines
  2020-11-30  5:30 [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines Eric Lin
  2020-11-30  8:07 ` Pekka Enberg
@ 2020-11-30  8:30 ` Christoph Hellwig
  2020-12-01  5:20   ` Eric Lin
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2020-11-30  8:30 UTC (permalink / raw)
  To: Eric Lin
  Cc: aou, dslin1010, Alan Kao, linux-kernel, peterx, daniel.m.jordan,
	penberg, palmer, paul.walmsley, akpm, walken, linux-riscv

> +	if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM)))

Please avoid the overly long line.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines
  2020-11-30  8:30 ` Christoph Hellwig
@ 2020-12-01  5:20   ` Eric Lin
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Lin @ 2020-12-01  5:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: aou, dslin1010, Alan Quey-Liang Kao(?????}),
	linux-kernel, peterx, daniel.m.jordan, penberg, palmer,
	paul.walmsley, akpm, walken, linux-riscv

On Mon, Nov 30, 2020 at 04:30:15PM +0800, Christoph Hellwig wrote:
Hi Christoph,
> > +	if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM)))
> 
> Please avoid the overly long line.
OK, I'll modify it in v2. Thanks for your review.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines
  2020-11-30  8:07 ` Pekka Enberg
@ 2020-12-01  5:32   ` Eric Lin
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Lin @ 2020-12-01  5:32 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Albert Ou, dslin1010, Alan Quey-Liang Kao(?????????),
	LKML, Peter Xu, Daniel Jordan, Palmer Dabbelt, Paul Walmsley,
	Andrew Morton, Michel Lespinasse, linux-riscv

On Mon, Nov 30, 2020 at 04:07:03PM +0800, Pekka Enberg wrote:

Hi Pekka,
> On Mon, Nov 30, 2020 at 7:33 AM Eric Lin <tesheng@andestech.com> wrote:
> >
> > In the page fault handler, an access to user-space memory
> > without get/put_user() or copy_from/to_user() routines is
> > not resolved properly. Like arm and other architectures,
> > we need to let it die earlier in page fault handler.
> 
> Fix looks good to me. Can you elaborate on how you found the issue and
> how the bug manifests itself?

OK, I'll elaborate more on the commit message.

> 
> >
> > Signed-off-by: Eric Lin <tesheng@andestech.com>
> > Cc: Alan Kao <alankao@andestech.com>
> > ---
> >  arch/riscv/mm/fault.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
> > index 3c8b9e433c67..a452cfa266a2 100644
> > --- a/arch/riscv/mm/fault.c
> > +++ b/arch/riscv/mm/fault.c
> > @@ -232,6 +232,9 @@ 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(regs, "Accessing user space memory without uaccess routines\n");
> 
> Let's introduce a die_kernel_fault() helper (similar to arm64, for
> example) to ensure same semantics for the different kernel faults. You
> can extract the helper from no_context().

OK, I'll add a die_kernel_fault() helper function in v2.

Thanks for your review.

> 
> > +
> >         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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-01  5:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30  5:30 [PATCH] riscv/mm: Prevent kernel module access user-space memory without uaccess routines Eric Lin
2020-11-30  8:07 ` Pekka Enberg
2020-12-01  5:32   ` Eric Lin
2020-11-30  8:30 ` Christoph Hellwig
2020-12-01  5:20   ` Eric Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).