Skip to content

Commit fc13a78

Browse files
committed
Merge tag 'hardening-v6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: "As usual, it's scattered changes all over. Patches touching things outside of our traditional areas in the tree have been Acked by maintainers or were trivial changes: - loadpin: remove unsupported MODULE_COMPRESS_NONE (Arulpandiyan Vadivel) - samples/check-exec: Fix script name (Mickaël Salaün) - yama: remove needless locking in yama_task_prctl() (Oleg Nesterov) - lib/string_choices: Sort by function name (R Sundar) - hardening: Allow default HARDENED_USERCOPY to be set at compile time (Mel Gorman) - uaccess: Split out compile-time checks into ucopysize.h - kbuild: clang: Support building UM with SUBARCH=i386 - x86: Enable i386 FORTIFY_SOURCE on Clang 16+ - ubsan/overflow: Rework integer overflow sanitizer option - Add missing __nonstring annotations for callers of memtostr*()/strtomem*() - Add __must_be_noncstr() and have memtostr*()/strtomem*() check for it - Introduce __nonstring_array for silencing future GCC 15 warnings" * tag 'hardening-v6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (26 commits) compiler_types: Introduce __nonstring_array hardening: Enable i386 FORTIFY_SOURCE on Clang 16+ x86/build: Remove -ffreestanding on i386 with GCC ubsan/overflow: Enable ignorelist parsing and add type filter ubsan/overflow: Enable pattern exclusions ubsan/overflow: Rework integer overflow sanitizer option to turn on everything samples/check-exec: Fix script name yama: don't abuse rcu_read_lock/get_task_struct in yama_task_prctl() kbuild: clang: Support building UM with SUBARCH=i386 loadpin: remove MODULE_COMPRESS_NONE as it is no longer supported lib/string_choices: Rearrange functions in sorted order string.h: Validate memtostr*()/strtomem*() arguments more carefully compiler.h: Introduce __must_be_noncstr() nilfs2: Mark on-disk strings as nonstring uapi: stddef.h: Introduce __kernel_nonstring x86/tdx: Mark message.bytes as nonstring string: kunit: Mark nonstring test strings as __nonstring scsi: qla2xxx: Mark device strings as nonstring scsi: mpt3sas: Mark device strings as nonstring scsi: mpi3mr: Mark device strings as nonstring ...
2 parents 06961fb + b688f36 commit fc13a78

36 files changed

+285
-153
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,9 @@
17851785
allocation boundaries as a proactive defense
17861786
against bounds-checking flaws in the kernel's
17871787
copy_to_user()/copy_from_user() interface.
1788-
on Perform hardened usercopy checks (default).
1788+
The default is determined by
1789+
CONFIG_HARDENED_USERCOPY_DEFAULT_ON.
1790+
on Perform hardened usercopy checks.
17891791
off Disable hardened usercopy checks.
17901792

17911793
hardlockup_all_cpu_backtrace=

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12591,6 +12591,7 @@ F: Documentation/ABI/testing/sysfs-kernel-warn_count
1259112591
F: arch/*/configs/hardening.config
1259212592
F: include/linux/overflow.h
1259312593
F: include/linux/randomize_kstack.h
12594+
F: include/linux/ucopysize.h
1259412595
F: kernel/configs/hardening.config
1259512596
F: lib/tests/usercopy_kunit.c
1259612597
F: mm/usercopy.c

arch/x86/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ ifeq ($(CONFIG_X86_32),y)
137137
include $(srctree)/arch/x86/Makefile_32.cpu
138138
KBUILD_CFLAGS += $(cflags-y)
139139

140-
# temporary until string.h is fixed
140+
ifneq ($(call clang-min-version, 160000),y)
141+
# https://github.com/llvm/llvm-project/issues/53645
141142
KBUILD_CFLAGS += -ffreestanding
143+
endif
142144

143145
ifeq ($(CONFIG_STACKPROTECTOR),y)
144146
ifeq ($(CONFIG_SMP),y)

arch/x86/coco/tdx/tdx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ static void __noreturn tdx_panic(const char *msg)
167167
/* Define register order according to the GHCI */
168168
struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; };
169169

