netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ptp: add range check on n_samples
@ 2013-09-24  7:05 Dong Zhu
  2013-09-24 12:50 ` Richard Cochran
  0 siblings, 1 reply; 2+ messages in thread
From: Dong Zhu @ 2013-09-24  7:05 UTC (permalink / raw)
  To: Richard Cochran, David Miller; +Cc: netdev, linux-kernel

>From d4eb97e8d5def76d46167c91059147e2c7d33433 Mon Sep 17 00:00:00 2001

When using PTP_SYS_OFFSET ioctl to measure the time offset between the
PHC and system clock, we need to specify the number of measurements, the
valid value of n_samples is between 1 to 25. If n_samples <= 0 or > 25
it makes no sense, so this patch intends to add a range check.

Signed-off-by: Dong Zhu <bluezhudong@gmail.com>
---
 drivers/ptp/ptp_chardev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index 34a0c60..4e85b23 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -104,7 +104,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 			err = -EFAULT;
 			break;
 		}
-		if (sysoff->n_samples > PTP_MAX_SAMPLES) {
+		if (sysoff->n_samples <= 0 ||
+		    sysoff->n_samples > PTP_MAX_SAMPLES) {
 			err = -EINVAL;
 			break;
 		}
-- 
1.7.11.7

-- 
Best Regards,
Dong Zhu

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

* Re: [PATCH] ptp: add range check on n_samples
  2013-09-24  7:05 [PATCH] ptp: add range check on n_samples Dong Zhu
@ 2013-09-24 12:50 ` Richard Cochran
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Cochran @ 2013-09-24 12:50 UTC (permalink / raw)
  To: Dong Zhu; +Cc: David Miller, netdev, linux-kernel

On Tue, Sep 24, 2013 at 03:05:57PM +0800, Dong Zhu wrote:
> From d4eb97e8d5def76d46167c91059147e2c7d33433 Mon Sep 17 00:00:00 2001
> 
> When using PTP_SYS_OFFSET ioctl to measure the time offset between the
> PHC and system clock, we need to specify the number of measurements, the
> valid value of n_samples is between 1 to 25. If n_samples <= 0 or > 25
> it makes no sense, so this patch intends to add a range check.

The field, n_samples, is unsigned, so the check is not needed.

Thanks,
Richard
 
> Signed-off-by: Dong Zhu <bluezhudong@gmail.com>
> ---
>  drivers/ptp/ptp_chardev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index 34a0c60..4e85b23 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -104,7 +104,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
>  			err = -EFAULT;
>  			break;
>  		}
> -		if (sysoff->n_samples > PTP_MAX_SAMPLES) {
> +		if (sysoff->n_samples <= 0 ||
> +		    sysoff->n_samples > PTP_MAX_SAMPLES) {
>  			err = -EINVAL;
>  			break;
>  		}
> -- 
> 1.7.11.7
> 
> -- 
> Best Regards,
> Dong Zhu

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

end of thread, other threads:[~2013-09-24 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-24  7:05 [PATCH] ptp: add range check on n_samples Dong Zhu
2013-09-24 12:50 ` Richard Cochran

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).