Skip to content

Commit 87caef4

Browse files
committed
Merge tag 'hardening-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: "The bulk of the changes here are related to refactoring and expanding the KUnit tests for string helper and fortify behavior. Some trivial strncpy replacements in fs/ were carried in my tree. Also some fixes to SCSI string handling were carried in my tree since the helper for those was introduce here. Beyond that, just little fixes all around: objtool getting confused about LKDTM+KCFI, preparing for future refactors (constification of sysctl tables, additional __counted_by annotations), a Clang UBSAN+i386 crash fix, and adding more options in the hardening.config Kconfig fragment. Summary: - selftests: Add str*cmp tests (Ivan Orlov) - __counted_by: provide UAPI for _le/_be variants (Erick Archer) - Various strncpy deprecation refactors (Justin Stitt) - stackleak: Use a copy of soon-to-be-const sysctl table (Thomas Weißschuh) - UBSAN: Work around i386 -regparm=3 bug with Clang prior to version 19 - Provide helper to deal with non-NUL-terminated string copying - SCSI: Fix older string copying bugs (with new helper) - selftests: Consolidate string helper behavioral tests - selftests: add memcpy() fortify tests - string: Add additional __realloc_size() annotations for "dup" helpers - LKDTM: Fix KCFI+rodata+objtool confusion - hardening.config: Enable KCFI" * tag 'hardening-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (29 commits) uapi: stddef.h: Provide UAPI macros for __counted_by_{le, be} stackleak: Use a copy of the ctl_table argument string: Add additional __realloc_size() annotations for "dup" helpers kunit/fortify: Fix replaced failure path to unbreak __alloc_size hardening: Enable KCFI and some other options lkdtm: Disable CFI checking for perms functions kunit/fortify: Add memcpy() tests kunit/fortify: Do not spam logs with fortify WARNs kunit/fortify: Rename tests to use recommended conventions init: replace deprecated strncpy with strscpy_pad kunit/fortify: Fix mismatched kvalloc()/vfree() usage scsi: qla2xxx: Avoid possible run-time warning with long model_num scsi: mpi3mr: Avoid possible run-time warning with long manufacturer strings scsi: mptfusion: Avoid possible run-time warning with long manufacturer strings fs: ecryptfs: replace deprecated strncpy with strscpy hfsplus: refactor copy_name to not use strncpy reiserfs: replace deprecated strncpy with scnprintf virt: acrn: replace deprecated strncpy with strscpy ubsan: Avoid i386 UBSAN handler crashes with Clang ubsan: Remove 1-element array usage in debug reporting ...
2 parents 92f74f7 + 6d305cb commit 87caef4

File tree

27 files changed

+768
-477
lines changed

27 files changed

+768
-477
lines changed

MAINTAINERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8463,8 +8463,6 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/har
84638463
F: include/linux/fortify-string.h
84648464
F: lib/fortify_kunit.c
84658465
F: lib/memcpy_kunit.c
8466-
F: lib/strcat_kunit.c
8467-
F: lib/strscpy_kunit.c
84688466
F: lib/test_fortify/*
84698467
F: scripts/test_fortify.sh
84708468
K: \b__NO_FORTIFY\b
@@ -22691,6 +22689,7 @@ F: include/linux/ubsan.h
2269122689
F: lib/Kconfig.ubsan
2269222690
F: lib/test_ubsan.c
2269322691
F: lib/ubsan.c
22692+
F: lib/ubsan.h
2269422693
F: scripts/Makefile.ubsan
2269522694
K: \bARCH_HAS_UBSAN\b
2269622695

arch/arm64/configs/hardening.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CONFIG_ARM64_SW_TTBR0_PAN=y
55

66
# Software Shadow Stack or PAC
77
CONFIG_SHADOW_CALL_STACK=y
8+
CONFIG_UNWIND_PATCH_PAC_INTO_SCS=y
89

910
# Pointer authentication (ARMv8.3 and later). If hardware actually supports
1011
# it, one can turn off CONFIG_STACKPROTECTOR_STRONG with this enabled.

arch/x86/configs/hardening.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ CONFIG_INTEL_IOMMU_DEFAULT_ON=y
1010
CONFIG_INTEL_IOMMU_SVM=y
1111
CONFIG_AMD_IOMMU=y
1212

13+
# Enforce CET Indirect Branch Tracking in the kernel.
14+
CONFIG_X86_KERNEL_IBT=y
15+
1316
# Enable CET Shadow Stack for userspace.
1417
CONFIG_X86_USER_SHADOW_STACK=y

drivers/message/fusion/mptsas.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,17 +2964,13 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
29642964
goto out_free;
29652965

29662966
manufacture_reply = data_out + sizeof(struct rep_manu_request);
2967-
strscpy(edev->vendor_id, manufacture_reply->vendor_id,
2968-
sizeof(edev->vendor_id));
2969-
strscpy(edev->product_id, manufacture_reply->product_id,
2970-
sizeof(edev->product_id));
2971-
strscpy(edev->product_rev, manufacture_reply->product_rev,
2972-
sizeof(edev->product_rev));
2967+
memtostr(edev->vendor_id, manufacture_reply->vendor_id);
2968+
memtostr(edev->product_id, manufacture_reply->product_id);
2969+
memtostr(edev->product_rev, manufacture_reply->product_rev);
29732970
edev->level = manufacture_reply->sas_format;
29742971
if (manufacture_reply->sas_format) {
2975-
strscpy(edev->component_vendor_id,
2976-
manufacture_reply->component_vendor_id,
2977-
sizeof(edev->component_vendor_id));
2972+
memtostr(edev->component_vendor_id,
2973+
manufacture_reply->component_vendor_id);
29782974
tmp = (u8 *)&manufacture_reply->component_id;
29792975
edev->component_id = tmp[0] << 8 | tmp[1];
29802976
edev->component_revision_id =

drivers/misc/lkdtm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ KASAN_SANITIZE_rodata.o := n
1919
KCSAN_SANITIZE_rodata.o := n
2020
KCOV_INSTRUMENT_rodata.o := n
2121
OBJECT_FILES_NON_STANDARD_rodata.o := y
22-
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO) $(RETHUNK_CFLAGS)
22+
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO) $(RETHUNK_CFLAGS) $(CC_FLAGS_CFI)
2323

2424
OBJCOPYFLAGS :=
2525
OBJCOPYFLAGS_rodata_objcopy.o := \

drivers/misc/lkdtm/perms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void *setup_function_descriptor(func_desc_t *fdesc, void *dst)
6161
return fdesc;
6262
}
6363

64-
static noinline void execute_location(void *dst, bool write)
64+
static noinline __nocfi void execute_location(void *dst, bool write)
6565
{
6666
void (*func)(void);
6767
func_desc_t fdesc;

drivers/scsi/mpi3mr/mpi3mr_transport.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,13 @@ static int mpi3mr_report_manufacture(struct mpi3mr_ioc *mrioc,
209209
goto out;
210210
}
211211

212-
strscpy(edev->vendor_id, manufacture_reply->vendor_id,
213-
SAS_EXPANDER_VENDOR_ID_LEN);
214-
strscpy(edev->product_id, manufacture_reply->product_id,
215-
SAS_EXPANDER_PRODUCT_ID_LEN);
216-
strscpy(edev->product_rev, manufacture_reply->product_rev,
217-
SAS_EXPANDER_PRODUCT_REV_LEN);
212+
memtostr(edev->vendor_id, manufacture_reply->vendor_id);
213+
memtostr(edev->product_id, manufacture_reply->product_id);
214+
memtostr(edev->product_rev, manufacture_reply->product_rev);
218215
edev->level = manufacture_reply->sas_format & 1;
219216
if (edev->level) {
220-
strscpy(edev->component_vendor_id,
221-
manufacture_reply->component_vendor_id,
222-
SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
217+
memtostr(edev->component_vendor_id,
218+
manufacture_reply->component_vendor_id);
223219
tmp = (u8 *)&manufacture_reply->component_id;
224220
edev->component_id = tmp[0] << 8 | tmp[1];
225221
edev->component_revision_id =

drivers/scsi/qla2xxx/qla_mr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,8 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, uint16_t fx_type)
19091909
if (fx_type == FXDISC_GET_CONFIG_INFO) {
19101910
struct config_info_data *pinfo =
19111911
(struct config_info_data *) fdisc->u.fxiocb.rsp_addr;
1912-
strscpy(vha->hw->model_number, pinfo->model_num,
1913-
ARRAY_SIZE(vha->hw->model_number));
1914-
strscpy(vha->hw->model_desc, pinfo->model_description,
1915-
ARRAY_SIZE(vha->hw->model_desc));
1912+
memtostr(vha->hw->model_number, pinfo->model_num);
1913+
memtostr(vha->hw->model_desc, pinfo->model_description);
19161914
memcpy(&vha->hw->mr.symbolic_name, pinfo->symbolic_name,
19171915
sizeof(vha->hw->mr.symbolic_name));
19181916
memcpy(&vha->hw->mr.serial_num, pinfo->serial_num,

drivers/virt/acrn/ioreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ struct acrn_ioreq_client *acrn_ioreq_client_create(struct acrn_vm *vm,
433433
client->priv = priv;
434434
client->is_default = is_default;
435435
if (name)
436-
strncpy(client->name, name, sizeof(client->name) - 1);
436+
strscpy(client->name, name);
437437
rwlock_init(&client->range_lock);
438438
INIT_LIST_HEAD(&client->range_list);
439439
init_waitqueue_head(&client->wq);

fs/ecryptfs/crypto.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,9 +1606,7 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
16061606
goto out;
16071607
}
16081608
mutex_init(&tmp_tfm->key_tfm_mutex);
1609-
strncpy(tmp_tfm->cipher_name, cipher_name,
1610-
ECRYPTFS_MAX_CIPHER_NAME_SIZE);
1611-
tmp_tfm->cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
1609+
strscpy(tmp_tfm->cipher_name, cipher_name);
16121610
tmp_tfm->key_size = key_size;
16131611
rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm,
16141612
tmp_tfm->cipher_name,

0 commit comments

Comments
 (0)