Skip to contentSkip to conversation

jfs: fix slab-out-of-bounds read in dbAllocBits

PATCH Superseded Jun Yeong Kim 1 participant 1 message Mar 21 JFS filesystem

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: fix slab-out-of-bounds read in dbAllocBits

When the underlying loop device backend storage is dynamically changed (e.g., via LOOP_SET_FD), JFS fails to update its internal block allocation metadata. This causes the dbAllocBits function to use outdated db_agl2size information, resulting in a wrong, oversized agno value.

This oversized agno leads to a slab-out-of-bounds read access when accessing mp->db_agfree[agno].

Fix this by adding a bounds check for the calculated agno. If agno is less than 0 or exceeds MAXAG, return -EIO to prevent the OOB access.

---
 fs/jfs/jfs_dmap.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/jfs/jfs_dmap.c +9 -0
index cb3cda1390ad..79816849aebb 100644
@@ -2288,6 +2288,15 @@ static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
 	dmtree_t *tp = (dmtree_t *) & dp->tree;
 	int rc = 0;
 	int size;
+
+	{
+		int check_agno = blkno >> bmp->db_agl2size;
+
+		if (check_agno >= MAXAG || check_agno < 0) {
+			pr_err("JFS: agno out of bounds in dbAllocBits!\n");
+			return -EIO;
+		}
+	}
 
 	/* determine the bit number and word within the dmap of the
 	 * starting block.
Signature · 1 line
2.47.3