Skip to content

Commit 5c0f220

Browse files
committed
Merge branch 'for-linus/hardening' into for-next/hardening
2 parents 5a6b64a + be0d8f4 commit 5c0f220

File tree

9 files changed

+27
-6
lines changed

9 files changed

+27
-6
lines changed

drivers/firmware/google/coreboot_table.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ static int coreboot_table_populate(struct device *dev, void *ptr)
9393
for (i = 0; i < header->table_entries; i++) {
9494
entry = ptr_entry;
9595

96-
device = kzalloc(sizeof(struct device) + entry->size, GFP_KERNEL);
96+
if (entry->size < sizeof(*entry)) {
97+
dev_warn(dev, "coreboot table entry too small!\n");
98+
return -EINVAL;
99+
}
100+
101+
device = kzalloc(sizeof(device->dev) + entry->size, GFP_KERNEL);
97102
if (!device)
98103
return -ENOMEM;
99104

100105
device->dev.parent = dev;
101106
device->dev.bus = &coreboot_bus_type;
102107
device->dev.release = coreboot_device_release;
103-
memcpy(&device->entry, ptr_entry, entry->size);
108+
memcpy(device->raw, ptr_entry, entry->size);
104109

105110
switch (device->entry.tag) {
106111
case LB_TAG_CBMEM_ENTRY:

drivers/firmware/google/coreboot_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct coreboot_device {
7979
struct lb_cbmem_ref cbmem_ref;
8080
struct lb_cbmem_entry cbmem_entry;
8181
struct lb_framebuffer framebuffer;
82+
DECLARE_FLEX_ARRAY(u8, raw);
8283
};
8384
};
8485

drivers/md/bcache/bcache_ondisk.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static inline unsigned long bkey_bytes(const struct bkey *k)
106106
return bkey_u64s(k) * sizeof(__u64);
107107
}
108108

109-
#define bkey_copy(_dest, _src) memcpy(_dest, _src, bkey_bytes(_src))
109+
#define bkey_copy(_dest, _src) unsafe_memcpy(_dest, _src, bkey_bytes(_src), \
110+
/* bkey is always padded */)
110111

111112
static inline void bkey_copy_key(struct bkey *dest, const struct bkey *src)
112113
{

drivers/md/bcache/journal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ reread: left = ca->sb.bucket_size - offset;
149149
bytes, GFP_KERNEL);
150150
if (!i)
151151
return -ENOMEM;
152-
memcpy(&i->j, j, bytes);
152+
unsafe_memcpy(&i->j, j, bytes,
153+
/* "bytes" was calculated by set_bytes() above */);
153154
/* Add to the location after 'where' points to */
154155
list_add(&i->list, where);
155156
ret = 1;

init/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ include/generated/utsversion.h: FORCE
5959

6060
$(obj)/version-timestamp.o: include/generated/utsversion.h
6161
CFLAGS_version-timestamp.o := -include include/generated/utsversion.h
62+
KASAN_SANITIZE_version-timestamp.o := n

lib/Kconfig.debug

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,15 @@ config MEMCPY_KUNIT_TEST
25662566

25672567
If unsure, say N.
25682568

2569+
config MEMCPY_SLOW_KUNIT_TEST
2570+
bool "Include exhaustive memcpy tests"
2571+
depends on MEMCPY_KUNIT_TEST
2572+
default y
2573+
help
2574+
Some memcpy tests are quite exhaustive in checking for overlaps
2575+
and bit ranges. These can be very slow, so they are split out
2576+
as a separate config, in case they need to be disabled.
2577+
25692578
config IS_SIGNED_TYPE_KUNIT_TEST
25702579
tristate "Test is_signed_type() macro" if !KUNIT_ALL_TESTS
25712580
depends on KUNIT

lib/memcpy_kunit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ static void set_random_nonzero(struct kunit *test, u8 *byte)
309309

310310
static void init_large(struct kunit *test)
311311
{
312+
if (!IS_ENABLED(CONFIG_MEMCPY_SLOW_KUNIT_TEST))
313+
kunit_skip(test, "Slow test skipped. Enable with CONFIG_MEMCPY_SLOW_KUNIT_TEST=y");
312314

313315
/* Get many bit patterns. */
314316
get_random_bytes(large_src, ARRAY_SIZE(large_src));

scripts/Makefile.vmlinux

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ quiet_cmd_cc_o_c = CC $@
1818
$(call if_changed_dep,cc_o_c)
1919

2020
ifdef CONFIG_MODULES
21+
KASAN_SANITIZE_.vmlinux.export.o := n
2122
targets += .vmlinux.export.o
2223
vmlinux: .vmlinux.export.o
2324
endif

scripts/gcc-plugins/gcc-common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
#include "varasm.h"
7272
#include "stor-layout.h"
7373
#include "internal-fn.h"
74+
#include "gimple.h"
7475
#include "gimple-expr.h"
76+
#include "gimple-iterator.h"
7577
#include "gimple-fold.h"
7678
#include "context.h"
7779
#include "tree-ssa-alias.h"
@@ -85,10 +87,8 @@
8587
#include "tree-eh.h"
8688
#include "stmt.h"
8789
#include "gimplify.h"
88-
#include "gimple.h"
8990
#include "tree-phinodes.h"
9091
#include "tree-cfg.h"
91-
#include "gimple-iterator.h"
9292
#include "gimple-ssa.h"
9393
#include "ssa-iterators.h"
9494

0 commit comments

Comments
 (0)