]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
idpf: fix null-ptr-deref in idpf_features_check
authorPavan Kumar Linga <pavan.kumar.linga@intel.com>
Fri, 11 Apr 2025 16:00:35 +0000 (09:00 -0700)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 19 May 2025 15:38:22 +0000 (08:38 -0700)
idpf_features_check is used to validate the TX packet. skb header
length is compared with the hardware supported value received from
the device control plane. The value is stored in the adapter structure
and to access it, vport pointer is used. During reset all the vports
are released and the vport pointer that the netdev private structure
points to is NULL.

To avoid null-ptr-deref, store the max header length value in netdev
private structure. This also helps to cache the value and avoid
accessing adapter pointer in hot path.

BUG: kernel NULL pointer dereference, address: 0000000000000068
...
RIP: 0010:idpf_features_check+0x6d/0xe0 [idpf]
Call Trace:
 <TASK>
 ? __die+0x23/0x70
 ? page_fault_oops+0x154/0x520
 ? exc_page_fault+0x76/0x190
 ? asm_exc_page_fault+0x26/0x30
 ? idpf_features_check+0x6d/0xe0 [idpf]
 netif_skb_features+0x88/0x310
 validate_xmit_skb+0x2a/0x2b0
 validate_xmit_skb_list+0x4c/0x70
 sch_direct_xmit+0x19d/0x3a0
 __dev_queue_xmit+0xb74/0xe70
 ...

Fixes: a251eee62133 ("idpf: add SRIOV support and other ndo_ops")
Reviewed-by: Madhu Chititm <madhu.chittim@intel.com>
Signed-off-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Samuel Salin <Samuel.salin@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/idpf/idpf.h
drivers/net/ethernet/intel/idpf/idpf_lib.c

index aef0e9775a33058f22049dd21470639b034f991f..70dbf80f3bb75b376e4a5768b7f978be9c8e00fa 100644 (file)
@@ -143,6 +143,7 @@ enum idpf_vport_state {
  * @vport_id: Vport identifier
  * @link_speed_mbps: Link speed in mbps
  * @vport_idx: Relative vport index
+ * @max_tx_hdr_size: Max header length hardware can support
  * @state: See enum idpf_vport_state
  * @netstats: Packet and byte stats
  * @stats_lock: Lock to protect stats update
@@ -153,6 +154,7 @@ struct idpf_netdev_priv {
        u32 vport_id;
        u32 link_speed_mbps;
        u16 vport_idx;
+       u16 max_tx_hdr_size;
        enum idpf_vport_state state;
        struct rtnl_link_stats64 netstats;
        spinlock_t stats_lock;
index 82f09b4030bce23bb39a49e29bcfe9eb98a10b26..3a033ce19cda23ce88590a619b18bb3a125a3faf 100644 (file)
@@ -723,6 +723,7 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)
                np->vport = vport;
                np->vport_idx = vport->idx;
                np->vport_id = vport->vport_id;
+               np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter);
                vport->netdev = netdev;
 
                return idpf_init_mac_addr(vport, netdev);
@@ -740,6 +741,7 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)
        np->adapter = adapter;
        np->vport_idx = vport->idx;
        np->vport_id = vport->vport_id;
+       np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter);
 
        spin_lock_init(&np->stats_lock);
 
@@ -2203,8 +2205,8 @@ static netdev_features_t idpf_features_check(struct sk_buff *skb,
                                             struct net_device *netdev,
                                             netdev_features_t features)
 {
-       struct idpf_vport *vport = idpf_netdev_to_vport(netdev);
-       struct idpf_adapter *adapter = vport->adapter;
+       struct idpf_netdev_priv *np = netdev_priv(netdev);
+       u16 max_tx_hdr_size = np->max_tx_hdr_size;
        size_t len;
 
        /* No point in doing any of this if neither checksum nor GSO are
@@ -2227,7 +2229,7 @@ static netdev_features_t idpf_features_check(struct sk_buff *skb,
                goto unsupported;
 
        len = skb_network_header_len(skb);
-       if (unlikely(len > idpf_get_max_tx_hdr_size(adapter)))
+       if (unlikely(len > max_tx_hdr_size))
                goto unsupported;
 
        if (!skb->encapsulation)
@@ -2240,7 +2242,7 @@ static netdev_features_t idpf_features_check(struct sk_buff *skb,
 
        /* IPLEN can support at most 127 dwords */
        len = skb_inner_network_header_len(skb);
-       if (unlikely(len > idpf_get_max_tx_hdr_size(adapter)))
+       if (unlikely(len > max_tx_hdr_size))
                goto unsupported;
 
        /* No need to validate L4LEN as TCP is the only protocol with a