[PATCH] bcachefs: Add check for the size of combined key and value

zhanghao posted 1 patch 1 year, 4 months ago
There is a newer version of this series
fs/bcachefs/bkey_types.h | 2 ++
1 file changed, 2 insertions(+)
[PATCH] bcachefs: Add check for the size of combined key and value
Posted by zhanghao 1 year, 4 months ago
The bkey_val_bytes() gets the number of bytes of value
stored in bkey->u64s.If u64s is smaller than BKEY_U64s,
it causes a negative number to be converted to an
unsigned number.

Reported-by: syzbot+1a11884d9c9f1353942d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1a11884d9c9f1353942d
Fixes: ba81523eaac3 ("bcachefs: Split out bkey_types.h")
Link: https://lore.kernel.org/all/00000000000025321f061d7b62ff@google.com/T/

Signed-off-by: zhanghao <zhanghao1@kylinos.cn>
---
 fs/bcachefs/bkey_types.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/bcachefs/bkey_types.h b/fs/bcachefs/bkey_types.h
index c9ae9e42b385..60fa5af93032 100644
--- a/fs/bcachefs/bkey_types.h
+++ b/fs/bcachefs/bkey_types.h
@@ -21,6 +21,8 @@ static inline struct bkey_i *bkey_next(struct bkey_i *k)
 
 static inline size_t bkey_val_bytes(const struct bkey *k)
 {
+	if (k->u64s < BKEY_U64s)
+		return 0;
 	return bkey_val_u64s(k) * sizeof(u64);
 }
 

base-commit: defaf1a2113a22b00dfa1abc0fd2014820eaf065
prerequisite-patch-id: 1ec511753fc7aab35ba0e982013cf91ba4403da6
-- 
2.39.2