Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3bc753c

Browse files
committedNov 18, 2022
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>
1 parent daf4218 commit 3bc753c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
562562
KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
563563
-fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
564564
-Werror=implicit-function-declaration -Werror=implicit-int \
565-
-Werror=return-type -Wno-format-security \
565+
-Werror=return-type -Wno-format-security -funsigned-char \
566566
-std=gnu11
567567
KBUILD_CPPFLAGS := -D__KERNEL__
568568
KBUILD_RUSTFLAGS := $(rust_common_flags) \

0 commit comments

Comments
 (0)
Failed to load comments.