Skip to contentSkip to conversation

qnx4: validate xblk_num_xtnts and rootdir size in qnx4_block_map() and mount

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 qnx4: validate xblk_num_xtnts and rootdir size in qnx4_block_map() and mount

In qnx4_block_map() and qnx4_fill_super() (fs/qnx4/inode.c), check that xblk->xblk_num_xtnts is between 1 and QNX4_MAX_XTNTS_PER_XBLK (60), return 0 instead of (unsigned long)-EIO on error, and validate the root directory inode size on mount to prevent out-of-bounds reads past the 512-byte buffer_head.

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

---

fs/qnx4/inode.c +6 -3
index 42fcd500fad2..f6eb08cac09b 100644
@@ -104,12 +104,15 @@ unsigned long qnx4_block_map( struct inode *inode, long iblock )
 				bh = sb_bread(inode->i_sb, i_xblk - 1);
 				if ( !bh ) {
 					QNX4DEBUG((KERN_ERR "qnx4: I/O error reading xtnt block [%ld])\n", i_xblk - 1));
-					return -EIO;
+					return 0;
 				}
 				xblk = (struct qnx4_xblk*)bh->b_data;
-				if ( memcmp( xblk->xblk_signature, "IamXblk", 7 ) ) {
+				if (memcmp(xblk->xblk_signature, "IamXblk", 7) ||
+				    xblk->xblk_num_xtnts == 0 ||
+				    xblk->xblk_num_xtnts > QNX4_MAX_XTNTS_PER_XBLK) {
 					QNX4DEBUG((KERN_ERR "qnx4: block at %ld is not a valid xtnt\n", qnx4_inode->i_xblk));
-					return -EIO;
+					brelse(bh);
+					return 0;
 				}
 			}
 			block = try_extent(&xblk->xblk_xtnts[ix], &offset);