lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e8f0948b-81dd-53c9-6a18-1da50b099b7a@huawei.com>
Date:   Fri, 8 Mar 2019 14:47:11 +0800
From:   Xiongfeng Wang <wangxiongfeng2@...wei.com>
To:     Arnd Bergmann <arnd@...db.de>
CC:     Thomas Gleixner <tglx@...utronix.de>,
        Deepa Dinamani <deepa.kernel@...il.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] posix-cpu-timers: Avoid undefined behaviour in
 timespec64_to_ns()



On 2019/3/6 18:38, Arnd Bergmann wrote:
> On Wed, Mar 6, 2019 at 9:41 AM Xiongfeng Wang <wangxiongfeng2@...wei.com> wrote:
>>
>>
>> diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
>> index 0e84bb7..4b57566 100644
>> --- a/kernel/time/posix-timers.c
>> +++ b/kernel/time/posix-timers.c
>> @@ -856,6 +856,10 @@ static int do_timer_settime(timer_t timer_id, int flags,
>>         if (!timespec64_valid(&new_spec64->it_interval) ||
>>             !timespec64_valid(&new_spec64->it_value))
>>                 return -EINVAL;
>> +       if (new_spec64->it_interval.tv_sec > KTIME_SEC_MAX)
>> +               new_spec64->it_interval.tv_sec = KTIME_SEC_MAX;
>> +       if (new_spec64->it_value.tv_sec > KTIME_SEC_MAX)
>> +               new_spec64->it_value.tv_sec = KTIME_SEC_MAX;
>>
> 
> I looked at the calculation we do later, and I think this can still overflow
> if tv_nsec is too large. The largest timespec value we can support is
> 
> (struct timespec64) { .tv_sec = 9223372036, .tv_nsec = 854775807 }
> 
> Your patch caps the tv_sec value to 9223372036, but it does not
> cap the tv_nsec. The easiest fix would be to always set tv_nsec
> to 0 if tv_sec>=9223372036, or a more correct calculation would
> have to limit tv_nsec if tv_sec==9223372036. I don't know if that
> matters or not (it should not, unless we explicitly compare the
> ktime_t for equality with KTIME_MAX later).

Thanks for your advice. I will send another one to  set tv_nsec
to 0 if tv_sec>=9223372036.
Do need to add a helper to clamp timespec64, such as 'saturate_timespec64_valid()'
to limit it between 0 and KTIME_MAX(or KTIME_SEC_MAX, it's easier.)

Thanks,
Xiongfeng

> 
>      Arnd
> 
> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