Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit babd6134 authored by Roi Dayan's avatar Roi Dayan Committed by David S. Miller
Browse files

net/mlx5: Fix flow counter bulk command out mailbox allocation



The FW command output length should be only the length of struct
mlx5_cmd_fc_bulk out field. Failing to do so will cause the memcpy
call which is invoked later in the driver to write over wrong memory
address and corrupt kernel memory which results in random crashes.

This bug was found using the kernel address sanitizer (kasan).

Fixes: a351a1b0 ('net/mlx5: Introduce bulk reading of flow counters')
Signed-off-by: default avatarRoi Dayan <roid@mellanox.com>
Signed-off-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7ac32731
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -425,11 +425,11 @@ struct mlx5_cmd_fc_bulk *
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num)
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num)
{
{
	struct mlx5_cmd_fc_bulk *b;
	struct mlx5_cmd_fc_bulk *b;
	int outlen = sizeof(*b) +
	int outlen =
		MLX5_ST_SZ_BYTES(query_flow_counter_out) +
		MLX5_ST_SZ_BYTES(query_flow_counter_out) +
		MLX5_ST_SZ_BYTES(traffic_counter) * num;
		MLX5_ST_SZ_BYTES(traffic_counter) * num;


	b = kzalloc(outlen, GFP_KERNEL);
	b = kzalloc(sizeof(*b) + outlen, GFP_KERNEL);
	if (!b)
	if (!b)
		return NULL;
		return NULL;