summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-05-30 02:06:06 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 23:08:23 +0200
commit1ae973345626fcd9cdb81fe856cabf7808a33140 (patch)
treeabcdefbfb37f4bd5ee74dde60c1a7ac672380803 /fs
parentbcachefs: Fix starting copygc when already started (diff)
downloadlinux-1ae973345626fcd9cdb81fe856cabf7808a33140.tar.xz
linux-1ae973345626fcd9cdb81fe856cabf7808a33140.zip
bcachefs: Don't overflow stack in bch2_extent_merge_inline()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/bkey.h5
-rw-r--r--fs/bcachefs/extents.c4
2 files changed, 5 insertions, 4 deletions
diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h
index 45de61d492a4..ba08d95aae6f 100644
--- a/fs/bcachefs/bkey.h
+++ b/fs/bcachefs/bkey.h
@@ -41,10 +41,7 @@ struct bkey_s {
#define bkey_next(_k) vstruct_next(_k)
-static inline unsigned bkey_val_u64s(const struct bkey *k)
-{
- return k->u64s - BKEY_U64s;
-}
+#define bkey_val_u64s(_k) ((_k)->u64s - BKEY_U64s)
static inline size_t bkey_val_bytes(const struct bkey *k)
{
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index c5a0d6c8e63a..a5582a6f6ef6 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1651,6 +1651,10 @@ static bool bch2_extent_merge_inline(struct bch_fs *c,
EBUG_ON(bkey_written(b, m));
+ if (bkey_val_u64s(l) > BKEY_EXTENT_VAL_U64s_MAX ||
+ bkey_val_u64s(r) > BKEY_EXTENT_VAL_U64s_MAX)
+ return BCH_MERGE_NOMERGE;
+
/*
* We need to save copies of both l and r, because we might get a
* partial merge (which modifies both) and then fails to repack