randstruct: report bad casts as warnings rather than notes

find_bad_casts() reports a cast between two randomized structure pointer
types with inform(), which renders as a "note:". It has done so since
the plugin was originally added, while using error() freely for attribute
misuse, UAPI structs, and version mismatches.

Clang's implementation of the same check has always been stricter:
it rejects such a cast as a full error. There is no reason for the GCC
side to be effectively silent about the same problem.

Build tested ARCH=x86_64 with CONFIG_RANDSTRUCT_FULL=y and GCC 14.2.0:
allmodconfig clean, and defconfig clean under three different random
seeds. A deliberate bad cast is still reported, now as a warning, at the
correct line and column.

Link: https://patch.msgid.link/20260903232438.60394-2-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
Kees Cook 2026-09-03 16:24:36 -07:00
parent 67beeb5621
commit b9f13e51ad

View File

@ -22,7 +22,7 @@
#define ORIG_TYPE_NAME(node) \
(TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
#define INFORM(loc, msg, ...) inform(loc, "randstruct: " msg, ##__VA_ARGS__)
#define INFORM(loc, msg, ...) warning_at(loc, 0, "randstruct: " msg, ##__VA_ARGS__)
#define MISMATCH(loc, how, ...) INFORM(loc, "casting between randomized structure pointer types (" how "): %qT and %qT\n", __VA_ARGS__)
__visible int plugin_is_GPL_compatible;