net: ptp: fix egregious supported flag checks
Subsystems (9)
v2 cover net: ptp: fix egregious supported flag checks
In preparation for adding .supported_extts_flags and .supported_perout_flags to the ptp_clock_info structure, fix a couple of places where drivers get existing flag gets grossly incorrect.
The igb driver claims 82580 supports strictly validating PTP_RISING_EDGE and PTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver to require that the request match both edges, as this is implied by the datasheet description.
The renesas driver also claims to support strict flag checking, but does not actually check the flags either. I do not have the data sheet for this device, so I do not know what edge it timestamps. For simplicity, just reject all requests with PTP_STRICT_FLAGS. This essentially prevents the PTP_EXTTS_REQUEST2 ioctl from working. Updating to correctly validate the flags will require someone who has the hardware to confirm the behavior.
The lan743x driver supports (and strictly validates) that the request is either PTP_RISING_EDGE or PTP_FALLING_EDGE but not both. However, it does not check the flags are one of the known valid flags. Thus, requests for PTP_EXT_OFF (and any future flag) will be accepted and misinterpreted. Add the appropriate check to reject unsupported PTP_EXT_OFF requests and future proof against new flags.
The broadcom PHY driver checks that PTP_PEROUT_PHASE is not set. This appears to be an attempt at rejecting unsupported flags. It is not robust against flag additions such as the PTP_PEROUT_ONE_SHOT, or anything added in the future. Fix this by instead checking against the negation of the supported PTP_PEROUT_DUTY_CYCLE instead.
The ptp_ocp driver supports PTP_PEROUT_PHASE and PTP_PEROUT_DUTY_CYCLE, but does not check unsupported flags. Add the appropriate check to ensure PTP_PEROUT_ONE_SHOT and any future flags are rejected as unsupported.
These are changes compile-tested, but I do not have hardware to validate the behavior.
There are a number of other drivers which enable periodic output or external timestamp requests, but which do not check flags at all. We could go through each of these drivers one-by-one and meticulously add a flag check. Instead, these drivers will be covered only by the upcoming .supported_extts_flags and .supported_perout_flags checks in a net-next series.
---
Changes in v2:
- Drop Raju Lakkaraju from Cc since his email appears to no longer deliver.
- Fix the igb 82580 check to allow disabling the pin without flags set.
- Link to v1: https://lore.kernel.org/r/20250310-jk-net-fixes-supported-extts-flags-v1-0-854ffb5f3a96@intel.com
---
Jacob Keller (5):
igb: reject invalid external timestamp requests for 82580-based HW
renesas: reject PTP_STRICT_FLAGS as unsupported
net: lan743x: reject unsupported external timestamp requests
broadcom: fix supported flag check in periodic output function
ptp: ocp: reject unsupported periodic output flags
drivers/net/ethernet/intel/igb/igb_ptp.c | 6 ++++++ drivers/net/ethernet/microchip/lan743x_ptp.c | 6 ++++++ drivers/net/ethernet/renesas/ravb_ptp.c | 3 +-- drivers/net/phy/bcm-phy-ptp.c | 3 ++- drivers/ptp/ptp_ocp.c | 4 ++++ 5 files changed, 19 insertions(+), 3 deletions(-)
---
base-commit: 992ee3ed6e9fdd0be83a7daa5ff738e3cf86047f
change-id: 20250310-jk-net-fixes-supported-extts-flags-e8434d8e2552
Best regards,
Signature · 1 line
Jacob Keller <[email protected]>
PATCH v2 1/5 igb: reject invalid external timestamp requests for 82580-based HW
The igb_ptp_feature_enable_82580 function correctly checks that unknown flags are not passed to the function. However, it does not actually check PTP_RISING_EDGE or PTP_FALLING_EDGE when configuring the external timestamp function.
The data sheet for the 82580 product says:
Upon a change in the input level of one of the SDP pins that was configured to detect Time stamp events using the TSSDP register, a time stamp of the system time is captured into one of the two auxiliary time stamp registers (AUXSTMPL/H0 or AUXSTMPL/H1).
For example to define timestamping of events in the AUXSTMPL0 and AUXSTMPH0 registers, Software should:
1. Set the TSSDP.AUX0_SDP_SEL field to select the SDP pin that detects the level change and set the TSSDP.AUX0_TS_SDP_EN bit to 1.
2. Set the TSAUXC.EN_TS0 bit to 1 to enable timestamping
The same paragraph is in the i350 and i354 data sheets.
The wording implies that the time stamps are captured at any level change. There does not appear to be any way to only timestamp one edge of the signal.
Reject requests which do not set both PTP_RISING_EDGE and PTP_FALLING_EDGE when operating under PTP_STRICT_FLAGS mode via PTP_EXTTS_REQUEST2.
---
Changes in v2:
- Fix the 82580 check to allow disabling the pin without flags set.
--- drivers/net/ethernet/intel/igb/igb_ptp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/igb/igb_ptp.c +6 -0
@@ -509,6 +509,12 @@ static int igb_ptp_feature_enable_82580(struct ptp_clock_info *ptp, PTP_STRICT_FLAGS))return -EOPNOTSUPP ; +/* Both the rising and falling edge are timestamped */ +if (rq->extts.flags &PTP_STRICT_FLAGS && + (rq->extts.flags &PTP_ENABLE_FEATURE ) && + (rq->extts.flags &PTP_EXTTS_EDGES ) !=PTP_EXTTS_EDGES ) +return -EOPNOTSUPP ; +if (on) { pin =ptp_find_pin (igb->ptp_clock,PTP_PF_EXTTS , rq->extts.index);
Signature · 1 line
2.48.1.397.gec9d649cc640
Re: [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW
Quoted 26 lines · Jacob Keller
The
igb_ptp_feature_enable_82580function correctly checks that unknown flags are not passed to the function. However, it does not actually checkPTP_RISING_EDGEorPTP_FALLING_EDGEwhen configuring the external timestamp function.The data sheet for the 82580 product says:
Upon a change in the input level of one of the SDP pins that was configured to detect Time stamp events using the TSSDP register, a time stamp of the system time is captured into one of the two auxiliary time stamp registers (AUXSTMPL/H0 or AUXSTMPL/H1).
For example to define timestamping of events in the AUXSTMPL0 and AUXSTMPH0 registers, Software should:
1. Set the TSSDP.AUX0_SDP_SEL field to select the SDP pin that detects the level change and set the TSSDP.AUX0_TS_SDP_EN bit to 1.
2. Set the TSAUXC.EN_TS0 bit to 1 to enable timestamping
The same paragraph is in the i350 and i354 data sheets.
The wording implies that the time stamps are captured at any level change. There does not appear to be any way to only timestamp one edge of the signal.
Quoted 6 lines
Reject requests which do not set both
PTP_RISING_EDGEandPTP_FALLING_EDGEwhen operating underPTP_STRICT_FLAGSmode viaPTP_EXTTS_REQUEST2.Fixes 38970eac41db ("igb: support EXTTS on 82580/i354/i350")Reviewed-by Michal Swiatkowski <[email protected]>Signed-off-by Jacob Keller <[email protected]>
PATCH v2 2/5 renesas: reject PTP_STRICT_FLAGS as unsupported
In reply to Jacob KellerThe ravb_ptp_extts() function checks the flags coming from the PTP_EXTTS_REQUEST ioctl, to ensure that future flags are not accepted on accident.
This was updated to 'honor' the PTP_STRICT_FLAGS in commit 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options."). However, the driver does not *actually* validate the flags.
I originally fixed this driver to reject future flags in commit 592025a03b34 ("renesas: reject unsupported external timestamp flags"). It is still unclear whether this hardware timestamps the rising, falling, or both edges of the input signal.
Accepting requests with PTP_STRICT_FLAGS is a bug, as this could lead to users mistakenly assuming a request with PTP_RISING_EDGE actually timestamps the rising edge only.
Reject requests with PTP_STRICT_FLAGS (and hence all PTP_EXTTS_REQUEST2 requests) until someone with access to the datasheet or hardware knowledge can confirm the timestamping behavior and update this driver.
--- drivers/net/ethernet/renesas/ravb_ptp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/renesas/ravb_ptp.c +1 -2
@@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,/* Reject requests with unsupported flags */ if (req->flags & ~(PTP_ENABLE_FEATURE |PTP_RISING_EDGE | -PTP_FALLING_EDGE | -PTP_STRICT_FLAGS )) +PTP_FALLING_EDGE ))return -EOPNOTSUPP ;if (req->index)
Signature · 1 line
2.48.1.397.gec9d649cc640
Re: [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
Hi Jacob,
Thanks for your work.
Quoted 17 lines · Jacob Keller
The
ravb_ptp_extts()function checks the flags coming from thePTP_EXTTS_REQUESTioctl, to ensure that future flags are not accepted on accident.This was updated to 'honor' the
PTP_STRICT_FLAGSin commit6138e687c7b6("ptp: Introduce strict checking of external time stamp options."). However, the driver does not *actually* validate the flags.I originally fixed this driver to reject future flags in commit
592025a03b34("renesas: reject unsupported external timestamp flags"). It is still unclear whether this hardware timestamps the rising, falling, or both edges of the input signal.Accepting requests with
PTP_STRICT_FLAGSis a bug, as this could lead to users mistakenly assuming a request withPTP_RISING_EDGEactually timestamps the rising edge only.
Quoted 6 lines
Reject requests with
PTP_STRICT_FLAGS(and hence allPTP_EXTTS_REQUEST2requests) until someone with access to the datasheet or hardware knowledge can confirm the timestamping behavior and update this driver.Fixes 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.")Signed-off-by Jacob Keller <[email protected]>
Quoted 22 lines
--- drivers/net/ethernet/renesas/ravb_ptp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/ethernet/renesas/ravb_ptp.c +1
-2@@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,/* Reject requests with unsupported flags */ if (req->flags & ~(PTP_ENABLE_FEATURE |PTP_RISING_EDGE | -PTP_FALLING_EDGE | -PTP_STRICT_FLAGS )) +PTP_FALLING_EDGE ))return -EOPNOTSUPP ;if (req->index)Signature · 2 lines
-- 2.48.1.397.gec9d649cc640
Signature · 2 lines
Kind Regards, Niklas Söderlund
Re: [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
In reply to Jacob KellerQuoted 17 lines · Jacob Keller
The
ravb_ptp_extts()function checks the flags coming from thePTP_EXTTS_REQUESTioctl, to ensure that future flags are not accepted on accident.This was updated to 'honor' the
PTP_STRICT_FLAGSin commit6138e687c7b6("ptp: Introduce strict checking of external time stamp options."). However, the driver does not *actually* validate the flags.I originally fixed this driver to reject future flags in commit
592025a03b34("renesas: reject unsupported external timestamp flags"). It is still unclear whether this hardware timestamps the rising, falling, or both edges of the input signal.Accepting requests with
PTP_STRICT_FLAGSis a bug, as this could lead to users mistakenly assuming a request withPTP_RISING_EDGEactually timestamps the rising edge only.
Quoted 6 lines
Reject requests with
PTP_STRICT_FLAGS(and hence allPTP_EXTTS_REQUEST2requests) until someone with access to the datasheet or hardware knowledge can confirm the timestamping behavior and update this driver.Fixes 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.")Signed-off-by Jacob Keller <[email protected]>
PATCH v2 3/5 net: lan743x: reject unsupported external timestamp requests
In reply to Jacob KellerThe lan743x_ptp_io_event_cap_en() function checks that the given request sets only one of PTP_RISING_EDGE or PTP_FALLING_EDGE, but not both.
However, this driver does not check whether other flags (such as PTP_EXT_OFF) are set, nor whether any future unrecognized flags are set.
Fix this by adding the appropriate check to the lan743x_ptp_io_extts() function.
--- drivers/net/ethernet/microchip/lan743x_ptp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/microchip/lan743x_ptp.c +6 -0
@@ -942,6 +942,12 @@ static int lan743x_ptp_io_extts(struct lan743x_adapter *adapter, int on, extts = &ptp->extts[index]; +if (extts_request->flags & ~(PTP_ENABLE_FEATURE | +PTP_RISING_EDGE | +PTP_FALLING_EDGE | +PTP_STRICT_FLAGS )) +return -EOPNOTSUPP ; +if (on) { extts_pin =ptp_find_pin (ptp->ptp_clock,PTP_PF_EXTTS , index);if (extts_pin <0 )
Signature · 1 line
2.48.1.397.gec9d649cc640
Re: [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests
Quoted 11 lines · Jacob Keller
The
lan743x_ptp_io_event_cap_en()function checks that the given request sets only one ofPTP_RISING_EDGEorPTP_FALLING_EDGE, but not both.However, this driver does not check whether other flags (such as
PTP_EXT_OFF) are set, nor whether any future unrecognized flags are set.Fix this by adding the appropriate check to the
lan743x_ptp_io_extts()function.Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")Signed-off-by Jacob Keller <[email protected]>
PATCH v2 4/5 broadcom: fix supported flag check in periodic output function
In reply to Jacob KellerIn bcm_ptp_perout_locked, the driver rejects requests which have PTP_PEROUT_PHASE set. This appears to be an attempt to reject any unsupported flags. Unfortunately, this only checks one flag, but does not protect against PTP_PEROUT_ONE_SHOT, or any future flags which may be added.
Fix the check to ensure that no flag other than the supported PTP_PEROUT_DUTY_CYCLE is set.
--- drivers/net/phy/bcm-phy-ptp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/bcm-phy-ptp.c +2 -1
@@ -597,7 +597,8 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv, period =BCM_MAX_PERIOD_8NS ;/* write nonzero value */ -if (req->flags &PTP_PEROUT_PHASE ) +/* Reject unsupported flags */ +if (req->flags & ~PTP_PEROUT_DUTY_CYCLE )return -EOPNOTSUPP ;if (req->flags &PTP_PEROUT_DUTY_CYCLE )
Signature · 1 line
2.48.1.397.gec9d649cc640
Re: [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function
Quoted 11 lines · Jacob Keller
In
bcm_ptp_perout_locked, the driver rejects requests which havePTP_PEROUT_PHASEset. This appears to be an attempt to reject any unsupported flags. Unfortunately, this only checks one flag, but does not protect againstPTP_PEROUT_ONE_SHOT, or any future flags which may be added.Fix the check to ensure that no flag other than the supported
PTP_PEROUT_DUTY_CYCLEis set.Fixes 7bfe91efd525 ("net: phy: Add support for 1PPS out and external timestamps")Signed-off-by Jacob Keller <[email protected]>
PATCH v2 5/5 ptp: ocp: reject unsupported periodic output flags
In reply to Jacob KellerThe ptp_ocp_signal_from_perout() function supports PTP_PEROUT_DUTY_CYCLE and PTP_PEROUT_PHASE. It does not support PTP_PEROUT_ONE_SHOT, but does not reject a request with such an unsupported flag.
Add the appropriate check to ensure that unsupported requests are rejected both for PTP_PEROUT_ONE_SHOT as well as any future flags.
--- drivers/ptp/ptp_ocp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ptp/ptp_ocp.c +4 -0
@@ -2090,6 +2090,10 @@ ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen, {struct ptp_ocp_signal s = { }; +if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE | +PTP_PEROUT_PHASE )) +return -EOPNOTSUPP ; + s.polarity = bp->signal[gen].polarity; s.period =ktime_set (req->period.sec, req->period.nsec);if (!s.period)
Signature · 1 line
2.48.1.397.gec9d649cc640
Re: [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags
Quoted 10 lines · Jacob Keller
The
ptp_ocp_signal_from_perout()function supportsPTP_PEROUT_DUTY_CYCLEandPTP_PEROUT_PHASE. It does not supportPTP_PEROUT_ONE_SHOT, but does not reject a request with such an unsupported flag.Add the appropriate check to ensure that unsupported requests are rejected both for
PTP_PEROUT_ONE_SHOTas well as any future flags.Fixes 1aa66a3a135a ("ptp: ocp: Program the signal generators via PTP_CLK_REQ_PEROUT")Reviewed-by Vadim Fedorenko <[email protected]>Signed-off-by Jacob Keller <[email protected]>
Paolo Abeni
maintainerQuoted 36 lines · Jacob Keller
In preparation for adding .supported_extts_flags and .supported_perout_flags to the
ptp_clock_infostructure, fix a couple of places where drivers get existing flag gets grossly incorrect.The igb driver claims 82580 supports strictly validating
PTP_RISING_EDGEandPTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver to require that the request match both edges, as this is implied by the datasheet description.The renesas driver also claims to support strict flag checking, but does not actually check the flags either. I do not have the data sheet for this device, so I do not know what edge it timestamps. For simplicity, just reject all requests with
PTP_STRICT_FLAGS. This essentially prevents thePTP_EXTTS_REQUEST2ioctl from working. Updating to correctly validate the flags will require someone who has the hardware to confirm the behavior.The lan743x driver supports (and strictly validates) that the request is either
PTP_RISING_EDGEorPTP_FALLING_EDGEbut not both. However, it does not check the flags are one of the known valid flags. Thus, requests forPTP_EXT_OFF(and any future flag) will be accepted and misinterpreted. Add the appropriate check to reject unsupportedPTP_EXT_OFFrequests and future proof against new flags.The broadcom PHY driver checks that
PTP_PEROUT_PHASEis not set. This appears to be an attempt at rejecting unsupported flags. It is not robust against flag additions such as thePTP_PEROUT_ONE_SHOT, or anything added in the future. Fix this by instead checking against the negation of the supportedPTP_PEROUT_DUTY_CYCLEinstead.The
ptp_ocpdriver supportsPTP_PEROUT_PHASEandPTP_PEROUT_DUTY_CYCLE, but does not check unsupported flags. Add the appropriate check to ensurePTP_PEROUT_ONE_SHOTand any future flags are rejected as unsupported.These are changes compile-tested, but I do not have hardware to validate the behavior.
Quoted 8 lines
There are a number of other drivers which enable periodic output or external timestamp requests, but which do not check flags at all. We could go through each of these drivers one-by-one and meticulously add a flag check. Instead, these drivers will be covered only by the upcoming .supported_extts_flags and .supported_perout_flags checks in a net-next series.
Signed-off-by Jacob Keller <[email protected]>
I admit I'm the most significant source of latency, but this series is IMHO a bit risky to land this late in the cycle in the net tree, especially considering the lack of H/W testing for the BCM phy.
What about applying this to net-next instead?
Thanks,
Paolo
Quoted 50 lines · Paolo Abeni
Quoted 36 lines · Jacob Keller
In preparation for adding .supported_extts_flags and .supported_perout_flags to the
ptp_clock_infostructure, fix a couple of places where drivers get existing flag gets grossly incorrect.The igb driver claims 82580 supports strictly validating
PTP_RISING_EDGEandPTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver to require that the request match both edges, as this is implied by the datasheet description.The renesas driver also claims to support strict flag checking, but does not actually check the flags either. I do not have the data sheet for this device, so I do not know what edge it timestamps. For simplicity, just reject all requests with
PTP_STRICT_FLAGS. This essentially prevents thePTP_EXTTS_REQUEST2ioctl from working. Updating to correctly validate the flags will require someone who has the hardware to confirm the behavior.The lan743x driver supports (and strictly validates) that the request is either
PTP_RISING_EDGEorPTP_FALLING_EDGEbut not both. However, it does not check the flags are one of the known valid flags. Thus, requests forPTP_EXT_OFF(and any future flag) will be accepted and misinterpreted. Add the appropriate check to reject unsupportedPTP_EXT_OFFrequests and future proof against new flags.The broadcom PHY driver checks that
PTP_PEROUT_PHASEis not set. This appears to be an attempt at rejecting unsupported flags. It is not robust against flag additions such as thePTP_PEROUT_ONE_SHOT, or anything added in the future. Fix this by instead checking against the negation of the supportedPTP_PEROUT_DUTY_CYCLEinstead.The
ptp_ocpdriver supportsPTP_PEROUT_PHASEandPTP_PEROUT_DUTY_CYCLE, but does not check unsupported flags. Add the appropriate check to ensurePTP_PEROUT_ONE_SHOTand any future flags are rejected as unsupported.These are changes compile-tested, but I do not have hardware to validate the behavior.
Quoted 8 lines
There are a number of other drivers which enable periodic output or external timestamp requests, but which do not check flags at all. We could go through each of these drivers one-by-one and meticulously add a flag check. Instead, these drivers will be covered only by the upcoming .supported_extts_flags and .supported_perout_flags checks in a net-next series.
Signed-off-by Jacob Keller <[email protected]>I admit I'm the most significant source of latency, but this series is IMHO a bit risky to land this late in the cycle in the net tree, especially considering the lack of H/W testing for the BCM phy.
Quoted 6 lines
What about applying this to net-next instead?
Thanks,
Paolo
I am fine with that. I only sent to net originally because I thought some folks might consider these worthy of backports due to the potential for user-error. However, given the minimal testing it may make sense to go ahead with next. Obviously no real users have complained about the situation, and this is more in preparation to make the kernel more resilient to such mistakes in the future with the .supported_*_flags modifications coming next cycle.
Thanks,
Jake
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Wed, 12 Mar 2025 15:15:49 -0700 you wrote:
In preparation for adding .supported_extts_flags and .supported_perout_flags to the
ptp_clock_infostructure, fix a couple of places where drivers get existing flag gets grossly incorrect.The igb driver claims 82580 supports strictly validating
PTP_RISING_EDGEandPTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver to require that the request match both edges, as this is implied by the datasheet description.[...]
Here is the summary with links:
- [net,v2,1/5] igb: reject invalid external timestamp requests for 82580-based HW
https://git.kernel.org/netdev/net-next/c/5eada2aabf13 - [net,v2,2/5] renesas: reject PTP_STRICT_FLAGS as unsupported https://git.kernel.org/netdev/net-next/c/51d58c0c7921 - [net,v2,3/5] net: lan743x: reject unsupported external timestamp requests https://git.kernel.org/netdev/net-next/c/c0b4ddd30871 - [net,v2,4/5] broadcom: fix supported flag check in periodic output function https://git.kernel.org/netdev/net-next/c/af2b428f7992 - [net,v2,5/5] ptp: ocp: reject unsupported periodic output flags https://git.kernel.org/netdev/net-next/c/8dcfc910a81d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html