]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
net/mlx5e: fix double free of encap_header
authorVlad Buslov <vladbu@nvidia.com>
Tue, 21 Nov 2023 13:15:30 +0000 (14:15 +0100)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 14 Dec 2023 01:22:15 +0000 (17:22 -0800)
commit8e13cd737cb4fbbb37d448e7e5228a99ae08fdc1
tree07d163d2ee242b5359a80bcb8b2f5dc0a39e85a0
parent5d089684dc434a31e08d32f0530066d0025c52e4
net/mlx5e: fix double free of encap_header

Cited commit introduced potential double free since encap_header can be
destroyed twice in some cases - once by error cleanup sequence in
mlx5e_tc_tun_{create|update}_header_ipv{4|6}(), once by generic
mlx5e_encap_put() that user calls as a result of getting an error from
tunnel create|update. At the same time the point where e->encap_header is
assigned can't be delayed because the function can still return non-error
code 0 as a result of checking for NUD_VALID flag, which will cause
neighbor update to dereference NULL encap_header.

Fix the issue by:

- Nulling local encap_header variables in
mlx5e_tc_tun_{create|update}_header_ipv{4|6}() to make kfree(encap_header)
call in error cleanup sequence noop after that point.

- Assigning reformat_params.data from e->encap_header instead of local
variable encap_header that was set to NULL pointer by previous step. Also
assign reformat_params.size from e->encap_size for uniformity and in order
to make the code less error-prone in the future.

Fixes: d589e785baf5 ("net/mlx5e: Allow concurrent creation of encap entries")
Reported-by: Dust Li <dust.li@linux.alibaba.com>
Reported-by: Cruz Zhao <cruzzhao@linux.alibaba.com>
Reported-by: Tianchen Ding <dtcccc@linux.alibaba.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c