diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-05-22 14:39:44 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:01 -0400 |
commit | 962210b281b327b236215c736b9f648369f0d39d (patch) | |
tree | 3a63cfebef930d3e6d116e75f4ec2c49621961cc /fs/bcachefs/buckets.h | |
parent | 0b438c5bfaebda3fdf6edc35d9572d4e2f66aef1 (diff) | |
download | linux-962210b281b327b236215c736b9f648369f0d39d.tar.gz linux-962210b281b327b236215c736b9f648369f0d39d.tar.bz2 linux-962210b281b327b236215c736b9f648369f0d39d.zip |
bcachefs: Fix a buffer overrun in bch2_fs_usage_read()
We were copying the size of a struct bch_fs_usage_online to a struct
bch_fs_usage, which is 8 bytes smaller.
This adds some new helpers so we can do this correctly, and get rid of
some magic +1s too.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/buckets.h')
-rw-r--r-- | fs/bcachefs/buckets.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index d677b0225c52..bdf4fff9cb8a 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -207,10 +207,24 @@ static inline u64 dev_buckets_available(struct bch_dev *ca, /* Filesystem usage: */ +static inline unsigned __fs_usage_u64s(unsigned nr_replicas) +{ + return sizeof(struct bch_fs_usage) / sizeof(u64) + nr_replicas; +} + static inline unsigned fs_usage_u64s(struct bch_fs *c) { - return sizeof(struct bch_fs_usage) / sizeof(u64) + - READ_ONCE(c->replicas.nr); + return __fs_usage_u64s(READ_ONCE(c->replicas.nr)); +} + +static inline unsigned __fs_usage_online_u64s(unsigned nr_replicas) +{ + return sizeof(struct bch_fs_usage_online) / sizeof(u64) + nr_replicas; +} + +static inline unsigned fs_usage_online_u64s(struct bch_fs *c) +{ + return __fs_usage_online_u64s(READ_ONCE(c->replicas.nr)); } static inline unsigned dev_usage_u64s(void) |