Skip to content

Commit 2df4de1

Browse files
jacob-kellerdavem330
authored andcommitted
ptp: correctly disable flags on old ioctls
Commit 4156065 ("PTP: introduce new versions of IOCTLs", 2019-09-13) introduced new versions of the PTP ioctls which actually validate that the flags are acceptable values. As part of this, it cleared the flags value using a bitwise and+negation, in an attempt to prevent the old ioctl from accidentally enabling new features. This is incorrect for a couple of reasons. First, it results in accidentally preventing previously working flags on the request ioctl. By clearing the "valid" flags, we now no longer allow setting the enable, rising edge, or falling edge flags. Second, if we add new additional flags in the future, they must not be set by the old ioctl. (Since the flag wasn't checked before, we could potentially break userspace programs which sent garbage flag data. The correct way to resolve this is to check for and clear all but the originally valid flags. Create defines indicating which flags are correctly checked and interpreted by the original ioctls. Use these to clear any bits which will not be correctly interpreted by the original ioctls. In the future, new flags must be added to the VALID_FLAGS macros, but *not* to the V1_VALID_FLAGS macros. In this way, new features may be exposed over the v2 ioctls, but without breaking previous userspace which happened to not clear the flags value properly. The old ioctl will continue to behave the same way, while the new ioctl gains the benefit of using the flags fields. Cc: Richard Cochran <[email protected]> Cc: Felipe Balbi <[email protected]> Cc: David S. Miller <[email protected]> Cc: Christopher Hall <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Acked-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 991ad2b commit 2df4de1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
155155
err = -EINVAL;
156156
break;
157157
} else if (cmd == PTP_EXTTS_REQUEST) {
158-
req.extts.flags &= ~PTP_EXTTS_VALID_FLAGS;
158+
req.extts.flags &= PTP_EXTTS_V1_VALID_FLAGS;
159159
req.extts.rsv[0] = 0;
160160
req.extts.rsv[1] = 0;
161161
}
@@ -184,7 +184,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
184184
err = -EINVAL;
185185
break;
186186
} else if (cmd == PTP_PEROUT_REQUEST) {
187-
req.perout.flags &= ~PTP_PEROUT_VALID_FLAGS;
187+
req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS;
188188
req.perout.rsv[0] = 0;
189189
req.perout.rsv[1] = 0;
190190
req.perout.rsv[2] = 0;

include/uapi/linux/ptp_clock.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,37 @@
3131
#define PTP_ENABLE_FEATURE (1<<0)
3232
#define PTP_RISING_EDGE (1<<1)
3333
#define PTP_FALLING_EDGE (1<<2)
34+
35+
/*
36+
* flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
37+
*/
3438
#define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
3539
PTP_RISING_EDGE | \
3640
PTP_FALLING_EDGE)
3741

42+
/*
43+
* flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
44+
* DO NOT ADD NEW FLAGS HERE.
45+
*/
46+
#define PTP_EXTTS_V1_VALID_FLAGS (PTP_ENABLE_FEATURE | \
47+
PTP_RISING_EDGE | \
48+
PTP_FALLING_EDGE)
49+
3850
/*
3951
* Bits of the ptp_perout_request.flags field:
4052
*/
4153
#define PTP_PEROUT_ONE_SHOT (1<<0)
54+
55+
/*
56+
* flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl.
57+
*/
4258
#define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT)
59+
60+
/*
61+
* No flags are valid for the original PTP_PEROUT_REQUEST ioctl
62+
*/
63+
#define PTP_PEROUT_V1_VALID_FLAGS (0)
64+
4365
/*
4466
* struct ptp_clock_time - represents a time value
4567
*

0 commit comments

Comments
 (0)