Skip to content

Commit 64cd7de

Browse files
peiliiKent Overstreet
authored andcommitted
bcachefs: Fix kmalloc bug in __snapshot_t_mut
When allocating too huge a snapshot table, we should fail gracefully in __snapshot_t_mut() instead of fail in kmalloc(). Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=770e99b65e26fa023ab1 Tested-by: [email protected] Signed-off-by: Pei Li <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 64ee143 commit 64cd7de

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/bcachefs/snapshot.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ static noinline struct snapshot_t *__snapshot_t_mut(struct bch_fs *c, u32 id)
168168
size_t new_bytes = kmalloc_size_roundup(struct_size(new, s, idx + 1));
169169
size_t new_size = (new_bytes - sizeof(*new)) / sizeof(new->s[0]);
170170

171+
if (unlikely(new_bytes > INT_MAX))
172+
return NULL;
173+
171174
new = kvzalloc(new_bytes, GFP_KERNEL);
172175
if (!new)
173176
return NULL;

0 commit comments

Comments
 (0)