Message ID | 07477254-e179-43e2-b1b3-3b9db4674195@stanley.mountain (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | [v3,net] net/mlx5: DR, prevent potential error pointer dereference | expand |
On 04/12/2024 14:06, Dan Carpenter wrote: > The dr_domain_add_vport_cap() function generally returns NULL on error > but sometimes we want it to return ERR_PTR(-EBUSY) so the caller can > retry. The problem here is that "ret" can be either -EBUSY or -ENOMEM > and if it's and -ENOMEM then the error pointer is propogated back and > eventually dereferenced in dr_ste_v0_build_src_gvmi_qpn_tag(). > > Fixes: 11a45def2e19 ("net/mlx5: DR, Add support for SF vports") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > v2: fix typo in commit message > v3: better style > > .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c > index 3d74109f8230..49f22cad92bf 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c > @@ -297,7 +297,9 @@ dr_domain_add_vport_cap(struct mlx5dr_domain *dmn, u16 vport) > if (ret) { > mlx5dr_dbg(dmn, "Couldn't insert new vport into xarray (%d)\n", ret); > kvfree(vport_caps); > - return ERR_PTR(ret); > + if (ret == -EBUSY) > + return ERR_PTR(-EBUSY); > + return NULL; > } > > return vport_caps; Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Thanks.
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c index 3d74109f8230..49f22cad92bf 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c @@ -297,7 +297,9 @@ dr_domain_add_vport_cap(struct mlx5dr_domain *dmn, u16 vport) if (ret) { mlx5dr_dbg(dmn, "Couldn't insert new vport into xarray (%d)\n", ret); kvfree(vport_caps); - return ERR_PTR(ret); + if (ret == -EBUSY) + return ERR_PTR(-EBUSY); + return NULL; } return vport_caps;
The dr_domain_add_vport_cap() function generally returns NULL on error but sometimes we want it to return ERR_PTR(-EBUSY) so the caller can retry. The problem here is that "ret" can be either -EBUSY or -ENOMEM and if it's and -ENOMEM then the error pointer is propogated back and eventually dereferenced in dr_ste_v0_build_src_gvmi_qpn_tag(). Fixes: 11a45def2e19 ("net/mlx5: DR, Add support for SF vports") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> --- v2: fix typo in commit message v3: better style .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)