net/mlx5: Annotate struct mlx5_flow_handle with __counted_by
Subsystems (4)
PATCH 1/1 net/mlx5: Annotate struct mlx5_flow_handle with __counted_by
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 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 mlx5_flow_handle.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1 -1
@@ -181,7 +181,7 @@ struct mlx5_flow_rule {struct mlx5_flow_handle {int num_rules; -struct mlx5_flow_rule *rule[]; + struct mlx5_flow_rule *rule[] __counted_by(num_rules); };/* Type of children is mlx5_flow_group */
Signature · 1 line
2.34.1
Quoted 28 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structmlx5_flow_handle.Cc Saeed Mahameed <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +0
-0
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h struct mlx5_flow_rule { · line 185
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1
-1@@ -181,7 +181,7 @@ struct mlx5_flow_rule {struct mlx5_flow_handle {int num_rules; -struct mlx5_flow_rule *rule[]; + struct mlx5_flow_rule *rule[] __counted_by(num_rules); };
Great patch!
handle->num_rules is properly assigned to before handle->rule has any accesses.
handle = alloc_handle((dest_num) ? dest_num : 1);
then
static struct mlx5_flow_handle *alloc_handle(int num_rules) {
...
handle->num_rules = num_rules;then
handle->rule[i] = rule;
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +0
-1/* Type of children is mlx5_flow_group */ --2.34.1
Thanks
Justin
Quoted 8 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structmlx5_flow_handle.
Quoted 10 lines
Cc Saeed Mahameed <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks
--
Gustavo
Quoted 17 lines
--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1
-1@@ -181,7 +181,7 @@ struct mlx5_flow_rule {struct mlx5_flow_handle {int num_rules; -struct mlx5_flow_rule *rule[]; + struct mlx5_flow_rule *rule[] __counted_by(num_rules); };/* Type of children is mlx5_flow_group */
Quoted 18 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structmlx5_flow_handle.Cc Saeed Mahameed <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 4 lines
--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks,
Saeed Mahameed
AppliedQuoted 8 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structmlx5_flow_handle.
Quoted 10 lines
Cc Saeed Mahameed <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
applied to net-next-mlx5.