diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-09-19 22:18:39 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:14 -0400 |
commit | a55fc65eb2c71da5d422937db767a78c6438f9b6 (patch) | |
tree | bcd324fe6e308cf3de514dce898ded93b63ec6c2 /fs/bcachefs/buckets.c | |
parent | f7f6943a8c6dccbd085600bbb7bae4f6f6047dc4 (diff) | |
download | lwn-a55fc65eb2c71da5d422937db767a78c6438f9b6.tar.gz lwn-a55fc65eb2c71da5d422937db767a78c6438f9b6.zip |
bcachefs: Fix an overflow check
When bucket sector counts were changed from u16s to u32s, a few things
were missed. This fixes an overflow check, and a truncation that
prevented the overflow check from firing.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/buckets.c')
-rw-r--r-- | fs/bcachefs/buckets.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 994129142d39..e7f4506f69ca 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -680,7 +680,7 @@ static int check_bucket_ref(struct btree_trans *trans, struct bch_fs *c = trans->c; struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev); size_t bucket_nr = PTR_BUCKET_NR(ca, ptr); - u16 bucket_sectors = !ptr->cached + u32 bucket_sectors = !ptr->cached ? dirty_sectors : cached_sectors; struct printbuf buf = PRINTBUF; @@ -752,9 +752,9 @@ static int check_bucket_ref(struct btree_trans *trans, goto err; } - if ((unsigned) (bucket_sectors + sectors) > U32_MAX) { + if ((u64) bucket_sectors + sectors > U32_MAX) { bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, - "bucket %u:%zu gen %u data type %s sector count overflow: %u + %lli > U16_MAX\n" + "bucket %u:%zu gen %u data type %s sector count overflow: %u + %lli > U32_MAX\n" "while marking %s", ptr->dev, bucket_nr, b_gen, bch2_data_types[bucket_data_type ?: ptr_data_type], |