linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RESEND] fix a potential NULL pointer deref in XFS on failed mount.
@ 2007-08-04 18:30 Jesper Juhl
  2007-08-06  0:52 ` David Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2007-08-04 18:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Linux Kernel Mailing List, David Chinner, xfs, xfs-masters, Jesper Juhl

Back in 2006 (2006-10-31 to be specific, reposted on 2006-11-16), I 
submitted a patch to fix a potential NULL pointer deref in XFS on 
failed mount.

The patch drew some comments and it turned out that my initial 
approach to a fix was wrong.
David Chinner kindly offered some tips on how to implement a proper 
fix, and on 2006-11-20 I submitted a revised fix.  This patch, 
unfortunately, didn't draw any comments, nor did it ever get merged 
anywhere.  
I believe that now sufficient time has passed to warrent a repost.

And now, on August 4, 2007 - yet another resend. 
it would really be nice if this patch could either get merged or, 
if it is wrong for some reason, get an explicit NACK. Come on people, 
what's it going to be?



The Coverity checker spotted (as bug #346) 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.

This patch fixes the issue by checking mp->m_logdev_targp against NULL 
in xfs_unmountfs_close() and doing the proper xfs_blkdev_put(logdev); 
and xfs_blkdev_put(rtdev); on (!mp->m_rtdev_targp) in xfs_mount().

Compile tested.

Comments and feedback welcome.

Please consider merging.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---
 fs/xfs/xfs_mount.c  |    2 +-
 fs/xfs/xfs_vfsops.c |   10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index a66b398..215e041 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -1275,7 +1275,7 @@ xfs_unmountfs(xfs_mount_t *mp, struct cred *cr)
 void
 xfs_unmountfs_close(xfs_mount_t *mp, struct cred *cr)
 {
-	if (mp->m_logdev_targp != mp->m_ddev_targp)
+	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);
diff --git a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c
index 11f5ea2..6d4bc5d 100644
--- a/fs/xfs/xfs_vfsops.c
+++ b/fs/xfs/xfs_vfsops.c
@@ -482,13 +482,19 @@ xfs_mount(
 	}
 	if (rtdev) {
 		mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
-		if (!mp->m_rtdev_targp)
+		if (!mp->m_rtdev_targp) {
+			xfs_blkdev_put(logdev);
+			xfs_blkdev_put(rtdev);
 			goto error0;
+		}
 	}
 	mp->m_logdev_targp = (logdev && logdev != ddev) ?
 				xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
-	if (!mp->m_logdev_targp)
+	if (!mp->m_logdev_targp) {
+		xfs_blkdev_put(logdev);
+		xfs_blkdev_put(rtdev);
 		goto error0;
+	}
 
 	/*
 	 * Setup flags based on mount(2) options and then the superblock




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][RESEND] fix a potential NULL pointer deref in XFS on failed mount.
  2007-08-04 18:30 [PATCH][RESEND] fix a potential NULL pointer deref in XFS on failed mount Jesper Juhl
@ 2007-08-06  0:52 ` David Chinner
  2007-08-07 19:51   ` Jesper Juhl
  0 siblings, 1 reply; 3+ messages in thread
From: David Chinner @ 2007-08-06  0:52 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Andrew Morton, Linux Kernel Mailing List, David Chinner, xfs,
	xfs-masters

On Sat, Aug 04, 2007 at 08:30:21PM +0200, Jesper Juhl wrote:
> Back in 2006 (2006-10-31 to be specific, reposted on 2006-11-16), I 
> submitted a patch to fix a potential NULL pointer deref in XFS on 
> failed mount.

Already checked into xfs-dev tree. Will go to next mainline merge.

http://oss.sgi.com/archives/xfs/2007-08/msg00030.html

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][RESEND] fix a potential NULL pointer deref in XFS on failed mount.
  2007-08-06  0:52 ` David Chinner
@ 2007-08-07 19:51   ` Jesper Juhl
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Juhl @ 2007-08-07 19:51 UTC (permalink / raw)
  To: David Chinner; +Cc: Andrew Morton, Linux Kernel Mailing List, xfs, xfs-masters

On 06/08/07, David Chinner <dgc@sgi.com> wrote:
> On Sat, Aug 04, 2007 at 08:30:21PM +0200, Jesper Juhl wrote:
> > Back in 2006 (2006-10-31 to be specific, reposted on 2006-11-16), I
> > submitted a patch to fix a potential NULL pointer deref in XFS on
> > failed mount.
>
> Already checked into xfs-dev tree. Will go to next mainline merge.
>
> http://oss.sgi.com/archives/xfs/2007-08/msg00030.html
>

Ok. Thanks a lot for the feedback David.

-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-07 19:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04 18:30 [PATCH][RESEND] fix a potential NULL pointer deref in XFS on failed mount Jesper Juhl
2007-08-06  0:52 ` David Chinner
2007-08-07 19:51   ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).