Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1286116

Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset

From John Stultz <john.stultz@linaro.org>
Newsgroups linux.kernel
Subject Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset
Date 2015-12-08 01:10 +0100
Message-ID <qDe0W-3li-11@gated-at.bofh.it> (permalink)
References <qBIZb-1y2-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Dec 3, 2015 at 12:46 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
> We need to make sure that the offset is valid before manipulating it,
> otherwise it might overflow on the multiplication.
>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>  kernel/time/ntp.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
> index 149cc80..36616c3 100644
> --- a/kernel/time/ntp.c
> +++ b/kernel/time/ntp.c
> @@ -297,6 +297,9 @@ static void ntp_update_offset(long offset)
>         if (!(time_status & STA_PLL))
>                 return;
>
> +       /* Make sure the multiplication below won't overflow */
> +       offset = clamp(offset, -MAXPHASE, MAXPHASE);
> +
>         if (!(time_status & STA_NANO))
>                 offset *= NSEC_PER_USEC;

So looking at this a bit closer, this bit looks sort of crazy since we
clam the offset, do the multiply and then do the exact same clamp.

I'd much rather do a more logical  clamp(offset, -USEC_PER_SEC,
USEC_PER_SEC), but only in the case where we do the multiply.

Any objection to that?

thanks
-john
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] ntp: verify offset doesn't overflow in ntp_update_offset Sasha Levin <sasha.levin@oracle.com> - 2015-12-03 21:50 +0100
  Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset John Stultz <john.stultz@linaro.org> - 2015-12-04 21:30 +0100
  Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset John Stultz <john.stultz@linaro.org> - 2015-12-08 01:10 +0100
    Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset Sasha Levin <sasha.levin@oracle.com> - 2015-12-08 01:30 +0100

csiph-web