Skip to contentSkip to conversation

bcachefs: return err ptr instead of null in read sb clean

PATCH Applied Diogo Jahchan Koike 2 participants 2 messages Sep 10, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: return err ptr instead of null in read sb clean

syzbot reported a null-ptr-deref in bch2_fs_start. [0]

When a sb is marked clear but doesn't have a clean section bch2_read_superblock_clean returns NULL which PTR_ERR_OR_ZERO lets through, eventually leading to a null ptr dereference down the line. Adjust read sb clean to return an ERR_PTR indicating the invalid clean section.

[0] https://syzkaller.appspot.com/bug?extid=1cecc37d87c4286e5543

---
 fs/bcachefs/sb-clean.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/sb-clean.c +1 -1
index c57d42bb8d1b..025848a9c4c0 100644
@@ -155,7 +155,7 @@ struct bch_sb_field_clean *bch2_read_superblock_clean(struct bch_fs *c)
 		SET_BCH_SB_CLEAN(c->disk_sb.sb, false);
 		c->sb.clean = false;
 		mutex_unlock(&c->sb_lock);
-		return NULL;
+		return ERR_PTR(-BCH_ERR_invalid_sb_clean);
 	}
 
 	clean = kmemdup(sb_clean, vstruct_bytes(&sb_clean->field),
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Diogo Jahchan Koike

syzbot reported a null-ptr-deref in bch2_fs_start. [0]

When a sb is marked clear but doesn't have a clean section bch2_read_superblock_clean returns NULL which PTR_ERR_OR_ZERO lets through, eventually leading to a null ptr dereference down the line. Adjust read sb clean to return an ERR_PTR indicating the invalid clean section.

Quoted 5 lines

[0] https://syzkaller.appspot.com/bug?extid=1cecc37d87c4286e5543

Thanks, applied