Skip to content

Commit e577516

Browse files
idoschdavem330
authored andcommitted
mlxsw: Fix use-after-free bug in mlxsw_sx_port_xmit
Store the length of the skb before transmitting it and use it for stats instead of skb->len, since skb might have been freed already. This issue was discovered using the Kernel Address sanitizer (KASan). Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3bfcd34 commit e577516

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/net/ethernet/mellanox/mlxsw/switchx2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static netdev_tx_t mlxsw_sx_port_xmit(struct sk_buff *skb,
300300
.local_port = mlxsw_sx_port->local_port,
301301
.is_emad = false,
302302
};
303+
u64 len;
303304
int err;
304305

305306
if (mlxsw_core_skb_transmit_busy(mlxsw_sx, &tx_info))
@@ -316,6 +317,7 @@ static netdev_tx_t mlxsw_sx_port_xmit(struct sk_buff *skb,
316317
}
317318
}
318319
mlxsw_sx_txhdr_construct(skb, &tx_info);
320+
len = skb->len;
319321
/* Due to a race we might fail here because of a full queue. In that
320322
* unlikely case we simply drop the packet.
321323
*/
@@ -325,7 +327,7 @@ static netdev_tx_t mlxsw_sx_port_xmit(struct sk_buff *skb,
325327
pcpu_stats = this_cpu_ptr(mlxsw_sx_port->pcpu_stats);
326328
u64_stats_update_begin(&pcpu_stats->syncp);
327329
pcpu_stats->tx_packets++;
328-
pcpu_stats->tx_bytes += skb->len;
330+
pcpu_stats->tx_bytes += len;
329331
u64_stats_update_end(&pcpu_stats->syncp);
330332
} else {
331333
this_cpu_inc(mlxsw_sx_port->pcpu_stats->tx_dropped);

0 commit comments

Comments
 (0)