Skip to content

Commit 4a7d37e

Browse files
committed
Merge tag 'hardening-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: "Beyond some specific LoadPin, UBSAN, and fortify features, there are other fixes scattered around in various subsystems where maintainers were okay with me carrying them in my tree or were non-responsive but the patches were reviewed by others: - Replace 0-length and 1-element arrays with flexible arrays in various subsystems (Paulo Miguel Almeida, Stephen Rothwell, Kees Cook) - randstruct: Disable Clang 15 support (Eric Biggers) - GCC plugins: Drop -std=gnu++11 flag (Sam James) - strpbrk(): Refactor to use strchr() (Andy Shevchenko) - LoadPin LSM: Allow root filesystem switching when non-enforcing - fortify: Use dynamic object size hints when available - ext4: Fix CFI function prototype mismatch - Nouveau: Fix DP buffer size arguments - hisilicon: Wipe entire crypto DMA pool on error - coda: Fully allocate sig_inputArgs - UBSAN: Improve arm64 trap code reporting - copy_struct_from_user(): Add minimum bounds check on kernel buffer size" * tag 'hardening-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: randstruct: disable Clang 15 support uaccess: Add minimum bounds check on kernel buffer size arm64: Support Clang UBSAN trap codes for better reporting coda: Avoid partial allocation of sig_inputArgs gcc-plugins: drop -std=gnu++11 to fix GCC 13 build lib/string: Use strchr() in strpbrk() crypto: hisilicon: Wipe entire pool on error net/i40e: Replace 0-length array with flexible array io_uring: Replace 0-length array with flexible array ext4: Fix function prototype mismatch for ext4_feat_ktype i915/gvt: Replace one-element array with flexible-array member drm/nouveau/disp: Fix nvif_outp_acquire_dp() argument size LoadPin: Allow filesystem switch when not enforcing LoadPin: Move pin reporting cleanly out of locking LoadPin: Refactor sysctl initialization LoadPin: Refactor read-only check into a helper ARM: ixp4xx: Replace 0-length arrays with flexible arrays fortify: Use __builtin_dynamic_object_size() when available rxrpc: replace zero-lenth array with DECLARE_FLEX_ARRAY() helper
2 parents 902d9fc + 78f7a3f commit 4a7d37e

File tree

24 files changed

+229
-60
lines changed

24 files changed

+229
-60
lines changed

arch/arm64/include/asm/brk-imm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* 0x401: for compile time BRK instruction
1818
* 0x800: kernel-mode BUG() and WARN() traps
1919
* 0x9xx: tag-based KASAN trap (allowed values 0x900 - 0x9ff)
20+
* 0x55xx: Undefined Behavior Sanitizer traps ('U' << 8)
2021
* 0x8xxx: Control-Flow Integrity traps
2122
*/
2223
#define KPROBES_BRK_IMM 0x004
@@ -28,6 +29,8 @@
2829
#define BUG_BRK_IMM 0x800
2930
#define KASAN_BRK_IMM 0x900
3031
#define KASAN_BRK_MASK 0x0ff
32+
#define UBSAN_BRK_IMM 0x5500
33+
#define UBSAN_BRK_MASK 0x00ff
3134

3235
#define CFI_BRK_IMM_TARGET GENMASK(4, 0)
3336
#define CFI_BRK_IMM_TYPE GENMASK(9, 5)

arch/arm64/kernel/traps.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/syscalls.h>
2727
#include <linux/mm_types.h>
2828
#include <linux/kasan.h>
29+
#include <linux/ubsan.h>
2930
#include <linux/cfi.h>
3031

3132
#include <asm/atomic.h>
@@ -1074,6 +1075,19 @@ static struct break_hook kasan_break_hook = {
10741075
};
10751076
#endif
10761077

1078+
#ifdef CONFIG_UBSAN_TRAP
1079+
static int ubsan_handler(struct pt_regs *regs, unsigned long esr)
1080+
{
1081+
die(report_ubsan_failure(regs, esr & UBSAN_BRK_MASK), regs, esr);
1082+
return DBG_HOOK_HANDLED;
1083+
}
1084+
1085+
static struct break_hook ubsan_break_hook = {
1086+
.fn = ubsan_handler,
1087+
.imm = UBSAN_BRK_IMM,
1088+
.mask = UBSAN_BRK_MASK,
1089+
};
1090+
#endif
10771091

10781092
#define esr_comment(esr) ((esr) & ESR_ELx_BRK64_ISS_COMMENT_MASK)
10791093

@@ -1091,6 +1105,10 @@ int __init early_brk64(unsigned long addr, unsigned long esr,
10911105
#ifdef CONFIG_KASAN_SW_TAGS
10921106
if ((esr_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM)
10931107
return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;
1108+
#endif
1109+
#ifdef CONFIG_UBSAN_TRAP
1110+
if ((esr_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM)
1111+
return ubsan_handler(regs, esr) != DBG_HOOK_HANDLED;
10941112
#endif
10951113
return bug_handler(regs, esr) != DBG_HOOK_HANDLED;
10961114
}
@@ -1104,6 +1122,9 @@ void __init trap_init(void)
11041122
register_kernel_break_hook(&fault_break_hook);
11051123
#ifdef CONFIG_KASAN_SW_TAGS
11061124
register_kernel_break_hook(&kasan_break_hook);
1125+
#endif
1126+
#ifdef CONFIG_UBSAN_TRAP
1127+
register_kernel_break_hook(&ubsan_break_hook);
11071128
#endif
11081129
debug_traps_init();
11091130
}

drivers/crypto/hisilicon/sgl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
124124
for (j = 0; j < i; j++) {
125125
dma_free_coherent(dev, block_size, block[j].sgl,
126126
block[j].sgl_dma);
127-
memset(block + j, 0, sizeof(*block));
128127
}
129-
kfree(pool);
128+
kfree_sensitive(pool);
130129
return ERR_PTR(-ENOMEM);
131130
}
132131
EXPORT_SYMBOL_GPL(hisi_acc_create_sgl_pool);