170-
char str[64];
170+
char bytes[64] __nonstring;
171171
} message;
172172

173173
/* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
174-
strtomem_pad(message.str, msg, '\0');
174+
strtomem_pad(message.bytes, msg, '\0');
175175

176176
args.r8 = message.r8;
177177
args.r9 = message.r9;

drivers/message/fusion/mptsas.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,10 +2834,10 @@ struct rep_manu_reply{
28342834
u8 sas_format:1;
28352835
u8 reserved1:7;
28362836
u8 reserved2[3];
2837-
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
2838-
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
2839-
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
2840-
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
2837+
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN] __nonstring;
2838+
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN] __nonstring;
2839+
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN] __nonstring;
2840+
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN] __nonstring;
28412841
u16 component_id;
28422842
u8 component_revision_id;
28432843
u8 reserved3;

drivers/scsi/mpi3mr/mpi3mr_transport.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ struct rep_manu_reply {
105105
u8 reserved0[2];
106106
u8 sas_format;
107107
u8 reserved2[3];
108-
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
109-
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
110-
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
111-
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
108+
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN] __nonstring;
109+
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN] __nonstring;
110+
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN] __nonstring;
111+
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN] __nonstring;
112112
u16 component_id;
113113
u8 component_revision_id;
114114
u8 reserved3;

drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ typedef struct _MPI2_CONFIG_REPLY {
606606

607607
typedef struct _MPI2_CONFIG_PAGE_MAN_0 {
608608
MPI2_CONFIG_PAGE_HEADER Header; /*0x00 */
609-
U8 ChipName[16]; /*0x04 */
609+
U8 ChipName[16] __nonstring; /*0x04 */
610610
U8 ChipRevision[8]; /*0x14 */
611611
U8 BoardName[16]; /*0x1C */
612612
U8 BoardAssembly[16]; /*0x2C */

drivers/scsi/mpt3sas/mpt3sas_transport.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ struct rep_manu_reply {
328328
u8 reserved0[2];
329329
u8 sas_format;
330330
u8 reserved2[3];
331-
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
332-
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
333-
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
334-
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
331+
u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN] __nonstring;
332+
u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN] __nonstring;
333+
u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN] __nonstring;
334+
u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN] __nonstring;
335335
u16 component_id;
336336
u8 component_revision_id;
337337
u8 reserved3;

drivers/scsi/qla2xxx/qla_mr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ struct register_host_info {
282282
#define QLAFX00_TGT_NODE_LIST_SIZE (sizeof(uint32_t) * 32)
283283

284284
struct config_info_data {
285-
uint8_t model_num[16];
286-
uint8_t model_description[80];
285+
uint8_t model_num[16] __nonstring;
286+
uint8_t model_description[80] __nonstring;
287287
uint8_t reserved0[160];
288288
uint8_t symbolic_name[64];
289289
uint8_t serial_num[32];

include/linux/compiler.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,25 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
206206
#define __must_be_byte_array(a) __BUILD_BUG_ON_ZERO_MSG(!__is_byte_array(a), \
207207
"must be byte array")
208208

209+
/*
210+
* If the "nonstring" attribute isn't available, we have to return true
211+
* so the __must_*() checks pass when "nonstring" isn't supported.
212+
*/
213+
#if __has_attribute(__nonstring__) && defined(__annotated)
214+
#define __is_cstr(a) (!__annotated(a, nonstring))
215+
#define __is_noncstr(a) (__annotated(a, nonstring))
216+
#else
217+
#define __is_cstr(a) (true)
218+
#define __is_noncstr(a) (true)
219+
#endif
220+
209221
/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */
210222
#define __must_be_cstr(p) \
211-
__BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)")
223+
__BUILD_BUG_ON_ZERO_MSG(!__is_cstr(p), \
224+
"must be C-string (NUL-terminated)")
225+
#define __must_be_noncstr(p) \
226+
__BUILD_BUG_ON_ZERO_MSG(!__is_noncstr(p), \
227+
"must be non-C-string (not NUL-terminated)")
212228

213229
#endif /* __KERNEL__ */
214230

0 commit comments

Comments
 (0)