Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1]
@ 2021-07-15 12:57 Colin King
  2021-07-15 17:02 ` Ilya Leoshkevich
  2021-07-15 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2021-07-15 12:57 UTC (permalink / raw)
  To: Ilya Leoshkevich, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Michael Holzheu, Martin Schwidefsky, netdev, bpf,
	linux-s390
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently array jit->seen_reg[r1] is being accessed before the range
checking of index r1. The range changing on r1 should be performed
first since it will avoid any potential out-of-range accesses on the
array seen_reg[] and also it is more optimal to perform checks on
r1 before fetching data from the array.  Fix this by swapping the
order of the checks before the array access.

Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 arch/s390/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 63cae0476bb4..2ae419f5115a 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -112,7 +112,7 @@ static inline void reg_set_seen(struct bpf_jit *jit, u32 b1)
 {
 	u32 r1 = reg2hex[b1];
 
-	if (!jit->seen_reg[r1] && r1 >= 6 && r1 <= 15)
+	if (r1 >= 6 && r1 <= 15 && !jit->seen_reg[r1])
 		jit->seen_reg[r1] = 1;
 }
 
-- 
2.31.1


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

* Re: [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1]
  2021-07-15 12:57 [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1] Colin King
@ 2021-07-15 17:02 ` Ilya Leoshkevich
  2021-07-15 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2021-07-15 17:02 UTC (permalink / raw)
  To: Colin King, Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Michael Holzheu,
	Martin Schwidefsky, netdev, bpf, linux-s390
  Cc: kernel-janitors, linux-kernel

On Thu, 2021-07-15 at 13:57 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently array jit->seen_reg[r1] is being accessed before the range
> checking of index r1. The range changing on r1 should be performed
> first since it will avoid any potential out-of-range accesses on the
> array seen_reg[] and also it is more optimal to perform checks on
> r1 before fetching data from the array.  Fix this by swapping the
> order of the checks before the array access.
> 
> Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  arch/s390/net/bpf_jit_comp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/s390/net/bpf_jit_comp.c
> b/arch/s390/net/bpf_jit_comp.c
> index 63cae0476bb4..2ae419f5115a 100644
> --- a/arch/s390/net/bpf_jit_comp.c
> +++ b/arch/s390/net/bpf_jit_comp.c
> @@ -112,7 +112,7 @@ static inline void reg_set_seen(struct bpf_jit
> *jit, u32 b1)
>  {
>         u32 r1 = reg2hex[b1];
>  
> -       if (!jit->seen_reg[r1] && r1 >= 6 && r1 <= 15)
> +       if (r1 >= 6 && r1 <= 15 && !jit->seen_reg[r1])
>                 jit->seen_reg[r1] = 1;
>  }
>  

Looks good to me, thanks!

Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>


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

* Re: [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1]
  2021-07-15 12:57 [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1] Colin King
  2021-07-15 17:02 ` Ilya Leoshkevich
@ 2021-07-15 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-15 17:50 UTC (permalink / raw)
  To: Colin King
  Cc: iii, hca, gor, borntraeger, ast, daniel, andrii, songliubraving,
	yhs, john.fastabend, kpsingh, holzheu, schwidefsky, netdev, bpf,
	linux-s390, kernel-janitors, linux-kernel

Hello:

This patch was applied to bpf/bpf.git (refs/heads/master):

On Thu, 15 Jul 2021 13:57:12 +0100 you wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently array jit->seen_reg[r1] is being accessed before the range
> checking of index r1. The range changing on r1 should be performed
> first since it will avoid any potential out-of-range accesses on the
> array seen_reg[] and also it is more optimal to perform checks on
> r1 before fetching data from the array.  Fix this by swapping the
> order of the checks before the array access.
> 
> [...]

Here is the summary with links:
  - s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1]
    https://git.kernel.org/bpf/bpf/c/91091656252f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-07-15 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 12:57 [PATCH] s390/bpf: perform r1 range checking before accessing jit->seen_reg[r1] Colin King
2021-07-15 17:02 ` Ilya Leoshkevich
2021-07-15 17:50 ` patchwork-bot+netdevbpf

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