bcachefs: Check for extents with too many ptrs
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 17 Jun 2022 02:38:10 +0000 (22:38 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:34 +0000 (17:09 -0400)
We have a hardcoded maximum on number of pointers in an extent that's
used by some other data structures - notably bch_devs_list - but we
weren't actually checking for it. Oops.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/extents.c

index b0226118077a2a6cbc39b42ed61c8a6f9305f4af..4e44234a2b2c699542123e746b77a52edc6ed733 100644 (file)
@@ -1078,6 +1078,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
        struct bch_extent_crc_unpacked crc;
        unsigned size_ondisk = k.k->size;
        unsigned nonce = UINT_MAX;
+       unsigned nr_ptrs = 0;
        int ret;
 
        if (bkey_is_btree_ptr(k.k))
@@ -1102,6 +1103,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
                                                 false, err);
                        if (ret)
                                return ret;
+                       nr_ptrs++;
                        break;
                case BCH_EXTENT_ENTRY_crc32:
                case BCH_EXTENT_ENTRY_crc64:
@@ -1140,6 +1142,11 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
                }
        }
 
+       if (nr_ptrs >= BCH_BKEY_PTRS_MAX) {
+               prt_str(err, "too many ptrs");
+               return -EINVAL;
+       }
+
        return 0;
 }