Skip to content

Commit cd734d5

Browse files
richardcochrandavem330
authored andcommitted
ptp: Validate requests to enable time stamping of external signals.
Commit 4156065 ("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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3df70af commit cd734d5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,19 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
149149
err = -EFAULT;
150150
break;
151151
}
152-
if (((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
153-
req.extts.rsv[0] || req.extts.rsv[1]) &&
154-
cmd == PTP_EXTTS_REQUEST2) {
155-
err = -EINVAL;
156-
break;
152+
if (cmd == PTP_EXTTS_REQUEST2) {
153+
/* Make sure no reserved bit is set. */
154+
if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
155+
req.extts.rsv[0] || req.extts.rsv[1]) {
156+
err = -EINVAL;
157+
break;
158+
}
159+
/* Ensure one of the rising/falling edge bits is set. */
160+
if ((req.extts.flags & PTP_ENABLE_FEATURE) &&
161+
(req.extts.flags & PTP_EXTTS_EDGES) == 0) {
162+
err = -EINVAL;
163+
break;
164+
}
157165
} else if (cmd == PTP_EXTTS_REQUEST) {
158166
req.extts.flags &= PTP_EXTTS_V1_VALID_FLAGS;
159167
req.extts.rsv[0] = 0;

include/uapi/linux/ptp_clock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define PTP_ENABLE_FEATURE (1<<0)
3232
#define PTP_RISING_EDGE (1<<1)
3333
#define PTP_FALLING_EDGE (1<<2)
34+
#define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
3435

3536
/*
3637
* flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.

0 commit comments

Comments
 (0)