提交 be0d8f48 编写于 作者: K Kees Cook

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: NAlexandre Pereira <alexpereira@disroot.org>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216785Acked-by: NColy Li <colyli@suse.de>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-bcache@vger.kernel.org
Signed-off-by: NKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230106060229.never.047-kees@kernel.org
上级 e6a71160
...@@ -106,7 +106,8 @@ static inline unsigned long bkey_bytes(const struct bkey *k) ...@@ -106,7 +106,8 @@ static inline unsigned long bkey_bytes(const struct bkey *k)
return bkey_u64s(k) * sizeof(__u64); return bkey_u64s(k) * sizeof(__u64);
} }
#define bkey_copy(_dest, _src) memcpy(_dest, _src, bkey_bytes(_src)) #define bkey_copy(_dest, _src) unsafe_memcpy(_dest, _src, bkey_bytes(_src), \
/* bkey is always padded */)
static inline void bkey_copy_key(struct bkey *dest, const struct bkey *src) static inline void bkey_copy_key(struct bkey *dest, const struct bkey *src)
{ {
......
...@@ -149,7 +149,8 @@ reread: left = ca->sb.bucket_size - offset; ...@@ -149,7 +149,8 @@ reread: left = ca->sb.bucket_size - offset;
bytes, GFP_KERNEL); bytes, GFP_KERNEL);
if (!i) if (!i)
return -ENOMEM; return -ENOMEM;
memcpy(&i->j, j, bytes); unsafe_memcpy(&i->j, j, bytes,
/* "bytes" was calculated by set_bytes() above */);
/* Add to the location after 'where' points to */ /* Add to the location after 'where' points to */
list_add(&i->list, where); list_add(&i->list, where);
ret = 1; ret = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册