]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bcachefs: Fix sb-downgrade validation
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 25 May 2024 16:38:53 +0000 (12:38 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Jul 2024 07:38:16 +0000 (09:38 +0200)
commit 9242a34b760648b722f4958749ad83ef7d0f7525 upstream.

Superblock downgrade entries are only two byte aligned, but section
sizes are 8 byte aligned, which means we have to be careful about
overrun checks; an entry that crosses the end of the section is allowed
(and ignored) as long as it has zero errors.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/bcachefs/sb-downgrade.c

index 13fb3292aba4068e851158b9567ecf041247bd56..b01d4969fe02ba415e39b87c785c00b16c25ca41 100644 (file)
@@ -146,6 +146,14 @@ static int bch2_sb_downgrade_validate(struct bch_sb *sb, struct bch_sb_field *f,
        for (const struct bch_sb_field_downgrade_entry *i = e->entries;
             (void *) i < vstruct_end(&e->field);
             i = downgrade_entry_next_c(i)) {
+               /*
+                * Careful: sb_field_downgrade_entry is only 2 byte aligned, but
+                * section sizes are 8 byte aligned - an empty entry spanning
+                * the end of the section is allowed (and ignored):
+                */
+               if ((void *) &i->errors[0] > vstruct_end(&e->field))
+                       break;
+
                if (BCH_VERSION_MAJOR(le16_to_cpu(i->version)) !=
                    BCH_VERSION_MAJOR(le16_to_cpu(sb->version))) {
                        prt_printf(err, "downgrade entry with mismatched major version (%u != %u)",