Skip to contentSkip to conversation

bcachefs: Fix journal_entry_dev_usage_to_text() overrun

PATCH New Kent Overstreet 1 participant 1 message Nov 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: Fix journal_entry_dev_usage_to_text() overrun

If the jset_entry_dev_usage is malformed, and too small, our nr_entries calculation will be incorrect - just bail out.

---
 fs/bcachefs/journal_io.c | 3 +++
 1 file changed, 3 insertions(+)
fs/bcachefs/journal_io.c +3 -0
index 667a2bb9e20b..768a3b950997 100644
@@ -711,6 +711,9 @@ static void journal_entry_dev_usage_to_text(struct printbuf *out, struct bch_fs
 		container_of(entry, struct jset_entry_dev_usage, entry);
 	unsigned i, nr_types = jset_entry_dev_usage_nr_types(u);
 
+	if (vstruct_bytes(entry) < sizeof(*u))
+		return;
+
 	prt_printf(out, "dev=%u", le32_to_cpu(u->dev));
 
 	printbuf_indent_add(out, 2);
Signature · 1 line
2.45.2