All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 bpf] bpf: Fix a data-race around bpf_jit_limit.
@ 2022-08-23 18:12 Kuniyuki Iwashima
  2022-08-23 21:20 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Kuniyuki Iwashima @ 2022-08-23 18:12 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, bpf, netdev

While reading bpf_jit_limit, it can be changed concurrently.
Thus, we need to add READ_ONCE() to its reader.

Fixes: ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
v2:
  * Drop other 3 patches (No change for this patch)

v1: https://lore.kernel.org/bpf/20220818042339.82992-1-kuniyu@amazon.com/
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index c1e10d088dbb..3d9eb3ae334c 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -971,7 +971,7 @@ pure_initcall(bpf_jit_charge_init);
 
 int bpf_jit_charge_modmem(u32 size)
 {
-	if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) {
+	if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) {
 		if (!bpf_capable()) {
 			atomic_long_sub(size, &bpf_jit_current);
 			return -EPERM;
-- 
2.30.2


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

* Re: [PATCH v2 bpf] bpf: Fix a data-race around bpf_jit_limit.
  2022-08-23 18:12 [PATCH v2 bpf] bpf: Fix a data-race around bpf_jit_limit Kuniyuki Iwashima
@ 2022-08-23 21:20 ` Daniel Borkmann
  2022-08-23 21:51   ` Kuniyuki Iwashima
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2022-08-23 21:20 UTC (permalink / raw)
  To: Kuniyuki Iwashima, Alexei Starovoitov, Andrii Nakryiko
  Cc: Kuniyuki Iwashima, bpf, netdev

On 8/23/22 8:12 PM, Kuniyuki Iwashima wrote:
> While reading bpf_jit_limit, it can be changed concurrently.
> Thus, we need to add READ_ONCE() to its reader.

For sake of a better/clearer commit message, please also provide data about the
WRITE_ONCE() pairing that this READ_ONCE() targets. This seems to be the case in
__do_proc_doulongvec_minmax() as far as I can see. For your 2nd sentence above
please also include load-tearing as main motivation for your fix.

> Fixes: ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> v2:
>    * Drop other 3 patches (No change for this patch)
> 
> v1: https://lore.kernel.org/bpf/20220818042339.82992-1-kuniyu@amazon.com/
> ---
>   kernel/bpf/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index c1e10d088dbb..3d9eb3ae334c 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -971,7 +971,7 @@ pure_initcall(bpf_jit_charge_init);
>   
>   int bpf_jit_charge_modmem(u32 size)
>   {
> -	if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) {
> +	if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) {
>   		if (!bpf_capable()) {
>   			atomic_long_sub(size, &bpf_jit_current);
>   			return -EPERM;
> 


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

* Re: [PATCH v2 bpf] bpf: Fix a data-race around bpf_jit_limit.
  2022-08-23 21:20 ` Daniel Borkmann
@ 2022-08-23 21:51   ` Kuniyuki Iwashima
  0 siblings, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2022-08-23 21:51 UTC (permalink / raw)
  To: daniel; +Cc: andrii, ast, bpf, kuni1840, kuniyu, netdev

From:   Daniel Borkmann <daniel@iogearbox.net>
Date:   Tue, 23 Aug 2022 23:20:29 +0200
> On 8/23/22 8:12 PM, Kuniyuki Iwashima wrote:
> > While reading bpf_jit_limit, it can be changed concurrently.
> > Thus, we need to add READ_ONCE() to its reader.
> 
> For sake of a better/clearer commit message, please also provide data about the
> WRITE_ONCE() pairing that this READ_ONCE() targets. This seems to be the case in
> __do_proc_doulongvec_minmax() as far as I can see. For your 2nd sentence above
> please also include load-tearing as main motivation for your fix.

I'll add better description.
Thank you!

> 
> > Fixes: ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations")
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> > ---
> > v2:
> >    * Drop other 3 patches (No change for this patch)
> > 
> > v1: https://lore.kernel.org/bpf/20220818042339.82992-1-kuniyu@amazon.com/
> > ---
> >   kernel/bpf/core.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index c1e10d088dbb..3d9eb3ae334c 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -971,7 +971,7 @@ pure_initcall(bpf_jit_charge_init);
> >   
> >   int bpf_jit_charge_modmem(u32 size)
> >   {
> > -	if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) {
> > +	if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) {
> >   		if (!bpf_capable()) {
> >   			atomic_long_sub(size, &bpf_jit_current);
> >   			return -EPERM;
> > 

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

end of thread, other threads:[~2022-08-23 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 18:12 [PATCH v2 bpf] bpf: Fix a data-race around bpf_jit_limit Kuniyuki Iwashima
2022-08-23 21:20 ` Daniel Borkmann
2022-08-23 21:51   ` Kuniyuki Iwashima

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.