Skip to contentSkip to conversation

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

PATCH New Kery Qi 1 participant 1 message Jan 22 JFS filesystem

lore
Share & tools
lore

Kery Qi

author
#0 lore raw

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

Similar to the issue fixed in commit 49f9637aafa6 ("jfs: fix array-index-out-of-bounds in diNewExt"), the diExtendFS() function also lacks validation for the AG (allocation group) number.

In diExtendFS(), the variable 'n' is computed from iagp->agstart which is read from disk. If agstart contains a malicious or corrupted value, 'n' may exceed the bounds of the im_agctl[] array (size MAXAG), leading to an out-of-bounds access.

Add a boundary check for 'n' after computation to ensure it falls within the valid range [0, MAXAG). If the check fails, release the metapage and return -EIO.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 fs/jfs/jfs_imap.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/jfs/jfs_imap.c +5 -0
index ecb8e05b8b84..24b414bffd29 100644
@@ -2900,6 +2900,11 @@ int diExtendFS(struct inode *ipimap, struct inode *ipbmap)
 
 		agstart = le64_to_cpu(iagp->agstart);
 		n = agstart >> mp->db_agl2size;
+		if (n < 0 || n >= MAXAG) {
+			release_metapage(bp);
+			jfs_error(ipimap->i_sb, "invalid AG number\n");
+			return -EIO;
+		}
 		iagp->agstart = cpu_to_le64((s64)n << mp->db_agl2size);
 
 		/* compute backed inodes */
Signature · 1 line
2.34.1