]> git.itanic.dy.fi Git - linux-stable/commit
kbuild: treat char as always unsigned
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 19 Oct 2022 16:26:48 +0000 (10:26 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 18 Nov 2022 23:56:15 +0000 (00:56 +0100)
commit3bc753c06dd02a3517c9b498e3846ebfc94ac3ee
treebc56dfe86a9f735c0bc099513988a56d0a0ffbff
parentdaf4218bf8dd9750d1ad93846aee98bf2e08eeee
kbuild: treat char as always unsigned

Recently, some compile-time checking I added to the clamp_t family of
functions triggered a build error when a poorly written driver was
compiled on ARM, because the driver assumed that the naked `char` type
is signed, but ARM treats it as unsigned, and the C standard says it's
architecture-dependent.

I doubt this particular driver is the only instance in which
unsuspecting authors make assumptions about `char` with no `signed` or
`unsigned` specifier. We were lucky enough this time that that driver
used `clamp_t(char, negative_value, positive_value)`, so the new
checking code found it, and I've sent a patch to fix it, but there are
likely other places lurking that won't be so easily unearthed.

So let's just eliminate this particular variety of heisensign bugs
entirely. Set `-funsigned-char` globally, so that gcc makes the type
unsigned on all architectures.

This will break things in some places and fix things in others, so this
will likely cause a bit of churn while reconciling the type misuse.

Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/lkml/202210190108.ESC3pc3D-lkp@intel.com/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Makefile