* [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large
@ 2024-01-25 19:18 Joe Damato
2024-01-25 19:33 ` Eric Dumazet
2024-01-26 9:11 ` Breno Leitao
0 siblings, 2 replies; 3+ messages in thread
From: Joe Damato @ 2024-01-25 19:18 UTC (permalink / raw)
To: linux-kernel, netdev
Cc: dhowells, alexander, leitao, wuyun.abel, kuniyu, pabeni, kuba,
edumazet, davem, Joe Damato
When drivers call netif_napi_add_weight with a weight that is larger
than NAPI_POLL_WEIGHT, the networking code allows the larger weight, but
prints an error.
Replicate this check for SO_BUSY_POLL_BUDGET; check if the user
specified amount exceeds NAPI_POLL_WEIGHT, allow it anyway, but print an
error.
Signed-off-by: Joe Damato <jdamato@fastly.com>
---
net/core/sock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/sock.c b/net/core/sock.c
index 158dbdebce6a..ed243bd0dd77 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1153,6 +1153,9 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
return -EPERM;
if (val < 0 || val > U16_MAX)
return -EINVAL;
+ if (val > NAPI_POLL_WEIGHT)
+ pr_err("SO_BUSY_POLL_BUDGET %u exceeds suggested maximum %u\n", val,
+ NAPI_POLL_WEIGHT);
WRITE_ONCE(sk->sk_busy_poll_budget, val);
return 0;
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large
2024-01-25 19:18 [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large Joe Damato
@ 2024-01-25 19:33 ` Eric Dumazet
2024-01-26 9:11 ` Breno Leitao
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2024-01-25 19:33 UTC (permalink / raw)
To: Joe Damato
Cc: linux-kernel, netdev, dhowells, alexander, leitao, wuyun.abel,
kuniyu, pabeni, kuba, davem
On Thu, Jan 25, 2024 at 8:18 PM Joe Damato <jdamato@fastly.com> wrote:
>
> When drivers call netif_napi_add_weight with a weight that is larger
> than NAPI_POLL_WEIGHT, the networking code allows the larger weight, but
> prints an error.
>
> Replicate this check for SO_BUSY_POLL_BUDGET; check if the user
> specified amount exceeds NAPI_POLL_WEIGHT, allow it anyway, but print an
> error.
>
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
> net/core/sock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 158dbdebce6a..ed243bd0dd77 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1153,6 +1153,9 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
> return -EPERM;
> if (val < 0 || val > U16_MAX)
> return -EINVAL;
> + if (val > NAPI_POLL_WEIGHT)
> + pr_err("SO_BUSY_POLL_BUDGET %u exceeds suggested maximum %u\n", val,
> + NAPI_POLL_WEIGHT);
> WRITE_ONCE(sk->sk_busy_poll_budget, val);
> return 0;
This is code run by privileged (CAP_NET_ADMIN) users,
please do not spam the console with such a message.
My point was : Do not allow an unpriv user to set an arbitrary value.
netif_napi_add_weight() is used from kernel drivers, we network
maintainers usually object
if a driver attempts to use a big value, at code review time.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large
2024-01-25 19:18 [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large Joe Damato
2024-01-25 19:33 ` Eric Dumazet
@ 2024-01-26 9:11 ` Breno Leitao
1 sibling, 0 replies; 3+ messages in thread
From: Breno Leitao @ 2024-01-26 9:11 UTC (permalink / raw)
To: Joe Damato
Cc: linux-kernel, netdev, dhowells, alexander, wuyun.abel, kuniyu,
pabeni, kuba, edumazet, davem
Hi Joe,
On Thu, Jan 25, 2024 at 07:18:40PM +0000, Joe Damato wrote:
> When drivers call netif_napi_add_weight with a weight that is larger
> than NAPI_POLL_WEIGHT, the networking code allows the larger weight, but
> prints an error.
>
> Replicate this check for SO_BUSY_POLL_BUDGET; check if the user
> specified amount exceeds NAPI_POLL_WEIGHT, allow it anyway, but print an
> error.
>
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
> net/core/sock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 158dbdebce6a..ed243bd0dd77 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1153,6 +1153,9 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
> return -EPERM;
> if (val < 0 || val > U16_MAX)
> return -EINVAL;
> + if (val > NAPI_POLL_WEIGHT)
> + pr_err("SO_BUSY_POLL_BUDGET %u exceeds suggested maximum %u\n", val,
> + NAPI_POLL_WEIGHT);
'val' is a signed value variable. I suspect it will never be negative given
the line above (val < 0 || val > U16_MAX), but, I am wondering if you
should still print it as signed integer (%d) to keep it consistent.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-26 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-25 19:18 [PATCH net-next] net: print error if SO_BUSY_POLL_BUDGET is large Joe Damato
2024-01-25 19:33 ` Eric Dumazet
2024-01-26 9:11 ` Breno Leitao
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.