diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-17 05:38:10 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:34 +0300 |
commit | b5f73fd79f4c710024ef4385626aecbaee6fc3f1 (patch) | |
tree | 2765baf91e7c5a6ca776fda2a515258d77d9384d /fs/bcachefs/extents.c | |
parent | 1c6ff39445553f84f9a46c2c60a4768c7f4ef226 (diff) | |
download | linux-b5f73fd79f4c710024ef4385626aecbaee6fc3f1.tar.xz |
bcachefs: Check for extents with too many ptrs
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>
Diffstat (limited to 'fs/bcachefs/extents.c')
-rw-r--r-- | fs/bcachefs/extents.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index b0226118077a..4e44234a2b2c 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -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; } |