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: <20241228130313.4457f873@dsl-u17-10>
Date: Sat, 28 Dec 2024 13:05:15 +0000
From: David Laight <david.laight.linux@...il.com>
To: kernel test robot <lkp@...el.com>
Cc: Vadim Pasternak <vadimp@...lanox.com>, oe-kbuild-all@...ts.linux.dev,
 linux-kernel@...r.kernel.org, Andy Shevchenko
 <andriy.shevchenko@...ux.intel.com>, yury.norov@...il.com
Subject: Re: drivers/platform/mellanox/mlxreg-hotplug.c:87:61: warning: '%d'
 directive output may be truncated writing 1 byte into a region of size
 between 0 and 31

On Sat, 28 Dec 2024 10:23:25 +0800
kernel test robot <lkp@...el.com> wrote:

(resend with fixed email address)

> Hi Vadim,
> 
> FYI, the error/warning still remains.
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   fd0584d220fe285dc45be43eede55df89ad6a3d9
> commit: 92d020f97966b1724cfcac93e89176d0eb3aca61 platform/mellanox: mlxreg-hotplug: Add environmental data to uevent
> date:   4 years, 5 months ago
> config: sparc-randconfig-001-20241212 (https://download.01.org/0day-ci/archive/20241228/202412281022.emy8ZDNh-lkp@intel.com/config)
> compiler: sparc-linux-gcc (GCC) 12.4.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241228/202412281022.emy8ZDNh-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@...el.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202412281022.emy8ZDNh-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    In file included from include/linux/bits.h:23,
>                     from include/linux/bitops.h:5,
>                     from drivers/platform/mellanox/mlxreg-hotplug.c:8:
>    drivers/platform/mellanox/mlxreg-hotplug.c: In function 'mlxreg_hotplug_attr_init':
>    include/linux/bits.h:26:42: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
>       26 |                 __builtin_constant_p((l) > (h)), (l) > (h), 0)))
>          |                                          ^
>    include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO'
>       16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
>          |                                                              ^
>    include/linux/bits.h:39:10: note: in expansion of macro 'GENMASK_INPUT_CHECK'
>       39 |         (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))

This pretty much always gives a warning when -Wtype-limits is enabled.
I'm sure someone said it was being removed from 'W=1' builds.
But changing the defines to (say):
	__builtin_constant_p((hi) - (lo), __GENMASK((hi) - (lo), 0) <<
(lo), __GENMASK(hi, lo)) will remove the type-limits warning and give a
'negative shift' error if (lo) > (hi).

...
>    drivers/platform/mellanox/mlxreg-hotplug.c: In function 'mlxreg_hotplug_udev_event_send.isra':
> >> drivers/platform/mellanox/mlxreg-hotplug.c:87:61: warning: '%d' directive output may be truncated writing 1 byte into a region of size between 0 and 31 [-Wformat-truncation=]  
>       87 |         snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
>          |                                                             ^~
>    drivers/platform/mellanox/mlxreg-hotplug.c:87:57: note: directive argument in the range [0, 1]
>       87 |         snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
>          |                                                         ^~~~~~~
>    drivers/platform/mellanox/mlxreg-hotplug.c:87:9: note: 'snprintf' output between 3 and 34 bytes into a destination of size 32
>       87 |         snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
>          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

The compiler is failing to note that ! returns 0 or 1!
But maybe 'action != 0' will be ok.

	David

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