Skip to contentSkip to conversation

jfs: validate dmap parameters in dbMount() and slot chains in jfs_dtree.c

PATCH New Hui Peng 1 participant 1 message Sep 19

Subsystems (2)
lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 jfs: validate dmap parameters in dbMount() and slot chains in jfs_dtree.c

Fix two filesystem corruption crashes in fs/jfs/:

1. In dbMount() (fs/jfs/jfs_dmap.c), validate db_mapsize > 0, db_numag <= MAXAG, db_agheight <= MAX_AGHEIGHT, and db_agwidth > 0 to prevent out-of-bounds array indexing on bmp->db_agfree[] and shift UB.
2. In check_dtroot(), check_dtpage(), and jfs_readdir() (fs/jfs/jfs_dtree.c), validate directory slot continuation indices to prevent cyclic or out-of-bounds slot walks.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by LLM

---

fs/jfs/jfs_dmap.c +2 -1
index a841cf21da7d..f7d6efe8cec8 100644
@@ -288,7 +288,8 @@ int dbMount(struct inode *ipbmap)
 	    (bmp->db_agstart > (CTLTREESIZE - 1 - bmp->db_agwidth * (MAXAG - 1))) ||
 	    (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG) ||
 	    (bmp->db_agl2size < 0) ||
-	    ((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) {
+	    (bmp->db_mapsize <= 0) ||
+	    (((bmp->db_mapsize - 1) >> bmp->db_agl2size) >= MAXAG)) {
 		err = -EINVAL;
 		goto err_release_metapage;
 	}
fs/jfs/jfs_dtree.c +47 -0

83 lines not on this page · raw message