Skip to contentSkip to conversation

ptp: Validate requests to enable time stamping of external signals.

PATCH In review Richard Cochran 2 participants 4 messages Nov 14, 2019

Subsystems (3)
lore
Share & tools
lore

Richard Cochran

author maintainer
#0 lore raw

PATCH 1/13 ptp: Validate requests to enable time stamping of external signals.

Commit 415606588c61 ("PTP: introduce new versions of IOCTLs") introduced a new external time stamp ioctl that validates the flags. This patch extends the validation to ensure that at least one rising or falling edge flag is set when enabling external time stamps.

---
 drivers/ptp/ptp_chardev.c      | 18 +++++++++++++-----
 include/uapi/linux/ptp_clock.h |  1 +
 2 files changed, 14 insertions(+), 5 deletions(-)
drivers/ptp/ptp_chardev.c +13 -5
index 67d0199840fd..cbbe1237ff8d 100644
@@ -149,11 +149,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 			err = -EFAULT;
 			break;
 		}
-		if (((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
-			req.extts.rsv[0] || req.extts.rsv[1]) &&
-			cmd == PTP_EXTTS_REQUEST2) {
-			err = -EINVAL;
-			break;
+		if (cmd == PTP_EXTTS_REQUEST2) {
+			/* Make sure no reserved bit is set. */
+			if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
+			    req.extts.rsv[0] || req.extts.rsv[1]) {
+				err = -EINVAL;
+				break;
+			}
+			/* Ensure one of the rising/falling edge bits is set. */
+			if ((req.extts.flags & PTP_ENABLE_FEATURE) &&
+			    (req.extts.flags & PTP_EXTTS_EDGES) == 0) {
+				err = -EINVAL;
+				break;
+			}
 		} else if (cmd == PTP_EXTTS_REQUEST) {
 			req.extts.flags &= PTP_EXTTS_V1_VALID_FLAGS;
 			req.extts.rsv[0] = 0;
include/uapi/linux/ptp_clock.h +1 -0
index 59e89a1bc3bb..304059b1609d 100644
@@ -31,6 +31,7 @@
 #define PTP_ENABLE_FEATURE (1<<0)
 #define PTP_RISING_EDGE    (1<<1)
 #define PTP_FALLING_EDGE   (1<<2)
+#define PTP_EXTTS_EDGES    (PTP_RISING_EDGE | PTP_FALLING_EDGE)
 
 /*
  * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
Signature · 1 line
2.20.1
#1 lore raw
Quoted 43 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, November 14, 2019 10:45 AM
To: netdev at vger.kernel.org
Cc: intel-wired-lan at lists.osuosl.org; David Miller <[email protected]>; Brandon Streiff <[email protected]>; Hall, Christopher S <[email protected]>; Eugenia Emantayev <[email protected]>; Felipe Balbi <[email protected]>; Feras Daoud <[email protected]>; Keller, Jacob E <[email protected]>; Kirsher, Jeffrey T <[email protected]>; Sergei Shtylyov <[email protected]>; Stefan Sorensen <[email protected]>
Subject: [PATCH net 01/13] ptp: Validate requests to enable time stamping of external signals.

Commit 415606588c61 ("PTP: introduce new versions of IOCTLs") introduced a new external time stamp ioctl that validates the flags. This patch extends the validation to ensure that at least one rising or falling edge flag is set when enabling external time stamps.

---
 drivers/ptp/ptp_chardev.c      | 18 +++++++++++++-----
 include/uapi/linux/ptp_clock.h |  1 +
 2 files changed, 14 insertions(+), 5 deletions(-)
drivers/ptp/ptp_chardev.c +3 -5
index 67d0199840fd..cbbe1237ff8d 100644
@@ -149,11 +149,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd,
 unsigned long arg)
 			err = -EFAULT;
 			break;
 		}
-		if (((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
-			req.extts.rsv[0] || req.extts.rsv[1]) &&
-			cmd == PTP_EXTTS_REQUEST2) {
-			err = -EINVAL;
-			break;
+		if (cmd == PTP_EXTTS_REQUEST2) {
+			/* Make sure no reserved bit is set. */
+			if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||

drivers/ptp/ptp_chardev.c long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, · line 165

Quoted 10 lines
drivers/ptp/ptp_chardev.c +10 -0
+			    req.extts.rsv[0] || req.extts.rsv[1]) {
+				err = -EINVAL;
+				break;
+			}
+			/* Ensure one of the rising/falling edge bits is set. */
+			if ((req.extts.flags & PTP_ENABLE_FEATURE) &&
+			    (req.extts.flags & PTP_EXTTS_EDGES) == 0) {
+				err = -EINVAL;
+				break;
+			}

Just to confirm, these new ioctls haven't been around long enough to be concerned about this change?

Thanks,
Jake

author maintainer
#2 lore raw
Quoted 1 line · Jacob E

Just to confirm, these new ioctls haven't been around long enough to be concerned about this change?

The "2" ioctls are about to appear in v5.4, and so I want to get the flag checking in before the release if possible.

Thanks,
Richard

#3 lore raw
Quoted 17 lines

-----Original Message-----
From: netdev-owner at vger.kernel.org <[email protected]> On Behalf Of Richard Cochran
Sent: Thursday, November 14, 2019 11:38 AM
To: Keller, Jacob E <[email protected]>
Cc: netdev at vger.kernel.org; intel-wired-lan at lists.osuosl.org; David Miller <[email protected]>; Brandon Streiff <[email protected]>; Hall, Christopher S <[email protected]>; Eugenia Emantayev <[email protected]>; Felipe Balbi <[email protected]>; Feras Daoud <[email protected]>; Kirsher, Jeffrey T <[email protected]>; Sergei Shtylyov <[email protected]>; Stefan Sorensen <[email protected]>
Subject: Re: [PATCH net 01/13] ptp: Validate requests to enable time stamping of external signals.

On Thu, Nov 14, 2019 at 07:06:58PM +0000, Keller, Jacob E wrote:

Quoted 8 lines
Quoted 1 line

Just to confirm, these new ioctls haven't been around long enough to be

concerned about this change?

The "2" ioctls are about to appear in v5.4, and so I want to get the flag checking in before the release if possible.

Thanks,
Richard

Yes agreed, we should land these fixes before 5.4 if we can, in order to ensure that the new ioctls always behaved the same way since their first major release introduction.

Regards,
Jake