]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ptp: only allow phase values lower than 1 period
authorVladimir Oltean <olteanv@gmail.com>
Wed, 5 Aug 2020 00:10:47 +0000 (03:10 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Aug 2020 19:06:44 +0000 (12:06 -0700)
The way we define the phase (the difference between the time of the
signal's rising edge, and the closest integer multiple of the period),
it doesn't make sense to have a phase value equal or larger than 1
period.

So deny these settings coming from the user.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/ptp/ptp_chardev.c

index e0e6f85966e193699426f60d0e383906c34cbbf1..af3bc65c4595dd50782ff2e02a2c17d0f6d0b670 100644 (file)
@@ -218,6 +218,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
                                        break;
                                }
                        }
+                       if (perout->flags & PTP_PEROUT_PHASE) {
+                               /*
+                                * The phase should be specified modulo the
+                                * period, therefore anything equal or larger
+                                * than 1 period is invalid.
+                                */
+                               if (perout->phase.sec > perout->period.sec ||
+                                   (perout->phase.sec == perout->period.sec &&
+                                    perout->phase.nsec >= perout->period.nsec)) {
+                                       err = -ERANGE;
+                                       break;
+                               }
+                       }
                } else if (cmd == PTP_PEROUT_REQUEST) {
                        req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS;
                        req.perout.rsv[0] = 0;