Linux Hardening
 help / color / mirror / Atom feed
* [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by
@ 2024-08-01 14:23 Dmitry Antipov
  2024-08-01 14:32 ` Gustavo A. R. Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dmitry Antipov @ 2024-08-01 14:23 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Paolo Abeni, Gustavo A . R . Silva, Kuniyuki Iwashima, Kees Cook,
	netdev, linux-hardening, Dmitry Antipov

According to '__reuseport_alloc()', annotate flexible array member
'sock' of 'struct sock_reuseport' with '__counted_by()' and use
convenient 'struct_size()' to simplify the math used in 'kzalloc()'.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v3: one more style nit (Jakub)
    https://lore.kernel.org/netdev/20240731165029.5f4b4e60@kernel.org
v2: style (Jakub), title and commit message (Gustavo) adjustments
    https://lore.kernel.org/netdev/20240730170142.32a6e9aa@kernel.org
    https://lore.kernel.org/netdev/c815078e-67f9-4235-b66c-29f8bdd1a9e0@embeddedor.com
---
 include/net/sock_reuseport.h | 2 +-
 net/core/sock_reuseport.c    | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/net/sock_reuseport.h b/include/net/sock_reuseport.h
index 6ec140b0a61b..6e4faf3ee76f 100644
--- a/include/net/sock_reuseport.h
+++ b/include/net/sock_reuseport.h
@@ -26,7 +26,7 @@ struct sock_reuseport {
 	unsigned int		bind_inany:1;
 	unsigned int		has_conns:1;
 	struct bpf_prog __rcu	*prog;		/* optional BPF sock selector */
-	struct sock		*socks[];	/* array of sock pointers */
+	struct sock		*socks[] __counted_by(max_socks);
 };
 
 extern int reuseport_alloc(struct sock *sk, bool bind_inany);
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index 5a165286e4d8..4211710393a8 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -173,10 +173,9 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,
 
 static struct sock_reuseport *__reuseport_alloc(unsigned int max_socks)
 {
-	unsigned int size = sizeof(struct sock_reuseport) +
-		      sizeof(struct sock *) * max_socks;
-	struct sock_reuseport *reuse = kzalloc(size, GFP_ATOMIC);
+	struct sock_reuseport *reuse;
 
+	reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC);
 	if (!reuse)
 		return NULL;
 
-- 
2.45.2


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

* Re: [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by
  2024-08-01 14:23 [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by Dmitry Antipov
@ 2024-08-01 14:32 ` Gustavo A. R. Silva
  2024-08-02  0:20 ` Kuniyuki Iwashima
  2024-08-03  0:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-01 14:32 UTC (permalink / raw)
  To: Dmitry Antipov, Jakub Kicinski
  Cc: Paolo Abeni, Kuniyuki Iwashima, Kees Cook, netdev,
	linux-hardening



On 01/08/24 08:23, Dmitry Antipov wrote:
> According to '__reuseport_alloc()', annotate flexible array member
> 'sock' of 'struct sock_reuseport' with '__counted_by()' and use
> convenient 'struct_size()' to simplify the math used in 'kzalloc()'.
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-Gustavo

> ---
> v3: one more style nit (Jakub)
>      https://lore.kernel.org/netdev/20240731165029.5f4b4e60@kernel.org
> v2: style (Jakub), title and commit message (Gustavo) adjustments
>      https://lore.kernel.org/netdev/20240730170142.32a6e9aa@kernel.org
>      https://lore.kernel.org/netdev/c815078e-67f9-4235-b66c-29f8bdd1a9e0@embeddedor.com
> ---
>   include/net/sock_reuseport.h | 2 +-
>   net/core/sock_reuseport.c    | 5 ++---
>   2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/include/net/sock_reuseport.h b/include/net/sock_reuseport.h
> index 6ec140b0a61b..6e4faf3ee76f 100644
> --- a/include/net/sock_reuseport.h
> +++ b/include/net/sock_reuseport.h
> @@ -26,7 +26,7 @@ struct sock_reuseport {
>   	unsigned int		bind_inany:1;
>   	unsigned int		has_conns:1;
>   	struct bpf_prog __rcu	*prog;		/* optional BPF sock selector */
> -	struct sock		*socks[];	/* array of sock pointers */
> +	struct sock		*socks[] __counted_by(max_socks);
>   };
>   
>   extern int reuseport_alloc(struct sock *sk, bool bind_inany);
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index 5a165286e4d8..4211710393a8 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -173,10 +173,9 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,
>   
>   static struct sock_reuseport *__reuseport_alloc(unsigned int max_socks)
>   {
> -	unsigned int size = sizeof(struct sock_reuseport) +
> -		      sizeof(struct sock *) * max_socks;
> -	struct sock_reuseport *reuse = kzalloc(size, GFP_ATOMIC);
> +	struct sock_reuseport *reuse;
>   
> +	reuse = kzalloc(struct_size(reuse, socks, max_socks), GFP_ATOMIC);
>   	if (!reuse)
>   		return NULL;
>   

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

* Re: [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by
  2024-08-01 14:23 [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by Dmitry Antipov
  2024-08-01 14:32 ` Gustavo A. R. Silva
@ 2024-08-02  0:20 ` Kuniyuki Iwashima
  2024-08-03  0:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-02  0:20 UTC (permalink / raw)
  To: dmantipov; +Cc: gustavo, kees, kuba, kuniyu, linux-hardening, netdev, pabeni

From: Dmitry Antipov <dmantipov@yandex.ru>
Date: Thu,  1 Aug 2024 17:23:11 +0300
> According to '__reuseport_alloc()', annotate flexible array member
> 'sock' of 'struct sock_reuseport' with '__counted_by()' and use
> convenient 'struct_size()' to simplify the math used in 'kzalloc()'.
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

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

* Re: [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by
  2024-08-01 14:23 [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by Dmitry Antipov
  2024-08-01 14:32 ` Gustavo A. R. Silva
  2024-08-02  0:20 ` Kuniyuki Iwashima
@ 2024-08-03  0:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-03  0:30 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: kuba, pabeni, gustavo, kuniyu, kees, netdev, linux-hardening

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  1 Aug 2024 17:23:11 +0300 you wrote:
> According to '__reuseport_alloc()', annotate flexible array member
> 'sock' of 'struct sock_reuseport' with '__counted_by()' and use
> convenient 'struct_size()' to simplify the math used in 'kzalloc()'.
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> v3: one more style nit (Jakub)
>     https://lore.kernel.org/netdev/20240731165029.5f4b4e60@kernel.org
> v2: style (Jakub), title and commit message (Gustavo) adjustments
>     https://lore.kernel.org/netdev/20240730170142.32a6e9aa@kernel.org
>     https://lore.kernel.org/netdev/c815078e-67f9-4235-b66c-29f8bdd1a9e0@embeddedor.com
> 
> [...]

Here is the summary with links:
  - [v3] net: core: annotate socks of struct sock_reuseport with __counted_by
    https://git.kernel.org/netdev/net-next/c/f94074687d05

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] 4+ messages in thread

end of thread, other threads:[~2024-08-03  0:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01 14:23 [PATCH v3] net: core: annotate socks of struct sock_reuseport with __counted_by Dmitry Antipov
2024-08-01 14:32 ` Gustavo A. R. Silva
2024-08-02  0:20 ` Kuniyuki Iwashima
2024-08-03  0:30 ` 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