ptp: add range check on n_samples
Subsystems (3)
PATCH 1/1 ptp: add range check on n_samples
Quoted 1 line
From
d4eb97e8d5def76d46167c91059147e2c7d33433Mon 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.
--- drivers/ptp/ptp_chardev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ptp/ptp_chardev.c +2 -1
@@ -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 ; }
Signature · 5 lines
1.7.11.7 -- Best Regards, Dong Zhu
Richard Cochran
maintainerQuoted 6 lines · Dong Zhu
From
d4eb97e8d5def76d46167c91059147e2c7d33433Mon Sep 17 00:00:00 2001When using
PTP_SYS_OFFSETioctl to measure the time offset between the PHC and system clock, we need to specify the number of measurements, the valid value ofn_samplesis between 1 to 25. Ifn_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
Quoted 25 lines
Signed-off-by Dong Zhu <[email protected]>--- drivers/ptp/ptp_chardev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/ptp/ptp_chardev.c +2
-1@@ -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 ; }Signature · 5 lines
1.7.11.7 -- Best Regards, Dong Zhu