net/mlx5e: Fix nullptr in mlx5e_tc_add_fdb_flow()
authorDima Chumak <dchumak@nvidia.com>
Mon, 26 Apr 2021 12:16:26 +0000 (15:16 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 19 May 2021 06:01:31 +0000 (23:01 -0700)
commitfe7738eb3ca3631a75844e790f6cb576c0fe7b00
tree6691b2141258b2b3d054baa5b37f5609e6b661da
parent82041634d96e87b41c600a673f10150d9f21f742
net/mlx5e: Fix nullptr in mlx5e_tc_add_fdb_flow()

The result of __dev_get_by_index() is not checked for NULL, which then
passed to mlx5e_attach_encap() and gets dereferenced.

Also, in case of a successful lookup, the net_device reference count is
not incremented, which may result in net_device pointer becoming invalid
at any time during mlx5e_attach_encap() execution.

Fix by using dev_get_by_index(), which does proper reference counting on
the net_device pointer. Also, handle nullptr return value when mirred
device is not found.

It's safe to call dev_put() on the mirred net_device pointer, right
after mlx5e_attach_encap() call, because it's not being saved/copied
down the call chain.

Fixes: 3c37745ec614 ("net/mlx5e: Properly deal with encap flows add/del under neigh update")
Addresses-Coverity: ("Dereference null return value")
Signed-off-by: Dima Chumak <dchumak@nvidia.com>
Reviewed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c