xfs
[Top] [All Lists]

[PATCH] xfs: catch invalid negative blknos in _xfs_buf_find()

To: xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH] xfs: catch invalid negative blknos in _xfs_buf_find()
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Wed, 19 Nov 2014 16:12:51 -0600
Delivered-to: xfs@xxxxxxxxxxx
Here blkno is a daddr_t, which is a __s64; it's possible to hold
a value which is negative, and thus pass the (blkno >= eofs)
test.  Then we try to do a xfs_perag_get() for a ridiculous
agno via xfs_daddr_to_agno(), and bad things happen when that
fails, and returns a null pag which is dereferenced shortly
thereafter.

Found via a user-supplied fuzzed image...

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 24b4ebe..f54a497 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -463,7 +463,7 @@ _xfs_buf_find(
         * have to check that the buffer falls within the filesystem bounds.
         */
        eofs = XFS_FSB_TO_BB(btp->bt_mount, btp->bt_mount->m_sb.sb_dblocks);
-       if (blkno >= eofs) {
+       if (blkno < 0 || blkno >= eofs) {
                /*
                 * XXX (dgc): we should really be returning -EFSCORRUPTED here,
                 * but none of the higher level infrastructure supports

<Prev in Thread] Current Thread [Next in Thread>