Skip to contentSkip to conversation

jfs : fix shift-out-of-bounds in dbUpdatePMap

PATCH In review Manas Ghandat 2 participants 4 messages Aug 27, 2023 – Aug 30, 2023 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs : fix shift-out-of-bounds in dbUpdatePMap

Currently there is no bound check for number of logical blocks per page (bmp->db_l2nbperpage). Added the required bound check for the calculation of dmap.

Reported-by [email protected]
Fixes 4d81715fc5df ("[PATCH] fs/jfs: Conversion to generic boolean")
---
 fs/jfs/jfs_dmap.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/jfs/jfs_dmap.c +4 -0
index a3eb1e826947..6a5df296fdc8 100644
@@ -467,6 +467,10 @@ dbUpdatePMap(struct inode *ipbmap,
 	lastlblkno = 0;
 	for (rem = nblocks; rem > 0; rem -= nblks, blkno += nblks) {
 		/* get the buffer for the current dmap. */
+
+		if (bmp->db_l2nbperpage > L2BPERDMAP)
+			return -EIO;
+
 		lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
 		if (lblkno != lastlblkno) {
 			if (mp) {
Signature · 6 lines
2.37.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Quoted 3 lines · Manas Ghandat

Currently there is no bound check for number of logical blocks per page (bmp->db_l2nbperpage). Added the required bound check for the calculation of dmap.

This should already be fixed by 11509910c599 ("jfs: jfs_dmap: Validate db_l2nbperpage while mounting")

Can you please verify if this problem still exists in v6.5?

Shaggy

Quoted 14 lines
Reported-by [email protected]
Fixes 4d81715fc5df ("[PATCH] fs/jfs: Conversion to generic boolean")
---
  fs/jfs/jfs_dmap.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/jfs/jfs_dmap.c +0 -0
index a3eb1e826947..6a5df296fdc8 100644

fs/jfs/jfs_dmap.c dbUpdatePMap(struct inode *ipbmap, · line 476

Quoted 10 lines
fs/jfs/jfs_dmap.c +4 -0
@@ -467,6 +467,10 @@ dbUpdatePMap(struct inode *ipbmap,
  	lastlblkno = 0;
  	for (rem = nblocks; rem > 0; rem -= nblks, blkno += nblks) {
  		/* get the buffer for the current dmap. */
+
+		if (bmp->db_l2nbperpage > L2BPERDMAP)
+			return -EIO;
+
  		lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
  		if (lblkno != lastlblkno) {
  			if (mp) {

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw

I checked for the v6.5. Its fixed there.

Quoted 11 lines · Dave Kleikamp
Quoted 3 lines · Manas Ghandat

Currently there is no bound check for number of logical blocks per page (bmp->db_l2nbperpage). Added the required bound check for the calculation of dmap.

This should already be fixed by 11509910c599 ("jfs: jfs_dmap: Validate db_l2nbperpage while mounting")

Can you please verify if this problem still exists in v6.5?

Shaggy

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#3 lore raw

Thanks for verifying!

Quoted 14 lines · Manas Ghandat

I checked for the v6.5. Its fixed there.

Quoted 11 lines · Dave Kleikamp
Quoted 3 lines · Manas Ghandat

Currently there is no bound check for number of logical blocks per page (bmp->db_l2nbperpage). Added the required bound check for the calculation of dmap.

This should already be fixed by 11509910c599 ("jfs: jfs_dmap: Validate db_l2nbperpage while mounting")

Can you please verify if this problem still exists in v6.5?

Shaggy

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees