Skip to contentSkip to conversation

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

PATCH In review Manas Ghandat 2 participants 3 messages Oct 8, 2023 – Nov 1, 2023 JFS filesystem

lore
Share & tools
lore
#0 lore raw

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

Currently while copying dtree root from inode to dnode in the xp slot there is a out of bound memcpy. Added a bound check to the memcpy.

---
 fs/jfs/jfs_imap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/jfs/jfs_imap.c +2 -1
index 799d3837e7c2..d1f897848be0 100644
@@ -746,7 +746,8 @@ int diWrite(tid_t tid, struct inode *ip)
 		xp = (dtpage_t *) & dp->di_dtroot;
 		lv = ilinelock->lv;
 		for (n = 0; n < ilinelock->index; n++, lv++) {
-			memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
+			if (lv->offset < 128)
+				memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
 			       lv->length << L2DTSLOTSIZE);
 		}
 	} else {
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

Just a friendly ping :)

Quoted 15 lines · Manas Ghandat

Currently while copying dtree root from inode to dnode in the xp slot there is a out of bound memcpy. Added a bound check to the memcpy.

---
  fs/jfs/jfs_imap.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/jfs/jfs_imap.c +0 -0
index 799d3837e7c2..d1f897848be0 100644

fs/jfs/jfs_imap.c int diWrite(tid_t tid, struct inode *ip) · line 753

Quoted 9 lines
fs/jfs/jfs_imap.c +2 -1
@@ -746,7 +746,8 @@ int diWrite(tid_t tid, struct inode *ip)
  		xp = (dtpage_t *) & dp->di_dtroot;
  		lv = ilinelock->lv;
  		for (n = 0; n < ilinelock->index; n++, lv++) {
-			memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
+			if (lv->offset < 128)
+				memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
  			       lv->length << L2DTSLOTSIZE);
  		}
  	} else {

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

#2 lore raw
In reply to Manas Ghandat
Quoted 15 lines · Manas Ghandat

Currently while copying dtree root from inode to dnode in the xp slot there is a out of bound memcpy. Added a bound check to the memcpy.

---
  fs/jfs/jfs_imap.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/jfs/jfs_imap.c +0 -0
index 799d3837e7c2..d1f897848be0 100644

fs/jfs/jfs_imap.c int diWrite(tid_t tid, struct inode *ip) · line 749

Quoted 5 lines
fs/jfs/jfs_imap.c +1 -1
@@ -746,7 +746,8 @@ int diWrite(tid_t tid, struct inode *ip)
  		xp = (dtpage_t *) & dp->di_dtroot;
  		lv = ilinelock->lv;
  		for (n = 0; n < ilinelock->index; n++, lv++) {
-			memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
+			if (lv->offset < 128)

I'd use DTPAGEMAXSLOT instead of hard-coding 128.

Also, we could at least set rc to -EIO, or we could do something more.
Calling jfs_error() would mark the superblock dirty and usually makes the file system read-only until it's fixed.

fs/jfs/jfs_imap.c int diWrite(tid_t tid, struct inode *ip) · line 753

Quoted 4 lines
fs/jfs/jfs_imap.c +1 -0
+				memcpy(&xp->slot[lv->offset], &p->slot[lv->offset],
  			       lv->length << L2DTSLOTSIZE);
  		}
  	} else {

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