[PATCH] btrfs: zoned: guard end of csum_list in btrfs_finish_ordered_zoned()
From: Ziheng Wei
Date: Thu Dec 03 2026 - 22:11:02 EST
In btrfs_finish_ordered_zoned(), the early return for
BTRFS_ORDERED_TRUNCATED only handles fully truncated ordered extents
(ordered->truncated_len == 0). When an ordered extent is partially
truncated (0 < ordered->truncated_len < ordered->disk_num_bytes),
sectors at or beyond i_size are marked finished without submitting bios
or adding btrfs_ordered_sum entries to ordered->csum_list.
The loop then compares the accumulated csum length against
ordered->disk_num_bytes and advances sum with list_next_entry(sum, list)
without checking whether sum is already the last element of
ordered->csum_list, causing an out-of-bounds type confusion on the list
head.
Stop iterating once sum reaches the last entry on ordered->csum_list.
Found by LLM-assisted static analysis. Compile-tested on x86_64.
Fixes: 71df088c1cc0 ("btrfs: defer splitting of ordered extents until I/O completion")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
fs/btrfs/zoned.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index bdadc704c..8e966afc1 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2158,7 +2158,8 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)
logical = sum->logical;
len = sum->len;
- while (len < ordered->disk_num_bytes) {
+ while (len < ordered->disk_num_bytes &&
+ !list_is_last(&sum->list, &ordered->csum_list)) {
sum = list_next_entry(sum, list);
if (sum->logical == logical + len) {
len += sum->len;
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0