public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mod_devicetable: Enlarge the maximum platform_device_id name length
@ 2025-04-15 23:14 Kees Cook
  2025-04-16  6:45 ` Andy Shevchenko
  2025-04-21 21:30 ` Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2025-04-15 23:14 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Kees Cook, Nipun Gupta, Nikhil Agarwal, Borislav Petkov (AMD),
	Pieter Jansen van Vuuren, Andy Shevchenko, Dave Hansen,
	Ingo Molnar, Mark Brown, Wesley Cheng, Tony Luck, Pawan Gupta,
	linux-kernel, linux-hardening

The 20 byte length of struct platform_device_id::name is not long enough
for many devices (especially regulators), where the string initialization
is getting truncated and missing the trailing NUL byte. This is seen
with GCC 15's -Wunterminated-string-initialization option:

drivers/regulator/hi6421v530-regulator.c:189:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  189 |         { .name = "hi6421v530-regulator" },
      |                   ^~~~~~~~~~~~~~~~~~~~~~
drivers/regulator/hi6421v600-regulator.c:278:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  278 |         { .name = "hi6421v600-regulator" },
      |                   ^~~~~~~~~~~~~~~~~~~~~~
drivers/regulator/lp87565-regulator.c:233:11: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  233 |         { "lp87565-q1-regulator", },
      |           ^~~~~~~~~~~~~~~~~~~~~~
sound/soc/fsl/imx-pcm-rpmsg.c:818:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  818 |         { .name = "rpmsg-micfil-channel" },
      |                   ^~~~~~~~~~~~~~~~~~~~~~
drivers/iio/light/hid-sensor-als.c:457:25: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  457 |                 .name = "HID-SENSOR-LISS-0041",
      |                         ^~~~~~~~~~~~~~~~~~~~~~
drivers/iio/light/hid-sensor-prox.c:366:25: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (21 chars into 20 available) [-Wunterminated-string-initialization]
  366 |                 .name = "HID-SENSOR-LISS-0226",
      |                         ^~~~~~~~~~~~~~~~~~~~~~

Increase the length to 24, slightly more than is currently being used by
the affected drivers. The string is used in '%s' format strings and via
the module code, which appears to do its own length encoding. This size
was chosen because there was already a 4 byte hole in the structure:

struct platform_device_id {
        char                       name[20];             /*     0    20 */

        /* XXX 4 bytes hole, try to pack */

        kernel_ulong_t             driver_data;          /*    24     8 */

        /* size: 32, cachelines: 1, members: 2 */
        /* sum members: 28, holes: 1, sum holes: 4 */
        /* last cacheline: 32 bytes */
};

Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Nipun Gupta <nipun.gupta@amd.com>
Cc: Nikhil Agarwal <nikhil.agarwal@amd.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/mod_devicetable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index dde836875deb..6077972e8b45 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -601,7 +601,7 @@ struct dmi_system_id {
 #define DMI_MATCH(a, b)	{ .slot = a, .substr = b }
 #define DMI_EXACT_MATCH(a, b)	{ .slot = a, .substr = b, .exact_match = 1 }
 
-#define PLATFORM_NAME_SIZE	20
+#define PLATFORM_NAME_SIZE	24
 #define PLATFORM_MODULE_PREFIX	"platform:"
 
 struct platform_device_id {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-04 23:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 23:14 [PATCH] mod_devicetable: Enlarge the maximum platform_device_id name length Kees Cook
2025-04-16  6:45 ` Andy Shevchenko
2025-07-04 23:49   ` Vitaly Chikunov
2025-04-21 21:30 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox