Skip to contentSkip to conversation

jfs: Add check for array bounds in dtDelete

PATCH New Pedro Demarchi Gomes 1 participant 1 message Sep 19, 2025 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: Add check for array bounds in dtDelete

stbl is s8 but it must contain offsets into slot which can go from 0 to 127.

Add a bound check for that error inside dtDelete function.

---
 fs/jfs/jfs_dtree.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
fs/jfs/jfs_dtree.c +11 -5
index ab11849cf9cc..c200b37f4562 100644
@@ -2129,11 +2129,17 @@ int dtDelete(tid_t tid,
 					next_index = -1;
 				else {
 					stbl = DT_GETSTBL(np);
-					ldtentry =
-					    (struct ldtentry *) & np->
-					    slot[stbl[0]];
-					next_index =
-					    le32_to_cpu(ldtentry->index);
+					if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
+						jfs_err("JFS: Invalid stbl[0] = %d for inode %ld, block = %lld",
+							stbl[0], (long)ip->i_ino, (long long)le64_to_cpu(p->header.next));
+						next_index = -1;
+					} else {
+						ldtentry =
+							(struct ldtentry *) & np->
+							slot[stbl[0]];
+						next_index =
+							le32_to_cpu(ldtentry->index);
+					}
 					DT_PUTPAGE(nmp);
 				}
 			}
Signature · 1 line
2.39.5