diff mbox series

net/mlx5e: Add missing check for xa_load

Message ID 20230904081210.23901-1-nichen@iscas.ac.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net/mlx5e: Add missing check for xa_load | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers success CCed 14 of 14 maintainers
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Chen Ni Sept. 4, 2023, 8:12 a.m. UTC
Add check for xa_load() in order to avoid NULL pointer
dereference.

Fixes: b7c9400cbc48 ("net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 .../net/ethernet/mellanox/mlx5/core/en_accel/macsec.c  | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Pavan Chebbi Sept. 4, 2023, 8:57 a.m. UTC | #1
On Mon, Sep 4, 2023 at 1:43 PM Chen Ni <nichen@iscas.ac.cn> wrote:
>
> Add check for xa_load() in order to avoid NULL pointer
> dereference.
>
> Fixes: b7c9400cbc48 ("net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>  .../net/ethernet/mellanox/mlx5/core/en_accel/macsec.c  | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> index c9c1db971652..d2467c0bc3c8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> @@ -1673,10 +1673,12 @@ void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
>
>         rcu_read_lock();
>         sc_xarray_element = xa_load(&macsec->sc_xarray, fs_id);
> -       rx_sc = sc_xarray_element->rx_sc;
> -       if (rx_sc) {
> -               dst_hold(&rx_sc->md_dst->dst);
> -               skb_dst_set(skb, &rx_sc->md_dst->dst);
> +       if (sc_xarray_element) {

While the check is good, IMO it is worthwhile to debug why the element
could be NULL. Is the issue xarray or the fs_id?
If you know already, then good idea to update the commit log.

> +               rx_sc = sc_xarray_element->rx_sc;
> +               if (rx_sc) {
> +                       dst_hold(&rx_sc->md_dst->dst);
> +                       skb_dst_set(skb, &rx_sc->md_dst->dst);
> +               }
>         }
>
>         rcu_read_unlock();
> --
> 2.25.1
>
>
Paolo Abeni Sept. 5, 2023, 8:33 a.m. UTC | #2
On Mon, 2023-09-04 at 08:12 +0000, Chen Ni wrote:
> Add check for xa_load() in order to avoid NULL pointer
> dereference.
> 
> Fixes: b7c9400cbc48 ("net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>  .../net/ethernet/mellanox/mlx5/core/en_accel/macsec.c  | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> index c9c1db971652..d2467c0bc3c8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
> @@ -1673,10 +1673,12 @@ void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
>  
>  	rcu_read_lock();
>  	sc_xarray_element = xa_load(&macsec->sc_xarray, fs_id);
> -	rx_sc = sc_xarray_element->rx_sc;
> -	if (rx_sc) {
> -		dst_hold(&rx_sc->md_dst->dst);
> -		skb_dst_set(skb, &rx_sc->md_dst->dst);
> +	if (sc_xarray_element) {
> +		rx_sc = sc_xarray_element->rx_sc;
> +		if (rx_sc) {
> +			dst_hold(&rx_sc->md_dst->dst);
> +			skb_dst_set(skb, &rx_sc->md_dst->dst);
> +		}
>  	}
>  
>  	rcu_read_unlock();

@Saeed: I assume this will first go through your tree and then we will
get back via a later PR, right?

In any case Pavan's comment looks reasonable to me, @Chen: please
address it.

Cheers,

Paolo
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
index c9c1db971652..d2467c0bc3c8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
@@ -1673,10 +1673,12 @@  void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
 
 	rcu_read_lock();
 	sc_xarray_element = xa_load(&macsec->sc_xarray, fs_id);
-	rx_sc = sc_xarray_element->rx_sc;
-	if (rx_sc) {
-		dst_hold(&rx_sc->md_dst->dst);
-		skb_dst_set(skb, &rx_sc->md_dst->dst);
+	if (sc_xarray_element) {
+		rx_sc = sc_xarray_element->rx_sc;
+		if (rx_sc) {
+			dst_hold(&rx_sc->md_dst->dst);
+			skb_dst_set(skb, &rx_sc->md_dst->dst);
+		}
 	}
 
 	rcu_read_unlock();