Skip to content

Commit 28cca23

Browse files
committed
Merge tag 'hardening-v6.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening fixes from Kees Cook: - Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST - Reorganize gcc-plugin includes for GCC 13 - Silence bcache memcpy run-time false positive warnings * tag 'hardening-v6.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: bcache: Silence memcpy() run-time false positive warnings gcc-plugins: Reorganize gimple includes for GCC 13 kunit: memcpy: Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST
2 parents d786f0f + be0d8f4 commit 28cca23

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

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;

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/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)