Skip to contentSkip to conversation

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

PATCH In review Ghanshyam Agrawal 2 participants 4 messages Oct 10, 2024 – Oct 31, 2024 JFS filesystem

lore
Share & tools
lore
#0 lore raw

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

The value of p->header.freelist can be less than zero which causes an error in dtInsertEntry. Added a check in dtInsert to address it.

---
 fs/jfs/jfs_dtree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dtree.c +1 -1
index 5d3127ca68a4..51bb3e14551b 100644
@@ -834,7 +834,7 @@ int dtInsert(tid_t tid, struct inode *ip,
 	 * the full page.
 	 */
 	DT_GETSEARCH(ip, btstack->top, bn, mp, p, index);
-	if (p->header.freelist == 0)
+	if (p->header.freelist <= 0)
 		return -EINVAL;
 
 	/*
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Ghanshyam Agrawal

The value of p->header.freelist can be less than zero which causes an error in dtInsertEntry. Added a check in dtInsert to address it.

Looks good. I'll apply this one.

Quoted 17 lines
---
  fs/jfs/jfs_dtree.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dtree.c +1 -1
index 5d3127ca68a4..51bb3e14551b 100644
@@ -834,7 +834,7 @@ int dtInsert(tid_t tid, struct inode *ip,
  	 * the full page.
  	 */
  	DT_GETSEARCH(ip, btstack->top, bn, mp, p, index);
-	if (p->header.freelist == 0)
+	if (p->header.freelist <= 0)
  		return -EINVAL;
 
  	/*
#2 lore raw
Quoted 10 lines · Dave Kleikamp
Quoted 7 lines · Ghanshyam Agrawal

The value of p->header.freelist can be less than zero which causes an error in dtInsertEntry. Added a check in dtInsert to address it.

Looks good. I'll apply this one.

Unapplying it. This caused regressions running xfstests. I'll need to look into it more carefully.

Shaggy

Quoted 17 lines
Quoted 17 lines

---
  fs/jfs/jfs_dtree.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dtree.c +1 -1
index 5d3127ca68a4..51bb3e14551b 100644
@@ -834,7 +834,7 @@ int dtInsert(tid_t tid, struct inode *ip,
        * the full page.
        */
       DT_GETSEARCH(ip, btstack->top, bn, mp, p, index);
-    if (p->header.freelist == 0)
+    if (p->header.freelist <= 0)
           return -EINVAL;
       /*
#3 lore raw
Quoted 23 lines · Dave Kleikamp
Quoted 10 lines · Dave Kleikamp
Quoted 7 lines · Ghanshyam Agrawal

The value of p->header.freelist can be less than zero which causes an error in dtInsertEntry. Added a check in dtInsert to address it.

Looks good. I'll apply this one.

Unapplying it. This caused regressions running xfstests. I'll need to look into it more carefully.

Shaggy

Quoted 5 lines
Quoted 5 lines
---
  fs/jfs/jfs_dtree.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
fs/jfs/jfs_dtree.c +0 -0
index 5d3127ca68a4..51bb3e14551b 100644
Quoted 8 lines

fs/jfs/jfs_dtree.c int dtInsert(tid_t tid, struct inode *ip, · line 839

Quoted 8 lines
fs/jfs/jfs_dtree.c +1 -1
@@ -834,7 +834,7 @@ int dtInsert(tid_t tid, struct inode *ip,
       * the full page.
       */
      DT_GETSEARCH(ip, btstack->top, bn, mp, p, index);
-    if (p->header.freelist == 0)
+    if (p->header.freelist <= 0)
          return -EINVAL;
      /*

Hello Dave,

Thank you for reviewing and testing my patch. Let me go through the xfstests results, find the issue and send a v2 for this patch.

Thanks & Regards,
Ghanshyam Agrawal