]> www.infradead.org Git - linux.git/commitdiff
bcachefs: Fix a memory splat
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 18 Dec 2019 22:34:36 +0000 (17:34 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:33 +0000 (17:08 -0400)
In __bch2_sb_field_resize, when a field's old a new size was 0, we were
doing an invalid write just past the end of the superblock.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super-io.c

index cd1aa3891c2e46d64dff8725a2f97630ab7ee41e..4c1e8571d87241dfcfd662ba6ab2d7778b0193e9 100644 (file)
@@ -54,7 +54,9 @@ static struct bch_sb_field *__bch2_sb_field_resize(struct bch_sb_handle *sb,
        BUG_ON(get_order(__vstruct_bytes(struct bch_sb, sb_u64s)) >
               sb->page_order);
 
-       if (!f) {
+       if (!f && !u64s) {
+               /* nothing to do: */
+       } else if (!f) {
                f = vstruct_last(sb->sb);
                memset(f, 0, sizeof(u64) * u64s);
                f->u64s = cpu_to_le32(u64s);