mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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 <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3bfcd34764
commit
e577516b9d
1 changed files with 3 additions and 1 deletions
|
@ -300,6 +300,7 @@ static netdev_tx_t mlxsw_sx_port_xmit(struct sk_buff *skb,
|
||||||
.local_port = mlxsw_sx_port->local_port,
|
.local_port = mlxsw_sx_port->local_port,
|
||||||
.is_emad = false,
|
.is_emad = false,
|
||||||
};
|
};
|
||||||
|
u64 len;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (mlxsw_core_skb_transmit_busy(mlxsw_sx, &tx_info))
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mlxsw_sx_txhdr_construct(skb, &tx_info);
|
mlxsw_sx_txhdr_construct(skb, &tx_info);
|
||||||
|
len = skb->len;
|
||||||
/* Due to a race we might fail here because of a full queue. In that
|
/* Due to a race we might fail here because of a full queue. In that
|
||||||
* unlikely case we simply drop the packet.
|
* unlikely case we simply drop the packet.
|
||||||
*/
|
*/
|
||||||
|
@ -325,7 +327,7 @@ static netdev_tx_t mlxsw_sx_port_xmit(struct sk_buff *skb,
|
||||||
pcpu_stats = this_cpu_ptr(mlxsw_sx_port->pcpu_stats);
|
pcpu_stats = this_cpu_ptr(mlxsw_sx_port->pcpu_stats);
|
||||||
u64_stats_update_begin(&pcpu_stats->syncp);
|
u64_stats_update_begin(&pcpu_stats->syncp);
|
||||||
pcpu_stats->tx_packets++;
|
pcpu_stats->tx_packets++;
|
||||||
pcpu_stats->tx_bytes += skb->len;
|
pcpu_stats->tx_bytes += len;
|
||||||
u64_stats_update_end(&pcpu_stats->syncp);
|
u64_stats_update_end(&pcpu_stats->syncp);
|
||||||
} else {
|
} else {
|
||||||
this_cpu_inc(mlxsw_sx_port->pcpu_stats->tx_dropped);
|
this_cpu_inc(mlxsw_sx_port->pcpu_stats->tx_dropped);
|
||||||
|
|
Loading…
Add table
Reference in a new issue