summaryrefslogtreecommitdiff
path: root/fs/bcachefs/buckets.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-05-22 21:39:44 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:10:01 +0300
commit962210b281b327b236215c736b9f648369f0d39d (patch)
tree3a63cfebef930d3e6d116e75f4ec2c49621961cc /fs/bcachefs/buckets.h
parent0b438c5bfaebda3fdf6edc35d9572d4e2f66aef1 (diff)
downloadlinux-962210b281b327b236215c736b9f648369f0d39d.tar.xz
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.h18
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)