netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ptp: validate the requested frequency adjustment.
@ 2014-04-27 13:01 Richard Cochran
  2014-04-28 17:29 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Cochran @ 2014-04-27 13:01 UTC (permalink / raw)
  To: netdev; +Cc: David Miller

PTP Hardware Clock drivers specify a maximum frequency adjustment that
their clocks can accommodate. Normally, user space programs will want to
respect the advertised limits. However, no kernel or driver code checks
that the dialed frequency offset is within the bounds, and out of range
values can lead to surprising results.

This patch fixes the issue by rejecting bad values.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
 drivers/ptp/ptp_clock.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index e25d2bc..296b0ec 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -142,7 +142,10 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
 		delta = ktime_to_ns(kt);
 		err = ops->adjtime(ops, delta);
 	} else if (tx->modes & ADJ_FREQUENCY) {
-		err = ops->adjfreq(ops, scaled_ppm_to_ppb(tx->freq));
+		s32 ppb = scaled_ppm_to_ppb(tx->freq);
+		if (ppb > ops->max_adj || ppb < -ops->max_adj)
+			return -ERANGE;
+		err = ops->adjfreq(ops, ppb);
 		ptp->dialed_frequency = tx->freq;
 	} else if (tx->modes == 0) {
 		tx->freq = ptp->dialed_frequency;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] ptp: validate the requested frequency adjustment.
  2014-04-27 13:01 [PATCH net-next] ptp: validate the requested frequency adjustment Richard Cochran
@ 2014-04-28 17:29 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-04-28 17:29 UTC (permalink / raw)
  To: richardcochran; +Cc: netdev

From: Richard Cochran <richardcochran@gmail.com>
Date: Sun, 27 Apr 2014 15:01:27 +0200

> PTP Hardware Clock drivers specify a maximum frequency adjustment that
> their clocks can accommodate. Normally, user space programs will want to
> respect the advertised limits. However, no kernel or driver code checks
> that the dialed frequency offset is within the bounds, and out of range
> values can lead to surprising results.
> 
> This patch fixes the issue by rejecting bad values.
> 
> Signed-off-by: Richard Cochran <richardcochran@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-28 19:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-27 13:01 [PATCH net-next] ptp: validate the requested frequency adjustment Richard Cochran
2014-04-28 17:29 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).