]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ice: fix NULL pointer dereference in ice_update_vsi_tx_ring_stats()
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Mon, 7 Mar 2022 17:47:39 +0000 (18:47 +0100)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Tue, 15 Mar 2022 20:36:13 +0000 (13:36 -0700)
It is possible to do NULL pointer dereference in routine that updates
Tx ring stats. Currently only stats and bytes are updated when ring
pointer is valid, but later on ring is accessed to propagate gathered Tx
stats onto VSI stats.

Change the existing logic to move to next ring when ring is NULL.

Fixes: 8015762f94a4 ("ice: split ice_ring onto Tx/Rx separate structs")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Acked-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_main.c

index 493942e910be0c1f26894addb630e5f7ab1d7edf..d4a7c39fd0786c5d6197dd360acd486a5a9810d9 100644 (file)
@@ -5962,8 +5962,9 @@ ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
                u64 pkts = 0, bytes = 0;
 
                ring = READ_ONCE(rings[i]);
-               if (ring)
-                       ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
+               if (!ring)
+                       continue;
+               ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
                vsi_stats->tx_packets += pkts;
                vsi_stats->tx_bytes += bytes;
                vsi->tx_restart += ring->tx_stats.restart_q;