From: Shailendra Tripathi <stripathi@agami.com>
To: Jesper Juhl <jesper.juhl@gmail.com>
Cc: linux-kernel@vger.kernel.org, xfs@oss.sgi.com,
xfs-masters@oss.sgi.com, nathans@sgi.com,
Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH][RFC][resend] potential NULL pointer deref in XFS on failed mount
Date: Thu, 16 Nov 2006 13:23:20 -0800 [thread overview]
Message-ID: <455CD6C8.5030907@agami.com> (raw)
In-Reply-To: <200611162218.26945.jesper.juhl@gmail.com>
Hey Jesper,
Rather, it can be done as below. Nothing to say that
your code wouldn't work. Just that catch it early, so that potential
function call overhead to call xfs_free_buftarg can be avoided.
void
xfs_unmountfs_close(xfs_mount_t *mp, struct cred *cr)
{
if (mp->m_logdev_targp && (mp->m_logdev_targp != mp->m_ddev_targp))
xfs_free_buftarg(mp->m_logdev_targp, 1);
if (mp->m_rtdev_targp)
xfs_free_buftarg(mp->m_rtdev_targp, 1);
xfs_free_buftarg(mp->m_ddev_targp, 0);
}
Jesper Juhl wrote:
> (got no reply on this when I originally send it on 20061031, so resending
> now that a bit of time has passed. The patch still applies cleanly to
> Linus' git tree as of today.)
>
>
> The Coverity checker spotted a potential problem in XFS.
>
> The problem is that if, in xfs_mount(), this code triggers:
>
> ...
> if (!mp->m_logdev_targp)
> goto error0;
> ...
>
> Then we'll end up calling xfs_unmountfs_close() with a NULL
> 'mp->m_logdev_targp'.
> This in turn will result in a call to xfs_free_buftarg() with its 'btp'
> argument == NULL. xfs_free_buftarg() dereferences 'btp' leading to
> a NULL pointer dereference and crash.
>
> I think this can happen, since the fatal call to xfs_free_buftarg()
> happens when 'm_logdev_targp != m_ddev_targp' and due to a check of
> 'm_ddev_targp' against NULL in xfs_mount() (and subsequent return if it is
> NULL) the two will never both be NULL when we hit the error0 label from
> the two lines cited above.
>
> Comments welcome (please keep me on Cc: on replies).
>
> Here's a proposed patch to fix this by testing 'btp' against NULL in
> xfs_free_buftarg().
>
>
> Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
> ---
>
> fs/xfs/linux-2.6/xfs_buf.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
> index db5f5a3..6ef1860 100644
> --- a/fs/xfs/linux-2.6/xfs_buf.c
> +++ b/fs/xfs/linux-2.6/xfs_buf.c
> @@ -1450,6 +1450,9 @@ xfs_free_buftarg(
> xfs_buftarg_t *btp,
> int external)
> {
> + if (unlikely(!btp))
> + return;
> +
> xfs_flush_buftarg(btp, 1);
> if (external)
> xfs_blkdev_put(btp->bt_bdev);
>
>
>
>
next prev parent reply other threads:[~2006-11-16 21:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-16 21:18 [PATCH][RFC][resend] potential NULL pointer deref in XFS on failed mount Jesper Juhl
2006-11-16 21:23 ` Shailendra Tripathi [this message]
[not found] ` <9a8748490611161343x44e759acs9b70247c84452ba5@mail.gmail.com>
2006-11-16 21:44 ` Shailendra Tripathi
[not found] ` <20061116220958.GE11034@melbourne.sgi.com>
[not found] ` <9a8748490611161418l4d5a773k76cf7061d73c8a51@mail.gmail.com>
2006-11-20 14:32 ` Jesper Juhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=455CD6C8.5030907@agami.com \
--to=stripathi@agami.com \
--cc=akpm@osdl.org \
--cc=jesper.juhl@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nathans@sgi.com \
--cc=xfs-masters@oss.sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox