ptp: Validate requests to enable time stamping of external signals.
authorRichard Cochran <richardcochran@gmail.com>
Thu, 14 Nov 2019 18:44:55 +0000 (10:44 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Nov 2019 20:48:32 +0000 (12:48 -0800)
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.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/ptp/ptp_chardev.c
include/uapi/linux/ptp_clock.h

index 67d0199840fdd224d088eed7da7f9f1b1ffbeaee..cbbe1237ff8d3ee8d5843ce1e189a98b0e8210e3 100644 (file)
@@ -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;
index 59e89a1bc3bb5fe14cc9ba22eda8a05f7ec4db67..304059b1609d25338fc532c9fcfb5e44c447c41c 100644 (file)
@@ -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.