Skip to content

Commit e2a689a

Browse files
committed
Merge branch 'ptp-Validate-the-ancillary-ioctl-flags-more-carefully'
Richard Cochran says: ==================== ptp: Validate the ancillary ioctl flags more carefully. The flags passed to the ioctls for periodic output signals and time stamping of external signals were never checked, and thus formed a useless ABI inadvertently. More recently, a version 2 of the ioctls was introduced in order make the flags meaningful. This series tightens up the checks on the new ioctl flags. - Patch 1 ensures at least one edge flag is set for the new ioctl. - Patches 2-7 are Jacob's recent checks, picking up the tags. - Patch 8 introduces a "strict" flag for passing to the drivers when the new ioctl is used. - Patches 9-12 implement the "strict" checking in the drivers. - Patch 13 extends the test program to exercise combinations of flags. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 3df70af + 6eb54cb commit e2a689a

File tree

11 files changed

+156
-8
lines changed

11 files changed

+156
-8
lines changed

drivers/net/dsa/mv88e6xxx/ptp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ static int mv88e6352_ptp_enable_extts(struct mv88e6xxx_chip *chip,
273273
int pin;
274274
int err;
275275

276+
/* Reject requests with unsupported flags */
277+
if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
278+
PTP_RISING_EDGE |
279+
PTP_FALLING_EDGE |
280+
PTP_STRICT_FLAGS))
281+
return -EOPNOTSUPP;
282+
283+
/* Reject requests to enable time stamping on both edges. */
284+
if ((rq->extts.flags & PTP_STRICT_FLAGS) &&
285+
(rq->extts.flags & PTP_ENABLE_FEATURE) &&
286+
(rq->extts.flags & PTP_EXTTS_EDGES) == PTP_EXTTS_EDGES)
287+
return -EOPNOTSUPP;
288+
276289
pin = ptp_find_pin(chip->ptp_clock, PTP_PF_EXTTS, rq->extts.index);
277290

