netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] mlxsw: Annotate structs with __counted_by
@ 2023-09-29 18:07 Kees Cook
  2023-09-29 18:07 ` [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards " Kees Cook
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	netdev, linux-hardening, llvm

Hi,

This annotates several mlxsw structures with the coming __counted_by attribute
for bounds checking of flexible arrays at run-time. For more details, see
commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").

Thanks!

-Kees

Kees Cook (5):
  mlxsw: Annotate struct mlxsw_linecards with __counted_by
  mlxsw: core: Annotate struct mlxsw_env with __counted_by
  mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with
    __counted_by
  mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info
    with __counted_by
  mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by

 drivers/net/ethernet/mellanox/mlxsw/core.h            | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/core_env.c        | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c    | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.34.1


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

* [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
@ 2023-09-29 18:07 ` Kees Cook
  2023-10-01 10:32   ` Ido Schimmel
  2023-09-29 18:07 ` [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env " Kees Cook
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct mlxsw_linecards.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mellanox/mlxsw/core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h
index e5474d3e34db..c6bc5819ce43 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.h
@@ -624,7 +624,7 @@ struct mlxsw_linecards {
 	struct mlxsw_linecard_types_info *types_info;
 	struct list_head event_ops_list;
 	struct mutex event_ops_list_lock; /* Locks accesses to event ops list */
-	struct mlxsw_linecard linecards[];
+	struct mlxsw_linecard linecards[] __counted_by(count);
 };
 
 static inline struct mlxsw_linecard *
-- 
2.34.1


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

* [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
  2023-09-29 18:07 ` [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards " Kees Cook
@ 2023-09-29 18:07 ` Kees Cook
  2023-10-01 10:33   ` Ido Schimmel
  2023-09-29 18:07 ` [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool " Kees Cook
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct mlxsw_env.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mellanox/mlxsw/core_env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c
index d637c0348fa1..a129e0df1d07 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c
@@ -34,7 +34,7 @@ struct mlxsw_env {
 	u8 num_of_slots; /* Including the main board. */
 	u8 max_eeprom_len; /* Maximum module EEPROM transaction length. */
 	struct mutex line_cards_lock; /* Protects line cards. */
-	struct mlxsw_env_line_card *line_cards[];
+	struct mlxsw_env_line_card *line_cards[] __counted_by(num_of_slots);
 };
 
 static bool __mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env,
-- 
2.34.1


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

* [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
  2023-09-29 18:07 ` [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards " Kees Cook
  2023-09-29 18:07 ` [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env " Kees Cook
@ 2023-09-29 18:07 ` Kees Cook
  2023-10-01 10:33   ` Ido Schimmel
  2023-10-03 23:17   ` Justin Stitt
  2023-09-29 18:07 ` [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info " Kees Cook
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_counter_pool.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
index ee59c79156e4..50e591420bd9 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
@@ -24,7 +24,7 @@ struct mlxsw_sp_counter_pool {
 	spinlock_t counter_pool_lock; /* Protects counter pool allocations */
 	atomic_t active_entries_count;
 	unsigned int sub_pools_count;
-	struct mlxsw_sp_counter_sub_pool sub_pools[];
+	struct mlxsw_sp_counter_sub_pool sub_pools[] __counted_by(sub_pools_count);
 };
 
 static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = {
-- 
2.34.1


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

* [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
                   ` (2 preceding siblings ...)
  2023-09-29 18:07 ` [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool " Kees Cook
@ 2023-09-29 18:07 ` Kees Cook
  2023-10-01 10:34   ` Ido Schimmel
  2023-10-03 23:12   ` Justin Stitt
  2023-09-29 18:07 ` [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span " Kees Cook
  2023-10-02 18:40 ` [PATCH 0/5] mlxsw: Annotate structs " patchwork-bot+netdevbpf
  5 siblings, 2 replies; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_nexthop_group_info.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index debd2c466f11..82a95125d9ca 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -3107,7 +3107,7 @@ struct mlxsw_sp_nexthop_group_info {
 	   gateway:1, /* routes using the group use a gateway */
 	   is_resilient:1;
 	struct list_head list; /* member in nh_res_grp_list */
-	struct mlxsw_sp_nexthop nexthops[];
+	struct mlxsw_sp_nexthop nexthops[] __counted_by(count);
 };
 
 static struct mlxsw_sp_rif *
-- 
2.34.1


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

* [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
                   ` (3 preceding siblings ...)
  2023-09-29 18:07 ` [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info " Kees Cook
@ 2023-09-29 18:07 ` Kees Cook
  2023-10-01 10:35   ` Ido Schimmel
  2023-10-03 23:06   ` Justin Stitt
  2023-10-02 18:40 ` [PATCH 0/5] mlxsw: Annotate structs " patchwork-bot+netdevbpf
  5 siblings, 2 replies; 15+ messages in thread
From: Kees Cook @ 2023-09-29 18:07 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Kees Cook, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_span.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
index b3472fb94617..af50ff9e5f26 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
@@ -31,7 +31,7 @@ struct mlxsw_sp_span {
 	refcount_t policer_id_base_ref_count;
 	atomic_t active_entries_count;
 	int entries_count;
-	struct mlxsw_sp_span_entry entries[];
+	struct mlxsw_sp_span_entry entries[] __counted_by(entries_count);
 };
 
 struct mlxsw_sp_span_analyzed_port {
-- 
2.34.1


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

* Re: [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards with __counted_by
  2023-09-29 18:07 ` [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards " Kees Cook
@ 2023-10-01 10:32   ` Ido Schimmel
  0 siblings, 0 replies; 15+ messages in thread
From: Ido Schimmel @ 2023-10-01 10:32 UTC (permalink / raw)
  To: Kees Cook
  Cc: Petr Machata, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, Gustavo A. R. Silva, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:07:40AM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct mlxsw_linecards.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env with __counted_by
  2023-09-29 18:07 ` [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env " Kees Cook
@ 2023-10-01 10:33   ` Ido Schimmel
  0 siblings, 0 replies; 15+ messages in thread
From: Ido Schimmel @ 2023-10-01 10:33 UTC (permalink / raw)
  To: Kees Cook
  Cc: Petr Machata, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, Gustavo A. R. Silva, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:07:41AM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct mlxsw_env.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by
  2023-09-29 18:07 ` [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool " Kees Cook
@ 2023-10-01 10:33   ` Ido Schimmel
  2023-10-03 23:17   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Ido Schimmel @ 2023-10-01 10:33 UTC (permalink / raw)
  To: Kees Cook
  Cc: Petr Machata, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, Gustavo A. R. Silva, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:07:42AM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_counter_pool.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info with __counted_by
  2023-09-29 18:07 ` [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info " Kees Cook
@ 2023-10-01 10:34   ` Ido Schimmel
  2023-10-03 23:12   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Ido Schimmel @ 2023-10-01 10:34 UTC (permalink / raw)
  To: Kees Cook
  Cc: Petr Machata, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, Gustavo A. R. Silva, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:07:43AM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_nexthop_group_info.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

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

* Re: [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by
  2023-09-29 18:07 ` [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span " Kees Cook
@ 2023-10-01 10:35   ` Ido Schimmel
  2023-10-03 23:06   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Ido Schimmel @ 2023-10-01 10:35 UTC (permalink / raw)
  To: Kees Cook
  Cc: Petr Machata, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, Gustavo A. R. Silva, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:07:44AM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_span.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

Thanks for taking care of that

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

* Re: [PATCH 0/5] mlxsw: Annotate structs with __counted_by
  2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
                   ` (4 preceding siblings ...)
  2023-09-29 18:07 ` [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span " Kees Cook
@ 2023-10-02 18:40 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 15+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-02 18:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: idosch, petrm, davem, edumazet, kuba, pabeni, gustavoars, nathan,
	ndesaulniers, trix, linux-kernel, netdev, linux-hardening, llvm

Hello:

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

On Fri, 29 Sep 2023 11:07:39 -0700 you wrote:
> Hi,
> 
> This annotates several mlxsw structures with the coming __counted_by attribute
> for bounds checking of flexible arrays at run-time. For more details, see
> commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").
> 
> Thanks!
> 
> [...]

Here is the summary with links:
  - [1/5] mlxsw: Annotate struct mlxsw_linecards with __counted_by
    https://git.kernel.org/netdev/net-next/c/0b7ed8183375
  - [2/5] mlxsw: core: Annotate struct mlxsw_env with __counted_by
    https://git.kernel.org/netdev/net-next/c/c63da7d62893
  - [3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by
    https://git.kernel.org/netdev/net-next/c/f7ebae83768f
  - [4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info with __counted_by
    https://git.kernel.org/netdev/net-next/c/4d3a42ec5cff
  - [5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by
    https://git.kernel.org/netdev/net-next/c/18cee9da32cd

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

* Re: [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span with __counted_by
  2023-09-29 18:07 ` [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span " Kees Cook
  2023-10-01 10:35   ` Ido Schimmel
@ 2023-10-03 23:06   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Justin Stitt @ 2023-10-03 23:06 UTC (permalink / raw)
  To: Kees Cook
  Cc: Ido Schimmel, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:08 AM Kees Cook <keescook@chromium.org> wrote:
>
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_span.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---

Great patch!

Crucially, span->entries_count is assigned before any flexible array
accesses.

        span->entries_count = entries_count;
        ...
        for (i = 0; i < mlxsw_sp->span->entries_count; i++)
                mlxsw_sp->span->entries[i].id = i;


Reviewed-by: Justin Stitt <justinstitt@google.com>

>  drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
> index b3472fb94617..af50ff9e5f26 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
> @@ -31,7 +31,7 @@ struct mlxsw_sp_span {
>         refcount_t policer_id_base_ref_count;
>         atomic_t active_entries_count;
>         int entries_count;
> -       struct mlxsw_sp_span_entry entries[];
> +       struct mlxsw_sp_span_entry entries[] __counted_by(entries_count);
>  };
>
>  struct mlxsw_sp_span_analyzed_port {
> --
> 2.34.1
>
>
Thanks
Justin

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

* Re: [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info with __counted_by
  2023-09-29 18:07 ` [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info " Kees Cook
  2023-10-01 10:34   ` Ido Schimmel
@ 2023-10-03 23:12   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Justin Stitt @ 2023-10-03 23:12 UTC (permalink / raw)
  To: Kees Cook
  Cc: Ido Schimmel, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:08 AM Kees Cook <keescook@chromium.org> wrote:
>
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_nexthop_group_info.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---

Reviewed-by: Justin Stitt <justinstitt@google.com>

>  drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> index debd2c466f11..82a95125d9ca 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> @@ -3107,7 +3107,7 @@ struct mlxsw_sp_nexthop_group_info {
>            gateway:1, /* routes using the group use a gateway */
>            is_resilient:1;
>         struct list_head list; /* member in nh_res_grp_list */
> -       struct mlxsw_sp_nexthop nexthops[];
> +       struct mlxsw_sp_nexthop nexthops[] __counted_by(count);
>  };
>
>  static struct mlxsw_sp_rif *
> --
> 2.34.1
>
>
Thanks
Justin

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

* Re: [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by
  2023-09-29 18:07 ` [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool " Kees Cook
  2023-10-01 10:33   ` Ido Schimmel
@ 2023-10-03 23:17   ` Justin Stitt
  1 sibling, 0 replies; 15+ messages in thread
From: Justin Stitt @ 2023-10-03 23:17 UTC (permalink / raw)
  To: Kees Cook
  Cc: Ido Schimmel, Petr Machata, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

On Fri, Sep 29, 2023 at 11:08 AM Kees Cook <keescook@chromium.org> wrote:
>
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct mlxsw_sp_counter_pool.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
> index ee59c79156e4..50e591420bd9 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
> @@ -24,7 +24,7 @@ struct mlxsw_sp_counter_pool {
>         spinlock_t counter_pool_lock; /* Protects counter pool allocations */
>         atomic_t active_entries_count;
>         unsigned int sub_pools_count;
> -       struct mlxsw_sp_counter_sub_pool sub_pools[];
> +       struct mlxsw_sp_counter_sub_pool sub_pools[] __counted_by(sub_pools_count);
>  };
>
>  static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = {
> --
> 2.34.1
>
>
Thanks
Justin

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

end of thread, other threads:[~2023-10-03 23:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 18:07 [PATCH 0/5] mlxsw: Annotate structs with __counted_by Kees Cook
2023-09-29 18:07 ` [PATCH 1/5] mlxsw: Annotate struct mlxsw_linecards " Kees Cook
2023-10-01 10:32   ` Ido Schimmel
2023-09-29 18:07 ` [PATCH 2/5] mlxsw: core: Annotate struct mlxsw_env " Kees Cook
2023-10-01 10:33   ` Ido Schimmel
2023-09-29 18:07 ` [PATCH 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool " Kees Cook
2023-10-01 10:33   ` Ido Schimmel
2023-10-03 23:17   ` Justin Stitt
2023-09-29 18:07 ` [PATCH 4/5] mlxsw: spectrum_router: Annotate struct mlxsw_sp_nexthop_group_info " Kees Cook
2023-10-01 10:34   ` Ido Schimmel
2023-10-03 23:12   ` Justin Stitt
2023-09-29 18:07 ` [PATCH 5/5] mlxsw: spectrum_span: Annotate struct mlxsw_sp_span " Kees Cook
2023-10-01 10:35   ` Ido Schimmel
2023-10-03 23:06   ` Justin Stitt
2023-10-02 18:40 ` [PATCH 0/5] mlxsw: Annotate structs " 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).