All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] sfc: check for NULL efx->ptp_data in efx_ptp_event
@ 2014-02-24 19:39 Edward Cree
  2014-02-24 23:40 ` Ben Hutchings
  0 siblings, 1 reply; 2+ messages in thread
From: Edward Cree @ 2014-02-24 19:39 UTC (permalink / raw)
  To: netdev; +Cc: Shradha Shah

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.

Signed-off-by: Edward Cree <ecree@solarflare.com>
---
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.

--- linux-3.13/drivers/net/ethernet/sfc/ptp.c.orig	2014-01-20
02:40:07.000000000 +0000
+++ linux-3.13/drivers/net/ethernet/sfc/ptp.c	2014-02-24
17:46:31.753497000 +0000
@@ -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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net] sfc: check for NULL efx->ptp_data in efx_ptp_event
  2014-02-24 19:39 [PATCH net] sfc: check for NULL efx->ptp_data in efx_ptp_event Edward Cree
@ 2014-02-24 23:40 ` Ben Hutchings
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Hutchings @ 2014-02-24 23:40 UTC (permalink / raw)
  To: Edward Cree; +Cc: netdev, Shradha Shah

[-- Attachment #1: Type: text/plain, Size: 1790 bytes --]

On Mon, 2014-02-24 at 19:39 +0000, Edward Cree wrote:
> 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.
> 
> Signed-off-by: Edward Cree <ecree@solarflare.com>
> ---
> 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.

Good thinking.

> --- linux-3.13/drivers/net/ethernet/sfc/ptp.c.orig	2014-01-20
> 02:40:07.000000000 +0000
> +++ linux-3.13/drivers/net/ethernet/sfc/ptp.c	2014-02-24
> 17:46:31.753497000 +0000

This patch has been word-wrapped and can't be applied; see
Documentation/email-clients.txt

Ben.

> @@ -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;
> 

-- 
Ben Hutchings
Beware of bugs in the above code;
I have only proved it correct, not tried it. - Donald Knuth

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-24 23:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-24 19:39 [PATCH net] sfc: check for NULL efx->ptp_data in efx_ptp_event Edward Cree
2014-02-24 23:40 ` Ben Hutchings

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.