Skip to contentSkip to conversation

sfc: check for NULL efx->ptp_data in efx_ptp_event

PATCH In review Edward Cree 3 participants 3 messages Feb 25, 2014 – Feb 26, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sfc: check for NULL efx->ptp_data in efx_ptp_event

If we receive a PTP event from the NIC when we haven't set up PTP state in the driver, we attempt to read through a NULL pointer efx->ptp_data, triggering a panic.

---
v2: resent using alpine, because Thunderbird mangled v1

While this shouldn't happen with existing released firmware, future sfn7322f firmware is planned to enable PPS irrespective of whether timestamping (and thus PTP) is enabled. We are considering workarounds, but this defensive patch seemed like a good idea anyway in case the firmware gets in a muddle.
Also, in principle this shouldn't happen on 3.14+ kernels as the driver should always set up PTP state at probe time (though there might still be a race against the firmware sending its first PPS), however 3.12 and 3.13 both supported EF10 but not PTP-on-EF10 and thus they never set up the PTP state; hence this fix should also be backported to those series.

drivers/net/ethernet/sfc/ptp.c renamed from drivers/net/ethernet/sfc/ptp.c.orig +7 -0
@@ -1360,6 +1360,13 @@ void efx_ptp_event(struct efx_nic *efx,
 	struct efx_ptp_data *ptp = efx->ptp_data;
 	int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE);
 
+	if (!ptp) {
+		if (net_ratelimit())
+			netif_warn(efx, drv, efx->net_dev,
+				   "Received PTP event but PTP not set up\n");
+		return;
+	}
+
 	if (!ptp->enabled)
 		return;
 
Acked-by on v2 1/1
#1 lore raw
Quoted 5 lines · Edward Cree

If we receive a PTP event from the NIC when we haven't set up PTP state in the driver, we attempt to read through a NULL pointer efx->ptp_data, triggering a panic.

Quoted 31 lines

---
v2: resent using alpine, because Thunderbird mangled v1

While this shouldn't happen with existing released firmware, future sfn7322f firmware is planned to enable PPS irrespective of whether timestamping (and thus PTP) is enabled. We are considering workarounds, but this defensive patch seemed like a good idea anyway in case the firmware gets in a muddle.
Also, in principle this shouldn't happen on 3.14+ kernels as the driver should always set up PTP state at probe time (though there might still be a race against the firmware sending its first PPS), however 3.12 and 3.13 both supported EF10 but not PTP-on-EF10 and thus they never set up the PTP state; hence this fix should also be backported to those series.

drivers/net/ethernet/sfc/ptp.c renamed from drivers/net/ethernet/sfc/ptp.c.orig +7 -0
@@ -1360,6 +1360,13 @@ void efx_ptp_event(struct efx_nic *efx,
 	struct efx_ptp_data *ptp = efx->ptp_data;
 	int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE);
 
+	if (!ptp) {
+		if (net_ratelimit())
+			netif_warn(efx, drv, efx->net_dev,
+				   "Received PTP event but PTP not set up\n");
+		return;
+	}
+
 	if (!ptp->enabled)
 		return;
 
maintainer
#2 lore raw
In reply to Edward Cree

From: Edward Cree <[email protected]>
Date: Tue, 25 Feb 2014 13:17:59 +0000

Quoted 8 lines

If we receive a PTP event from the NIC when we haven't set up PTP state in the driver, we attempt to read through a NULL pointer efx->ptp_data, triggering a panic.

---
v2: resent using alpine, because Thunderbird mangled v1

Quoted 10 lines

While this shouldn't happen with existing released firmware, future sfn7322f firmware is planned to enable PPS irrespective of whether timestamping (and thus PTP) is enabled. We are considering workarounds, but this defensive patch seemed like a good idea anyway in case the firmware gets in a muddle.
Also, in principle this shouldn't happen on 3.14+ kernels as the driver should always set up PTP state at probe time (though there might still be a race against the firmware sending its first PPS), however 3.12 and 3.13 both supported EF10 but not PTP-on-EF10 and thus they never set up the PTP state; hence this fix should also be backported to those series.

Applied and queued up for -stable, thanks.