Skip to content

Commit be0d8f4

Browse files
committed
bcache: Silence memcpy() run-time false positive warnings
struct bkey has internal padding in a union, but it isn't always named the same (e.g. key ## _pad, key_p, etc). This makes it extremely hard for the compiler to reason about the available size of copies done against such keys. Use unsafe_memcpy() for now, to silence the many run-time false positive warnings: memcpy: detected field-spanning write (size 264) of single field "&i->j" at drivers/md/bcache/journal.c:152 (size 240) memcpy: detected field-spanning write (size 24) of single field "&b->key" at drivers/md/bcache/btree.c:939 (size 16) memcpy: detected field-spanning write (size 24) of single field "&temp.key" at drivers/md/bcache/extents.c:428 (size 16) Reported-by: Alexandre Pereira <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216785 Acked-by: Coly Li <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e6a7116 commit be0d8f4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
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;

0 commit comments

Comments
 (0)