Skip to content

Commit befaa60

Browse files
committed
Merge tag 'hardening-v6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: "One of the more voluminous set of changes is for adding the new __counted_by annotation[1] to gain run-time bounds checking of dynamically sized arrays with UBSan. - Add LKDTM test for stuck CPUs (Mark Rutland) - Improve LKDTM selftest behavior under UBSan (Ricardo Cañuelo) - Refactor more 1-element arrays into flexible arrays (Gustavo A. R. Silva) - Analyze and replace strlcpy and strncpy uses (Justin Stitt, Azeem Shaikh) - Convert group_info.usage to refcount_t (Elena Reshetova) - Add __counted_by annotations (Kees Cook, Gustavo A. R. Silva) - Add Kconfig fragment for basic hardening options (Kees Cook, Lukas Bulwahn) - Fix randstruct GCC plugin performance mode to stay in groups (Kees Cook) - Fix strtomem() compile-time check for small sources (Kees Cook)" * tag 'hardening-v6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (56 commits) hwmon: (acpi_power_meter) replace open-coded kmemdup_nul reset: Annotate struct reset_control_array with __counted_by kexec: Annotate struct crash_mem with __counted_by virtio_console: Annotate struct port_buffer with __counted_by ima: Add __counted_by for struct modsig and use struct_size() MAINTAINERS: Include stackleak paths in hardening entry string: Adjust strtomem() logic to allow for smaller sources hardening: x86: drop reference to removed config AMD_IOMMU_V2 randstruct: Fix gcc-plugin performance mode to stay in group mailbox: zynqmp: Annotate struct zynqmp_ipi_pdata with __counted_by drivers: thermal: tsens: Annotate struct tsens_priv with __counted_by irqchip/imx-intmux: Annotate struct intmux_data with __counted_by KVM: Annotate struct kvm_irq_routing_table with __counted_by virt: acrn: Annotate struct vm_memory_region_batch with __counted_by hwmon: Annotate struct gsc_hwmon_platform_data with __counted_by sparc: Annotate struct cpuinfo_tree with __counted_by isdn: kcapi: replace deprecated strncpy with strscpy_pad isdn: replace deprecated strncpy with strscpy NFS/flexfiles: Annotate struct nfs4_ff_layout_segment with __counted_by nfs41: Annotate struct nfs4_file_layout_dsaddr with __counted_by ...
2 parents fdce8bd + 9cca73d commit befaa60

60 files changed

Lines changed: 280 additions & 90 deletions

File tree

Some content is hidden

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

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8649,6 +8649,8 @@ L: linux-hardening@vger.kernel.org
86498649
S: Maintained
86508650
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
86518651
F: Documentation/kbuild/gcc-plugins.rst
8652+
F: include/linux/stackleak.h
8653+
F: kernel/stackleak.c
86528654
F: scripts/Makefile.gcc-plugins
86538655
F: scripts/gcc-plugins/
86548656

@@ -11415,16 +11417,20 @@ F: usr/
1141511417

