linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: reject invalid syscalls below -1
@ 2019-12-18  8:47 David Abdurachmanov
  2019-12-18  9:46 ` Andreas Schwab
  2019-12-28  6:02 ` Paul Walmsley
  0 siblings, 2 replies; 5+ messages in thread
From: David Abdurachmanov @ 2019-12-18  8:47 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, David Abdurachmanov,
	Kees Cook, Anup Patel, Vincent Chen, Valentin Schneider,
	Thomas Gleixner, Bin Meng, linux-riscv, linux-kernel
  Cc: david.abdurachmanov

Running "stress-ng --enosys 4 -t 20 -v" showed a large number of kernel oops
with "Unable to handle kernel paging request at virtual address" message. This
happens when enosys stressor starts testing random non-valid syscalls.

I forgot to redirect any syscall below -1 to sys_ni_syscall.

With the patch kernel oops messages are gone while running stress-ng enosys
stressor.

Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
Fixes: 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index a1349ca64669..e163b7b64c86 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -246,6 +246,7 @@ check_syscall_nr:
 	 */
 	li t1, -1
 	beq a7, t1, ret_from_syscall_rejected
+	blt a7, t1, 1f
 	/* Call syscall */
 	la s0, sys_call_table
 	slli t0, a7, RISCV_LGPTR
-- 
2.24.1


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

* Re: [PATCH] riscv: reject invalid syscalls below -1
  2019-12-18  8:47 [PATCH] riscv: reject invalid syscalls below -1 David Abdurachmanov
@ 2019-12-18  9:46 ` Andreas Schwab
  2019-12-18 10:06   ` David Abdurachmanov
  2019-12-28  6:02 ` Paul Walmsley
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2019-12-18  9:46 UTC (permalink / raw)
  To: David Abdurachmanov
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, David Abdurachmanov,
	Kees Cook, Anup Patel, Vincent Chen, Valentin Schneider,
	Thomas Gleixner, Bin Meng, linux-riscv, linux-kernel

On Dez 18 2019, David Abdurachmanov wrote:

> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
> index a1349ca64669..e163b7b64c86 100644
> --- a/arch/riscv/kernel/entry.S
> +++ b/arch/riscv/kernel/entry.S
> @@ -246,6 +246,7 @@ check_syscall_nr:
>  	 */
>  	li t1, -1
>  	beq a7, t1, ret_from_syscall_rejected
> +	blt a7, t1, 1f

How about using bgeu instead in the preceding check?

	/*
	 * Syscall number held in a7.
	 * If syscall number is above allowed value, redirect to ni_syscall.
	 */
	bge a7, t0, 1f

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] riscv: reject invalid syscalls below -1
  2019-12-18  9:46 ` Andreas Schwab
@ 2019-12-18 10:06   ` David Abdurachmanov
  2019-12-18 10:35     ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: David Abdurachmanov @ 2019-12-18 10:06 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, David Abdurachmanov,
	Kees Cook, Anup Patel, Vincent Chen, Valentin Schneider,
	Thomas Gleixner, Bin Meng, linux-riscv,
	linux-kernel@vger.kernel.org List

On Wed, Dec 18, 2019 at 11:46 AM Andreas Schwab <schwab@suse.de> wrote:
>
> On Dez 18 2019, David Abdurachmanov wrote:
>
> > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
> > index a1349ca64669..e163b7b64c86 100644
> > --- a/arch/riscv/kernel/entry.S
> > +++ b/arch/riscv/kernel/entry.S
> > @@ -246,6 +246,7 @@ check_syscall_nr:
> >        */
> >       li t1, -1
> >       beq a7, t1, ret_from_syscall_rejected
> > +     blt a7, t1, 1f
>
> How about using bgeu instead in the preceding check?

The syscall number could be -1 if tracer rejected it.

We could do:

li t0, __NR_syscalls
[..]
// first check if syscall was rejected
li t1, -1
beq a7, t1, ret_from_syscall_rejected
// then check the bounds
bgeu a7, t0, 1f

>
>         /*
>          * Syscall number held in a7.
>          * If syscall number is above allowed value, redirect to ni_syscall.
>          */
>         bge a7, t0, 1f
>
> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

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

* Re: [PATCH] riscv: reject invalid syscalls below -1
  2019-12-18 10:06   ` David Abdurachmanov
@ 2019-12-18 10:35     ` Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2019-12-18 10:35 UTC (permalink / raw)
  To: David Abdurachmanov
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, David Abdurachmanov,
	Kees Cook, Anup Patel, Vincent Chen, Valentin Schneider,
	Thomas Gleixner, Bin Meng, linux-riscv,
	linux-kernel@vger.kernel.org List

On Dez 18 2019, David Abdurachmanov wrote:

> On Wed, Dec 18, 2019 at 11:46 AM Andreas Schwab <schwab@suse.de> wrote:
>>
>> On Dez 18 2019, David Abdurachmanov wrote:
>>
>> > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
>> > index a1349ca64669..e163b7b64c86 100644
>> > --- a/arch/riscv/kernel/entry.S
>> > +++ b/arch/riscv/kernel/entry.S
>> > @@ -246,6 +246,7 @@ check_syscall_nr:
>> >        */
>> >       li t1, -1
>> >       beq a7, t1, ret_from_syscall_rejected
>> > +     blt a7, t1, 1f
>>
>> How about using bgeu instead in the preceding check?
>
> The syscall number could be -1 if tracer rejected it.

So check for -1 first, then for out-of-range?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] riscv: reject invalid syscalls below -1
  2019-12-18  8:47 [PATCH] riscv: reject invalid syscalls below -1 David Abdurachmanov
  2019-12-18  9:46 ` Andreas Schwab
@ 2019-12-28  6:02 ` Paul Walmsley
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2019-12-28  6:02 UTC (permalink / raw)
  To: David Abdurachmanov
  Cc: Palmer Dabbelt, Albert Ou, David Abdurachmanov, Kees Cook,
	Anup Patel, Vincent Chen, Valentin Schneider, Thomas Gleixner,
	Bin Meng, linux-riscv, linux-kernel

On Wed, 18 Dec 2019, David Abdurachmanov wrote:

> Running "stress-ng --enosys 4 -t 20 -v" showed a large number of kernel oops
> with "Unable to handle kernel paging request at virtual address" message. This
> happens when enosys stressor starts testing random non-valid syscalls.
> 
> I forgot to redirect any syscall below -1 to sys_ni_syscall.
> 
> With the patch kernel oops messages are gone while running stress-ng enosys
> stressor.
> 
> Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
> Fixes: 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")

From the thread, I couldn't tell whether you were happy with this patch as 
it stands or not; the thread seems to have petered out.  So this one has 
been queued for v5.5-rc; let me know if you didn't intend for that to 
happen.


- Paul

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

end of thread, other threads:[~2019-12-28  6:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18  8:47 [PATCH] riscv: reject invalid syscalls below -1 David Abdurachmanov
2019-12-18  9:46 ` Andreas Schwab
2019-12-18 10:06   ` David Abdurachmanov
2019-12-18 10:35     ` Andreas Schwab
2019-12-28  6:02 ` Paul Walmsley

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).