diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-16 22:38:10 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2022-10-03 22:52:24 -0400 |
commit | a9377cf09654c7e2b6cc42b247e57e370dfa8d11 (patch) | |
tree | 468d398b58cda9aa5e7985bdfe2c63c6cde21353 | |
parent | 6f32c9d8f66ab4568e46492c5db91c1cb2bb5469 (diff) |
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>
-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 f4875c430a14..2ca13014b9c4 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -1096,6 +1096,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)) @@ -1120,6 +1121,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: @@ -1158,6 +1160,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; } |