1141611418
KERNEL HARDENING (not covered by other areas)
1141711419
M: Kees Cook <keescook@chromium.org>
11420+
R: Gustavo A. R. Silva <gustavoars@kernel.org>
1141811421
L: linux-hardening@vger.kernel.org
1141911422
S: Supported
1142011423
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
1142111424
F: Documentation/ABI/testing/sysfs-kernel-oops_count
1142211425
F: Documentation/ABI/testing/sysfs-kernel-warn_count
11426+
F: arch/*/configs/hardening.config
1142311427
F: include/linux/overflow.h
1142411428
F: include/linux/randomize_kstack.h
11429+
F: kernel/configs/hardening.config
1142511430
F: mm/usercopy.c
1142611431
K: \b(add|choose)_random_kstack_offset\b
1142711432
K: \b__check_(object_size|heap_object)\b
11433+
K: \b__counted_by\b
1142811434

1142911435
KERNEL JANITORS
1143011436
L: kernel-janitors@vger.kernel.org

arch/arm/configs/hardening.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Basic kernel hardening options (specific to arm)
2+
3+
# Make sure PXN/PAN emulation is enabled.
4+
CONFIG_CPU_SW_DOMAIN_PAN=y
5+
6+
# Dangerous; old interfaces and needless additional attack surface.
7+
# CONFIG_OABI_COMPAT is not set
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Basic kernel hardening options (specific to arm64)
2+
3+
# Make sure PAN emulation is enabled.
4+
CONFIG_ARM64_SW_TTBR0_PAN=y
5+
6+
# Software Shadow Stack or PAC
7+
CONFIG_SHADOW_CALL_STACK=y
8+
9+
# Pointer authentication (ARMv8.3 and later). If hardware actually supports
10+
# it, one can turn off CONFIG_STACKPROTECTOR_STRONG with this enabled.
11+
CONFIG_ARM64_PTR_AUTH=y
12+
CONFIG_ARM64_PTR_AUTH_KERNEL=y
13+
14+
# Available in ARMv8.5 and later.
15+
CONFIG_ARM64_BTI=y
16+
CONFIG_ARM64_BTI_KERNEL=y
17+
CONFIG_ARM64_MTE=y
18+
CONFIG_KASAN_HW_TAGS=y
19+
CONFIG_ARM64_E0PD=y
20+
21+
# Available in ARMv8.7 and later.
22+
CONFIG_ARM64_EPAN=y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# PowerPC specific hardening options
2+
3+
# Block kernel from unexpectedly reading userspace memory.
4+
CONFIG_PPC_KUAP=y
5+
6+
# Attack surface reduction.
7+
# CONFIG_SCOM_DEBUGFS is not set
8+
9+
# Disable internal kernel debugger.
10+
# CONFIG_XMON is not set

arch/sparc/kernel/cpumap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct cpuinfo_tree {
5050

5151
/* Offsets into nodes[] for each level of the tree */
5252
struct cpuinfo_level level[CPUINFO_LVL_MAX];
53-
struct cpuinfo_node nodes[];
53+
struct cpuinfo_node nodes[] __counted_by(total_nodes);
5454
};
5555

5656

arch/um/os-Linux/drivers/ethertap_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
105105
sprintf(data_fd_buf, "%d", data_remote);
106106
sprintf(version_buf, "%d", UML_NET_VERSION);
107107
if (gate != NULL) {
108-
strncpy(gate_buf, gate, 15);
108+
strscpy(gate_buf, gate, sizeof(gate_buf));
109109
args = setup_args;
110110
}
111111
else args = nosetup_args;

arch/x86/configs/hardening.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Basic kernel hardening options (specific to x86)
2+
3+
# Modern libc no longer needs a fixed-position mapping in userspace, remove
4+
# it as a possible target.
5+
CONFIG_LEGACY_VSYSCALL_NONE=y
6+
7+
# Enable chip-specific IOMMU support.
8+
CONFIG_INTEL_IOMMU=y
9+
CONFIG_INTEL_IOMMU_DEFAULT_ON=y
10+
CONFIG_INTEL_IOMMU_SVM=y
11+
CONFIG_AMD_IOMMU=y
12+
13+
# Enable CET Shadow Stack for userspace.
14+
CONFIG_X86_USER_SHADOW_STACK=y

drivers/accel/ivpu/ivpu_job.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct ivpu_job {
5151
u32 job_id;
5252
u32 engine_idx;
5353
size_t bo_count;
54-
struct ivpu_bo *bos[];
54+
struct ivpu_bo *bos[] __counted_by(bo_count);
5555
};
5656

5757
int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file);

drivers/auxdisplay/panel.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,10 +1449,9 @@ static struct logical_input *panel_bind_key(const char *name, const char *press,
14491449
key->rise_time = 1;
14501450
key->fall_time = 1;
14511451

1452-
strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1453-
strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1454-
strncpy(key->u.kbd.release_str, release,
1455-
sizeof(key->u.kbd.release_str));
1452+
strtomem_pad(key->u.kbd.press_str, press, '\0');
1453+
strtomem_pad(key->u.kbd.repeat_str, repeat, '\0');
1454+
strtomem_pad(key->u.kbd.release_str, release, '\0');
14561455
list_add(&key->list, &logical_inputs);
14571456
return key;
14581457
}

drivers/block/drbd/drbd_int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ struct fifo_buffer {
555555
unsigned int head_index;
556556
unsigned int size;
557557
int total; /* sum of all values */
558-
int values[];
558+
int values[] __counted_by(size);
559559
};
560560
extern struct fifo_buffer *fifo_alloc(unsigned int fifo_size);
561561

0 commit comments

Comments
 (0)