Skip to contentSkip to conversation

xfs: don't perform lookups on zero-height btrees

PATCH In review Darrick J. Wong 3 participants 4 messages Aug 19, 2016 – Aug 25, 2016 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: don't perform lookups on zero-height btrees

If the caller passes in a cursor to a zero-height btree (which is impossible), we never set block to anything but NULL, which causes the later dereference of it to crash. Instead, just return -EFSCORRUPTED.

---
 fs/xfs/libxfs/xfs_btree.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_btree.c +4 -0
index 64fd847..4bffea4 100644
@@ -1814,6 +1814,10 @@ xfs_btree_lookup(
 
 	XFS_BTREE_STATS_INC(cur, lookup);
 
+	/* No such thing as a zero-level tree. */
+	if (cur->bc_nlevels == 0)
+		return -EFSCORRUPTED;
+
 	block = NULL;
 	keyno = 0;
 

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

#1 lore raw
Quoted 6 lines · Darrick J. Wong

If the caller passes in a cursor to a zero-height btree (which is impossible), we never set block to anything but NULL, which causes the later dereference of it to crash. Instead, just return -EFSCORRUPTED.

---

Did something actually cause this to happen?

Brian

Quoted 19 lines
 fs/xfs/libxfs/xfs_btree.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_btree.c +4 -0
index 64fd847..4bffea4 100644
@@ -1814,6 +1814,10 @@ xfs_btree_lookup(
 
 	XFS_BTREE_STATS_INC(cur, lookup);
 
+	/* No such thing as a zero-level tree. */
+	if (cur->bc_nlevels == 0)
+		return -EFSCORRUPTED;
+
 	block = NULL;
 	keyno = 0;
 
Quoted 4 lines

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

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

#2 lore raw
Quoted 9 lines · Brian Foster
Quoted 6 lines · Darrick J. Wong

If the caller passes in a cursor to a zero-height btree (which is impossible), we never set block to anything but NULL, which causes the later dereference of it to crash. Instead, just return -EFSCORRUPTED.

---

Did something actually cause this to happen?

Well, if you took a reflink xfs that was formatted before we added the rmap/refcount btree block counters to the AGF and then tried to mount it after will blow up like this, because the refcount_level field got moved to somewhere that's zero in the old image.

Anyone being malicious with xfs_db can also do this to any other _level field.

(Yay automounting!)

--D

Quoted 22 lines

Brian

Quoted 19 lines
 fs/xfs/libxfs/xfs_btree.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_btree.c +4 -0
index 64fd847..4bffea4 100644
@@ -1814,6 +1814,10 @@ xfs_btree_lookup(
 
 	XFS_BTREE_STATS_INC(cur, lookup);
 
+	/* No such thing as a zero-level tree. */
+	if (cur->bc_nlevels == 0)
+		return -EFSCORRUPTED;
+
 	block = NULL;
 	keyno = 0;
 
Quoted 4 lines
Quoted 4 lines

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

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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Darrick J. Wong
Quoted 5 lines · Darrick J. Wong

If the caller passes in a cursor to a zero-height btree (which is impossible), we never set block to anything but NULL, which causes the later dereference of it to crash. Instead, just return -EFSCORRUPTED.

Looks fine,

maybe also throw in an unlikely notation, though..

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