Skip to contentSkip to conversation

pNFS: Fix uninited ptr access in ext_tree_encode_commit

PATCH In review Sergey Bashirov 3 participants 3 messages Jul 17, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pNFS: Fix uninited ptr access in ext_tree_encode_commit

Current implementation of the function assumes that the provided buffer can always accommodate at least one encoded extent. This patch adds handling of all theoretically possible values of be_prev, so that ext_tree_encode_commit makes no assumptions about the provided buffer size, and static checks pass without warnings.

Fixes d84c4754f874 ("pNFS: Fix extent encoding in block/scsi layout")

Addresses-Coverity-ID: 1647611 ("Memory - illegal accesses (UNINIT)")

---
 fs/nfs/blocklayout/extent_tree.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/nfs/blocklayout/extent_tree.c +5 -2
index 315949a7e92d..adc1fe190cfc 100644
@@ -585,7 +585,7 @@ static int
 ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
 		size_t buffer_size, size_t *count, __u64 *lastbyte)
 {
-	struct pnfs_block_extent *be, *be_prev;
+	struct pnfs_block_extent *be, *be_prev = NULL;
 	int ret = 0;
 
 	spin_lock(&bl->bl_ext_lock);
@@ -611,10 +611,13 @@ ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
 	if (!ret) {
 		*lastbyte = (bl->bl_lwb != 0) ? bl->bl_lwb - 1 : U64_MAX;
 		bl->bl_lwb = 0;
-	} else {
+	} else if (be_prev) {
 		*lastbyte = be_prev->be_f_offset + be_prev->be_length;
 		*lastbyte <<= SECTOR_SHIFT;
 		*lastbyte -= 1;
+	} else {
+		/* Buffer too small even for one extent, count is zero */
+		*lastbyte = U64_MAX;
 	}
 	spin_unlock(&bl->bl_ext_lock);
 
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Sergey Bashirov

Current implementation of the function assumes that the provided buffer can always accommodate at least one encoded extent. This patch adds handling of all theoretically possible values of be_prev, so that ext_tree_encode_commit makes no assumptions about the provided buffer size, and static checks pass without warnings.

Fixes d84c4754f874 ("pNFS: Fix extent encoding in block/scsi layout")

Addresses-Coverity-ID: 1647611 ("Memory - illegal accesses (UNINIT)")

Thanks a lot!
Regards,

Signature · 5 lines
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
Reviewed-by on v1 1/1
#2 lore raw
In reply to Sergey Bashirov
Quoted 10 lines · Sergey Bashirov

Current implementation of the function assumes that the provided buffer can always accommodate at least one encoded extent. This patch adds handling of all theoretically possible values of be_prev, so that ext_tree_encode_commit makes no assumptions about the provided buffer size, and static checks pass without warnings.

Fixes d84c4754f874 ("pNFS: Fix extent encoding in block/scsi layout")

Addresses-Coverity-ID: 1647611 ("Memory - illegal accesses (UNINIT)")

---

Generally, we wouldn't put a Fixes tag here because it's just silencing a false positive. But also putting a Fixes tag is fine. Thanks!

regards,
dan carpenter