Skip to content

Commit 582c161

Browse files
committed
Merge tag 'hardening-v6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: "There are three areas of note: A bunch of strlcpy()->strscpy() conversions ended up living in my tree since they were either Acked by maintainers for me to carry, or got ignored for multiple weeks (and were trivial changes). The compiler option '-fstrict-flex-arrays=3' has been enabled globally, and has been in -next for the entire devel cycle. This changes compiler diagnostics (though mainly just -Warray-bounds which is disabled) and potential UBSAN_BOUNDS and FORTIFY _warning_ coverage. In other words, there are no new restrictions, just potentially new warnings. Any new FORTIFY warnings we've seen have been fixed (usually in their respective subsystem trees). For more details, see commit df8fc4e. The under-development compiler attribute __counted_by has been added so that we can start annotating flexible array members with their associated structure member that tracks the count of flexible array elements at run-time. It is possible (likely?) that the exact syntax of the attribute will change before it is finalized, but GCC and Clang are working together to sort it out. Any changes can be made to the macro while we continue to add annotations. As an example of that last case, I have a treewide commit waiting with such annotations found via Coccinelle: https://git.kernel.org/linus/adc5b3cb48a049563dc673f348eab7b6beba8a9b Also see commit dd06e72 for more details. Summary: - Fix KMSAN vs FORTIFY in strlcpy/strlcat (Alexander Potapenko) - Convert strreplace() to return string start (Andy Shevchenko) - Flexible array conversions (Arnd Bergmann, Wyes Karny, Kees Cook) - Add missing function prototypes seen with W=1 (Arnd Bergmann) - Fix strscpy() kerndoc typo (Arne Welzel) - Replace strlcpy() with strscpy() across many subsystems which were either Acked by respective maintainers or were trivial changes that went ignored for multiple weeks (Azeem Shaikh) - Remove unneeded cc-option test for UBSAN_TRAP (Nick Desaulniers) - Add KUnit tests for strcat()-family - Enable KUnit tests of FORTIFY wrappers under UML - Add more complete FORTIFY protections for strlcat() - Add missed disabling of FORTIFY for all arch purgatories. - Enable -fstrict-flex-arrays=3 globally - Tightening UBSAN_BOUNDS when using GCC - Improve checkpatch to check for strcpy, strncpy, and fake flex arrays - Improve use of const variables in FORTIFY - Add requested struct_size_t() helper for types not pointers - Add __counted_by macro for annotating flexible array size members" * tag 'hardening-v6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (54 commits) netfilter: ipset: Replace strlcpy with strscpy uml: Replace strlcpy with strscpy um: Use HOST_DIR for mrproper kallsyms: Replace all non-returning strlcpy with strscpy sh: Replace all non-returning strlcpy with strscpy of/flattree: Replace all non-returning strlcpy with strscpy sparc64: Replace all non-returning strlcpy with strscpy Hexagon: Replace all non-returning strlcpy with strscpy kobject: Use return value of strreplace() lib/string_helpers: Change returned value of the strreplace() jbd2: Avoid printing outside the boundary of the buffer checkpatch: Check for 0-length and 1-element arrays riscv/purgatory: Do not use fortified string functions s390/purgatory: Do not use fortified string functions x86/purgatory: Do not use fortified string functions acpi: Replace struct acpi_table_slit 1-element array with flex-array clocksource: Replace all non-returning strlcpy with strscpy string: use __builtin_memcpy() in strlcpy/strlcat staging: most: Replace all non-returning strlcpy with strscpy drm/i2c: tda998x: Replace all non-returning strlcpy with strscpy ...
2 parents 8ad7868 + acf15e0 commit 582c161

File tree

84 files changed

+467
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+467
-203
lines changed

Documentation/filesystems/autofs-mount-control.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ information and return operation results::
196196
struct args_ismountpoint ismountpoint;
197197
};
198198

199-
char path[0];
199+
char path[];
200200
};
201201

202202
The ioctlfd field is a mount point file descriptor of an autofs mount

Documentation/filesystems/autofs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ Each ioctl is passed a pointer to an `autofs_dev_ioctl` structure::
467467
struct args_ismountpoint ismountpoint;
468468
};
469469

470-
char path[0];
470+
char path[];
471471
};
472472

473473
For the **OPEN_MOUNT** and **IS_MOUNTPOINT** commands, the target

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8099,6 +8099,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/har
80998099
F: include/linux/fortify-string.h
81008100
F: lib/fortify_kunit.c
81018101
F: lib/memcpy_kunit.c
8102+
F: lib/strcat_kunit.c
81028103
F: lib/strscpy_kunit.c
81038104
F: lib/test_fortify/*
81048105
F: scripts/test_fortify.sh

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign
10261026
# globally built with -Wcast-function-type.
10271027
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
10281028

1029+
# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
1030+
# the kernel uses only C99 flexible arrays for dynamically sized trailing
1031+
# arrays. Enforce this for everything that may examine structure sizes and
1032+
# perform bounds checking.
1033+
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
1034+
10291035
# disable stringop warnings in gcc 8+
10301036
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
10311037

arch/hexagon/kernel/setup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ void __init setup_arch(char **cmdline_p)
6666
on_simulator = 0;
6767

6868
if (p[0] != '\0')
69-
strlcpy(boot_command_line, p, COMMAND_LINE_SIZE);
69+
strscpy(boot_command_line, p, COMMAND_LINE_SIZE);
7070
else
71-
strlcpy(boot_command_line, default_command_line,
71+
strscpy(boot_command_line, default_command_line,
7272
COMMAND_LINE_SIZE);
7373

7474
/*
7575
* boot_command_line and the value set up by setup_arch
7676
* are both picked up by the init code. If no reason to
7777
* make them different, pass the same pointer back.
7878
*/
79-
strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
79+
strscpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
8080
*cmdline_p = cmd_line;
8181

8282
parse_early_param();

arch/microblaze/kernel/prom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void __init early_init_devtree(void *params)
2020

2121
early_init_dt_scan(params);
2222
if (!strlen(boot_command_line))
23-
strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
23+
strscpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
2424

2525
memblock_allow_resize();
2626

arch/riscv/purgatory/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE
3131
$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
3232
$(call if_changed_rule,cc_o_c)
3333

34-
CFLAGS_sha256.o := -D__DISABLE_EXPORTS
34+
CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
3535
CFLAGS_string.o := -D__DISABLE_EXPORTS
3636
CFLAGS_ctype.o := -D__DISABLE_EXPORTS
3737

arch/s390/purgatory/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
1010
$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
1111
$(call if_changed_rule,cc_o_c)
1212

13-
CFLAGS_sha256.o := -D__DISABLE_EXPORTS
13+
CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
1414

1515
$(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE
1616
$(call if_changed_rule,as_o_S)

arch/sh/drivers/dma/dma-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int request_dma(unsigned int chan, const char *dev_id)
198198
if (atomic_xchg(&channel->busy, 1))
199199
return -EBUSY;
200200

201-
strlcpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
201+
strscpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
202202

203203
if (info->ops->request) {
204204
result = info->ops->request(channel);

arch/sh/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ void __init setup_arch(char **cmdline_p)
305305
bss_resource.end = virt_to_phys(__bss_stop)-1;
306306

307307
#ifdef CONFIG_CMDLINE_OVERWRITE
308-
strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
308+
strscpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
309309
#else
310-
strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
310+
strscpy(command_line, COMMAND_LINE, sizeof(command_line));
311311
#ifdef CONFIG_CMDLINE_EXTEND
312312
strlcat(command_line, " ", sizeof(command_line));
313313
strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));

0 commit comments

Comments
 (0)