278291
if (pin < 0)

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6280,6 +6280,10 @@ static int tg3_ptp_enable(struct ptp_clock_info *ptp,
62806280

62816281
switch (rq->type) {
62826282
case PTP_CLK_REQ_PEROUT:
6283+
/* Reject requests with unsupported flags */
6284+
if (rq->perout.flags)
6285+
return -EOPNOTSUPP;
6286+
62836287
if (rq->perout.index != 0)
62846288
return -EINVAL;
62856289

drivers/net/ethernet/intel/igb/igb_ptp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,19 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp,
521521

522522
switch (rq->type) {
523523
case PTP_CLK_REQ_EXTTS:
524+
/* Reject requests with unsupported flags */
525+
if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
526+
PTP_RISING_EDGE |
527+
PTP_FALLING_EDGE |
528+
PTP_STRICT_FLAGS))
529+
return -EOPNOTSUPP;
530+
531+
/* Reject requests failing to enable both edges. */
532+
if ((rq->extts.flags & PTP_STRICT_FLAGS) &&
533+
(rq->extts.flags & PTP_ENABLE_FEATURE) &&
534+
(rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
535+
return -EOPNOTSUPP;
536+
524537
if (on) {
525538
pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS,
526539
rq->extts.index);
@@ -551,6 +564,10 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp,
551564
return 0;
552565

553566
case PTP_CLK_REQ_PEROUT:
567+
/* Reject requests with unsupported flags */
568+
if (rq->perout.flags)
569+
return -EOPNOTSUPP;
570+
554571
if (on) {
555572
pin = ptp_find_pin(igb->ptp_clock, PTP_PF_PEROUT,
556573
rq->perout.index);

drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp,
236236
if (!MLX5_PPS_CAP(mdev))
237237
return -EOPNOTSUPP;
238238

239+
/* Reject requests with unsupported flags */
240+
if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
241+
PTP_RISING_EDGE |
242+
PTP_FALLING_EDGE |
243+
PTP_STRICT_FLAGS))
244+
return -EOPNOTSUPP;
245+
246+
/* Reject requests to enable time stamping on both edges. */
247+
if ((rq->extts.flags & PTP_STRICT_FLAGS) &&
248+
(rq->extts.flags & PTP_ENABLE_FEATURE) &&
249+
(rq->extts.flags & PTP_EXTTS_EDGES) == PTP_EXTTS_EDGES)
250+
return -EOPNOTSUPP;
251+
239252
if (rq->extts.index >= clock->ptp_info.n_pins)
240253
return -EINVAL;
241254

@@ -290,6 +303,10 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,
290303
if (!MLX5_PPS_CAP(mdev))
291304
return -EOPNOTSUPP;
292305

306+
/* Reject requests with unsupported flags */
307+
if (rq->perout.flags)
308+
return -EOPNOTSUPP;
309+
293310
if (rq->perout.index >= clock->ptp_info.n_pins)
294311
return -EINVAL;
295312

drivers/net/ethernet/microchip/lan743x_ptp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ static int lan743x_ptp_perout(struct lan743x_adapter *adapter, int on,
429429
int pulse_width = 0;
430430
int perout_bit = 0;
431431

432+
/* Reject requests with unsupported flags */
433+
if (perout->flags)
434+
return -EOPNOTSUPP;
435+
432436
if (!on) {
433437
lan743x_ptp_perout_off(adapter);
434438
return 0;

drivers/net/ethernet/renesas/ravb_ptp.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,
182182
struct net_device *ndev = priv->ndev;
183183
unsigned long flags;
184184

185+
/* Reject requests with unsupported flags */
186+
if (req->flags & ~(PTP_ENABLE_FEATURE |
187+
PTP_RISING_EDGE |
188+
PTP_FALLING_EDGE |
189+
PTP_STRICT_FLAGS))
190+
return -EOPNOTSUPP;
191+
185192
if (req->index)
186193
return -EINVAL;
187194

@@ -211,6 +218,10 @@ static int ravb_ptp_perout(struct ptp_clock_info *ptp,
211218
unsigned long flags;
212219
int error = 0;
213220

221+
/* Reject requests with unsupported flags */
222+
if (req->flags)
223+
return -EOPNOTSUPP;
224+
214225
if (req->index)
215226
return -EINVAL;
216227

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
140140

141141
switch (rq->type) {
142142
case PTP_CLK_REQ_PEROUT:
143+
/* Reject requests with unsupported flags */
144+
if (rq->perout.flags)
145+
return -EOPNOTSUPP;
146+
143147
cfg = &priv->pps[rq->perout.index];
144148

145149
cfg->start.tv_sec = rq->perout.start.sec;

drivers/net/phy/dp83640.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
469469

470470
switch (rq->type) {
471471
case PTP_CLK_REQ_EXTTS:
472+
/* Reject requests with unsupported flags */
473+
if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
474+
PTP_RISING_EDGE |
475+
PTP_FALLING_EDGE |
476+
PTP_STRICT_FLAGS))
477+
return -EOPNOTSUPP;
478+
479+
/* Reject requests to enable time stamping on both edges. */
480+
if ((rq->extts.flags & PTP_STRICT_FLAGS) &&
481+
(rq->extts.flags & PTP_ENABLE_FEATURE) &&
482+
(rq->extts.flags & PTP_EXTTS_EDGES) == PTP_EXTTS_EDGES)
483+
return -EOPNOTSUPP;
484+
472485
index = rq->extts.index;
473486
if (index >= N_EXT_TS)
474487
return -EINVAL;
@@ -491,6 +504,9 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
491504
return 0;
492505

493506
case PTP_CLK_REQ_PEROUT:
507+
/* Reject requests with unsupported flags */
508+
if (rq->perout.flags)
509+
return -EOPNOTSUPP;
494510
if (rq->perout.index >= N_PER_OUT)
495511
return -EINVAL;
496512
return periodic_output(clock, rq, on, rq->perout.index);

drivers/ptp/ptp_chardev.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,21 @@ 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+
/* Tell the drivers to check the flags carefully. */
154+
req.extts.flags |= PTP_STRICT_FLAGS;
155+
/* Make sure no reserved bit is set. */
156+
if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
157+
req.extts.rsv[0] || req.extts.rsv[1]) {
158+
err = -EINVAL;
159+
break;
160+
}
161+
/* Ensure one of the rising/falling edge bits is set. */
162+
if ((req.extts.flags & PTP_ENABLE_FEATURE) &&
163+
(req.extts.flags & PTP_EXTTS_EDGES) == 0) {
164+
err = -EINVAL;
165+
break;
166+
}
157167
} else if (cmd == PTP_EXTTS_REQUEST) {
158168
req.extts.flags &= PTP_EXTTS_V1_VALID_FLAGS;
159169
req.extts.rsv[0] = 0;

include/uapi/linux/ptp_clock.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
#define PTP_ENABLE_FEATURE (1<<0)
3232
#define PTP_RISING_EDGE (1<<1)
3333
#define PTP_FALLING_EDGE (1<<2)
34+
#define PTP_STRICT_FLAGS (1<<3)
35+
#define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
3436

3537
/*
3638
* flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
3739
*/
3840
#define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
3941
PTP_RISING_EDGE | \
40-
PTP_FALLING_EDGE)
42+
PTP_FALLING_EDGE | \
43+
PTP_STRICT_FLAGS)
4144

4245
/*
4346
* flag fields valid for the original PTP_EXTTS_REQUEST ioctl.

0 commit comments

Comments
 (0)