KSPP / linux

Linux kernel source tree (Kernel Self Protection Project)
https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project
Other
83 stars 5 forks source link

Address -Wstringop-overflow warning in arch/s390/kernel/setup.c #340

Open GustavoARSilva opened 1 year ago

GustavoARSilva commented 1 year ago

Seen under s390 and allyesconfig

In function 'strlcat',
    inlined from 'strcat' at include/linux/fortify-string.h:432:6,
    inlined from 'setup_zfcpdump' at arch/s390/kernel/setup.c:309:2,
    inlined from 'setup_arch' at arch/s390/kernel/setup.c:1009:2:
include/linux/fortify-string.h:57:33: warning: '__builtin_memcpy' writing 30 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
   57 | #define __underlying_memcpy     __builtin_memcpy
      |                                 ^
include/linux/fortify-string.h:405:9: note: in expansion of macro '__underlying_memcpy'
  405 |         __underlying_memcpy(p + p_len, q, copy_len);
      |         ^~~~~~~~~~~~~~~~~~~

Code to audit:

arch/s390/kernel/setup.c:

 302 #ifdef CONFIG_CRASH_DUMP
 303 static void __init setup_zfcpdump(void)
 304 {
 305         if (!is_ipl_type_dump())
 306                 return;
 307         if (oldmem_data.start)
 308                 return;
 @ 309         strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
 310         console_loglevel = 2;
 311 }
 312 #else
 313 static inline void setup_zfcpdump(void) {}
 314 #endif /* CONFIG_CRASH_DUMP */

init/main.c:

 137 /* Untouched command line saved by arch-specific code. */
 138 char boot_command_line[COMMAND_LINE_SIZE] __ro_after_init;

include/linux/init.h:

147 extern char boot_command_line[];

arch/s390/include/asm/setup.h:

 15 #define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE

arch/s390/Kconfig:

436 config COMMAND_LINE_SIZE
437         int "Maximum size of kernel command line"
438         default 4096
439         range 896 1048576
440         help
441           This allows you to specify the maximum length of the kernel command
442           line.