drivers/gpu/drm/i915/gvt/firmware.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct gvt_firmware_header {
4545
u64 cfg_space_offset; /* offset in the file */
4646
u64 mmio_size;
4747
u64 mmio_offset; /* offset in the file */
48-
unsigned char data[1];
48+
unsigned char data[];
4949
};
5050

5151
#define dev_to_drm_minor(d) dev_get_drvdata((d))
@@ -77,7 +77,7 @@ static int expose_firmware_sysfs(struct intel_gvt *gvt)
7777
unsigned long size, crc32_start;
7878
int ret;
7979

80-
size = sizeof(*h) + info->mmio_size + info->cfg_space_size;
80+
size = offsetof(struct gvt_firmware_header, data) + info->mmio_size + info->cfg_space_size;
8181
firmware = vzalloc(size);
8282
if (!firmware)
8383
return -ENOMEM;

drivers/gpu/drm/nouveau/include/nvif/outp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define __NVIF_OUTP_H__
44
#include <nvif/object.h>
55
#include <nvif/if0012.h>
6+
#include <drm/display/drm_dp.h>
67
struct nvif_disp;
78

89
struct nvif_outp {
@@ -21,7 +22,7 @@ int nvif_outp_acquire_rgb_crt(struct nvif_outp *);
2122
int nvif_outp_acquire_tmds(struct nvif_outp *, int head,
2223
bool hdmi, u8 max_ac_packet, u8 rekey, u8 scdc, bool hda);
2324
int nvif_outp_acquire_lvds(struct nvif_outp *, bool dual, bool bpc8);
24-
int nvif_outp_acquire_dp(struct nvif_outp *, u8 dpcd[16],
25+
int nvif_outp_acquire_dp(struct nvif_outp *outp, u8 dpcd[DP_RECEIVER_CAP_SIZE],
2526
int link_nr, int link_bw, bool hda, bool mst);
2627
void nvif_outp_release(struct nvif_outp *);
2728
int nvif_outp_infoframe(struct nvif_outp *, u8 type, struct nvif_outp_infoframe_v0 *, u32 size);

drivers/gpu/drm/nouveau/nvif/outp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0
127127
}
128128

129129
int
130-
nvif_outp_acquire_dp(struct nvif_outp *outp, u8 dpcd[16],
130+
nvif_outp_acquire_dp(struct nvif_outp *outp, u8 dpcd[DP_RECEIVER_CAP_SIZE],
131131
int link_nr, int link_bw, bool hda, bool mst)
132132
{
133133
struct nvif_outp_acquire_v0 args;

drivers/misc/lkdtm/heap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void lkdtm_VMALLOC_LINEAR_OVERFLOW(void)
3131
char *one, *two;
3232

3333
one = vzalloc(PAGE_SIZE);
34+
OPTIMIZER_HIDE_VAR(one);
3435
two = vzalloc(PAGE_SIZE);
3536

3637
pr_info("Attempting vmalloc linear overflow ...\n");

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ enum i40e_interrupt_policy {
176176

177177
struct i40e_lump_tracking {
178178
u16 num_entries;
179-
u16 list[0];
179+
u16 list[];
180180
#define I40E_PILE_VALID_BIT 0x8000
181181
#define I40E_IWARP_IRQ_PILE_ID (I40E_PILE_VALID_BIT - 2)
182182
};

drivers/soc/ixp4xx/ixp4xx-npe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,15 @@ int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
519519
u32 id;
520520
u32 size;
521521
union {
522-
u32 data[0];
523-
struct dl_block blocks[0];
522+
DECLARE_FLEX_ARRAY(u32, data);
523+
DECLARE_FLEX_ARRAY(struct dl_block, blocks);
524524
};
525525
} *image;
526526

527527
struct dl_codeblock {
528528
u32 npe_addr;
529529
u32 size;
530-
u32 data[0];
530+
u32 data[];
531531
} *cb;
532532

533533
int i, j, err, data_size, instr_size, blocks, table_end;

fs/coda/upcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ static int coda_upcall(struct venus_comm *vcp,
791791
sig_req = kmalloc(sizeof(struct upc_req), GFP_KERNEL);
792792
if (!sig_req) goto exit;
793793

794-
sig_inputArgs = kvzalloc(sizeof(struct coda_in_hdr), GFP_KERNEL);
794+
sig_inputArgs = kvzalloc(sizeof(*sig_inputArgs), GFP_KERNEL);
795795
if (!sig_inputArgs) {
796796
kfree(sig_req);
797797
goto exit;

0 commit comments

Comments
 (0)