mirror-linux/drivers/net
Vinicius Costa Gomes 84523aeeea igc: Fix race condition in PTP tx code
commit 9c50e2b150 upstream.

Currently, the igc driver supports timestamping only one tx packet at a
time. During the transmission flow, the skb that requires hardware
timestamping is saved in adapter->ptp_tx_skb. Once hardware has the
timestamp, an interrupt is delivered, and adapter->ptp_tx_work is
scheduled. In igc_ptp_tx_work(), we read the timestamp register, update
adapter->ptp_tx_skb, and notify the network stack.

While the thread executing the transmission flow (the user process
running in kernel mode) and the thread executing ptp_tx_work don't
access adapter->ptp_tx_skb concurrently, there are two other places
where adapter->ptp_tx_skb is accessed: igc_ptp_tx_hang() and
igc_ptp_suspend().

igc_ptp_tx_hang() is executed by the adapter->watchdog_task worker
thread which runs periodically so it is possible we have two threads
accessing ptp_tx_skb at the same time. Consider the following scenario:
right after __IGC_PTP_TX_IN_PROGRESS is set in igc_xmit_frame_ring(),
igc_ptp_tx_hang() is executed. Since adapter->ptp_tx_start hasn't been
written yet, this is considered a timeout and adapter->ptp_tx_skb is
cleaned up.

This patch fixes the issue described above by adding the ptp_tx_lock to
protect access to ptp_tx_skb and ptp_tx_start fields from igc_adapter.
Since igc_xmit_frame_ring() called in atomic context by the networking
stack, ptp_tx_lock is defined as a spinlock, and the irq safe variants
of lock/unlock are used.

With the introduction of the ptp_tx_lock, the __IGC_PTP_TX_IN_PROGRESS
flag doesn't provide much of a use anymore so this patch gets rid of it.

Fixes: 2c344ae245 ("igc: Add support for TX timestamping")
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de>
Tested-by: Naama Meir <naamax.meir@linux.intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-25 12:03:03 +02:00
..
appletalk
arcnet net: arcnet: Do not call kfree_skb() under local_irq_disable() 2023-09-13 09:42:35 +02:00
bonding
caif
can can: sun4i_can: Only show Kconfig if ARCH_SUNXI is set 2023-10-19 23:08:52 +02:00
dsa net: dsa: qca8k: fix potential MDIO bus conflict when accessing internal PHYs via management frames 2023-10-19 23:08:52 +02:00
ethernet igc: Fix race condition in PTP tx code 2023-10-25 12:03:03 +02:00
fddi
fjes
hamradio
hippi
hyperv
ieee802154 ieee802154: ca8210: Fix a potential UAF in ca8210_probe 2023-10-19 23:08:53 +02:00
ipa
ipvlan
mctp
mdio
netdevsim
pcs
phy net: phy: mscc: macsec: reject PN update requests 2023-10-19 23:08:53 +02:00
plip
ppp
pse-pd
slip
team team: fix null-ptr-deref when team device type is changed 2023-10-06 14:56:41 +02:00
usb net: usb: dm9601: fix uninitialized variable use in dm9601_mdio_read 2023-10-19 23:08:54 +02:00
vmxnet3
vxlan neighbour: annotate lockless accesses to n->nud_state 2023-10-10 22:00:42 +02:00
wan drivers/net: process the result of hdlc_open() and add call of hdlc_close() in uhdlc_close() 2023-10-10 22:00:40 +02:00
wireguard
wireless wifi: mt76: mt76x02: fix MT76x0 external LNA gain handling 2023-10-10 22:00:40 +02:00
wwan
xen-netback xen-netback: use default TX queue size for vifs 2023-10-19 23:08:53 +02:00
Kconfig
LICENSE.SRC
Makefile
Space.c
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c net: macsec: indicate next pn update when offloading 2023-10-19 23:08:53 +02:00
macvlan.c
macvtap.c
mdio.c
mhi_net.c
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
sungem_phy.c
tap.c
thunderbolt.c net: thunderbolt: Fix TCPv6 GSO checksum calculation 2023-10-06 14:57:04 +02:00
tun.c
veth.c veth: Fixing transmit return status for dropped packets 2023-09-19 12:28:02 +02:00
virtio_net.c
vrf.c vrf: Fix lockdep splat in output path 2023-10-10 22:00:46 +02:00
vsockmon.c
xen-netfront.c