Re: [PATCH] net/mlx5e: Add missing check for xa_load

From: Pavan Chebbi
Date: Mon Sep 04 2023 - 04:58:29 EST


On Mon, Sep 4, 2023 at 1:43 PM Chen Ni <nichen@xxxxxxxxxxx> 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@xxxxxxxxxxx>
> ---
> .../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
>
>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature