Skip to contentSkip to conversation

jfs: array-index-out-of-bounds fix in dtReadFirst

PATCH In review Ghanshyam Agrawal 2 participants 2 messages Sep 28, 2024 – Oct 29, 2024 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: array-index-out-of-bounds fix in dtReadFirst

The value of stbl can be sometimes out of bounds due to a bad filesystem. Added a check with appopriate return of error code in that case.

---
 fs/jfs/jfs_dtree.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/jfs/jfs_dtree.c +7 -0
index 5d3127ca68a4..69fd936fbdb3 100644
@@ -3086,6 +3086,13 @@ static int dtReadFirst(struct inode *ip, struct btstack * btstack)
 
 		/* get the leftmost entry */
 		stbl = DT_GETSTBL(p);
+
+		if (stbl[0] < 0 || stbl[0] > 127) {
+			DT_PUTPAGE(mp);
+			jfs_error(ip->i_sb, "stbl[0] out of bound\n");
+			return -EIO;
+		}
+
 		xd = (pxd_t *) & p->slot[stbl[0]];
 
 		/* get the child page block address */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Ghanshyam Agrawal

The value of stbl can be sometimes out of bounds due to a bad filesystem. Added a check with appopriate return of error code in that case.

---
  fs/jfs/jfs_dtree.c | 7 +++++++
  1 file changed, 7 insertions(+)
fs/jfs/jfs_dtree.c +0 -0
index 5d3127ca68a4..69fd936fbdb3 100644

fs/jfs/jfs_dtree.c static int dtReadFirst(struct inode *ip, struct btstack * btstack) · line 3090

Quoted 5 lines
fs/jfs/jfs_dtree.c +2 -0
@@ -3086,6 +3086,13 @@ static int dtReadFirst(struct inode *ip, struct btstack * btstack)
 
  		/* get the leftmost entry */
  		stbl = DT_GETSTBL(p);
+
+		if (stbl[0] < 0 || stbl[0] > 127) {

Technically, a signed 8-bit integer cannot exceed 127, but since the compiler will know that and optimize it out, I'll leave it in because it looks more complete.

fs/jfs/jfs_dtree.c static int dtReadFirst(struct inode *ip, struct btstack * btstack) · line 3098

Quoted 8 lines
fs/jfs/jfs_dtree.c +5 -0
+			DT_PUTPAGE(mp);
+			jfs_error(ip->i_sb, "stbl[0] out of bound\n");
+			return -EIO;
+		}
+
  		xd = (pxd_t *) & p->slot[stbl[0]];
 
  		/* get the child page block address */

Looks good. I'll apply this.

Shaggy