Skip to contentSkip to conversation

xfs: don't release NULL pip in xfs_filestream_lookup_ag()

PATCH In review Eric Sandeen 3 participants 3 messages Mar 3, 2015 – Mar 4, 2015 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: don't release NULL pip in xfs_filestream_lookup_ag()

If xfs_filestream_get_parent() fails, we have a null pip, goto out, and attempt to IRELE(NULL). This causes a null pointer dereference and BUG().

Fix this by testing for pip before trying to release it.

---

fs/xfs/xfs_filestream.c +2 -1
index a2e86e8..fb09a63 100644
@@ -348,7 +348,8 @@ xfs_filestream_lookup_ag(
 	if (xfs_filestream_pick_ag(pip, startag, &ag, 0, 0))
 		ag = NULLAGNUMBER;
 out:
-	IRELE(pip);
+	if (pip)
+		IRELE(pip);
 	return ag;
 }
 

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 15 lines · Eric Sandeen

If xfs_filestream_get_parent() fails, we have a null pip, goto out, and attempt to IRELE(NULL). This causes a null pointer dereference and BUG().

Fix this by testing for pip before trying to release it.

---

fs/xfs/xfs_filestream.c +0 -0
index a2e86e8..fb09a63 100644

fs/xfs/xfs_filestream.c xfs_filestream_lookup_ag( · line 355

Quoted 9 lines
fs/xfs/xfs_filestream.c +2 -1
@@ -348,7 +348,8 @@ xfs_filestream_lookup_ag(
 	if (xfs_filestream_pick_ag(pip, startag, &ag, 0, 0))
 		ag = NULLAGNUMBER;
 out:
-	IRELE(pip);
+	if (pip)
+		IRELE(pip);
 	return ag;
 }
 

I'd just convert the error case when get_parent fails to:

	if (!pip)
		return NULLAGNUMBER;

rather than using the goto and adding conditional cleanup for this case.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw

PATCH v2 1/1 xfs: fix NULL pointer dereference in xfs_filestream_lookup_ag()

In reply to Eric Sandeen

If xfs_filestream_get_parent() fails, we have a null pip, goto out, and attempt to IRELE(NULL). This causes a null pointer dereference and BUG().

Fix this by directly returning NULLAGNUMBER in this case.

---

V2: skip the goto, because Dave doesn't like it. ;)

fs/xfs/xfs_filestream.c +1 -1
index a2e86e8..8f9f854 100644
@@ -322,7 +322,7 @@ xfs_filestream_lookup_ag(
 
 	pip = xfs_filestream_get_parent(ip);
 	if (!pip)
-		goto out;
+		return NULLAGNUMBER;
 
 	mru = xfs_mru_cache_lookup(mp->m_filestream, pip->i_ino);
 	if (mru) {

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs