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] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 5 Nov 2021 21:45:30 +0100
From:   Arnd Bergmann <arnd@...nel.org>
To:     Nick Desaulniers <ndesaulniers@...gle.com>
Cc:     Anders Roxell <anders.roxell@...aro.org>,
        Shuah Khan <shuah@...nel.org>,
        Nathan Chancellor <nathan@...nel.org>,
        "open list:KERNEL SELFTEST FRAMEWORK" 
        <linux-kselftest@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        llvm@...ts.linux.dev
Subject: Re: [PATCH 2/2] selftests: timens: exec: use 'labs()' over 'abs()'

On Fri, Nov 5, 2021 at 9:35 PM Nick Desaulniers <ndesaulniers@...gle.com> wrote:
>
> On Fri, Nov 5, 2021 at 9:31 AM Anders Roxell <anders.roxell@...aro.org> wrote:
> >
> > When building selftests/timens with clang, the compiler warn about the
> > function abs() see below:
> >
> > exec.c:33:8: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value]
> >                         if (abs(tst.tv_sec - now.tv_sec) > 5)
> >                             ^
> > exec.c:33:8: note: use function 'labs' instead
> >                         if (abs(tst.tv_sec - now.tv_sec) > 5)
> >                             ^~~
> >                             labs
>
> Careful.
>
> Isn't the tv_sec member of `struct timespec` a `time_t` which is 32b
> on 32b hosts and 64b on 64b hosts? If I'm recalling that correctly,
> then this patch results in a harmless (though unnecessary) sign
> extension for 32b targets. That should be fine, but someone like Arnd
> should triple check if my concern is valid or not.

It could actually be 'int', 'long' or 'long long' depending on the architecture
and C library. Maybe we need a temporary variable of type 'long long'
to hold the difference, and pass that to llabs()?

       Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