linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Ben Myers <bpm@sgi.com>
Cc: Eric Sandeen <sandeen@sandeen.net>, Alex Elder <elder@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	XFS FILESYSTEM <xfs@oss.sgi.com>,
	"Geyslan G. Bem" <geyslan@gmail.com>,
	kernel-br@googlegroups.com
Subject: Re: [PATCH] xfs: fix possible NULL dereference
Date: Tue, 22 Oct 2013 10:56:01 +1100	[thread overview]
Message-ID: <20131021235601.GG4446@dastard> (raw)
In-Reply-To: <20131021231849.GL10553@sgi.com>

On Mon, Oct 21, 2013 at 06:18:49PM -0500, Ben Myers wrote:
> Hey,
> 
> On Mon, Oct 21, 2013 at 06:12:18PM -0500, Eric Sandeen wrote:
> > On 10/21/13 5:44 PM, Dave Chinner wrote:
> > > On Mon, Oct 21, 2013 at 03:58:23PM -0500, Eric Sandeen wrote:
> > >> On 10/21/13 1:32 PM, Geyslan G. Bem wrote:
> > >>> This patch puts a 'break' in the true branch, avoiding the 'icptr->ic_next'
> > >>> dereferencing.
> > >>
> > >> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> > > 
> > > Actually, NACK.
> > 
> > I felt that one coming ;)
> > 
> > >> Hm, yeah - cmn_err(CE_PANIC, " " ); used to BUG_ON, but the newer
> > >> xfs_emerg() doesn't.
> > >>
> > >> Dave, was that intentional?
> > > 
> > > Of course it was. ;) xfs_emerg() is only called from the debug code
> > > in xlog_verify_iclog(), xlog_verify_tail_lsn and assfail().
> > > 
> > > In the case of assfail(), it has it's own BUG() call, so it does
> > > everything just fine.
> > > 
> > > In the case of xlog_verify_iclog() when icptr is NULL, it will
> > > panic immediately after the message is printed, just like the old
> > > code. i.e. this patch isn't fixing anything we need fixed. 
> > 
> > A BUG() is probably warranted, then.
> 
> I tend to agree with Eric on this point.  If we want to crash, I'd rather our
> intent be very clear, rather than just see a null ptr deref.  ;)

Sure. ASSERT() would be better and more consistent with the rest of
the code. i.e:

        for (i = 0; i < log->l_iclog_bufs; i++, icptr = icptr->ic_next)
		ASSERT(icptr);

<Devil's Advocate>

However, I keep coming back to the fact that what we are checking is
that the list is correctly circular and that and adding an
ASSERT(icptr) to panic if a pointer chase finds a null pointer is
kinda redundant, especially as:

	- there's already 2 comments for the function indicating
	  that it is checking the validity of the pointers and that
	  they are circular....
	- we have repeatedly, over many years, justified the removal
	  of ASSERT(ptr) from code like:

		ASSERT(ptr);
		foo = ptr->foo;

	  as it is redundant because production code will always
	  panic the machine in that situation via the dereference.
	  ASSERT() is for documenting assumptions and constraints
	  that are not obvious from the code context.

IOWs, in this case the presence or absence of the ASSERT inside
*debug-only code* doesn't add any addition value to debugging such
problems, nor does it add any value in terms of documentation
because it's clear from the comments in the debug code that it
should not be NULL to begin with.

</Devil's Advocate>

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2013-10-21 23:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 18:32 [PATCH] xfs: fix possible NULL dereference Geyslan G. Bem
     [not found] ` <5265956F.4010700@sandeen.net>
2013-10-21 22:44   ` Dave Chinner
2013-10-21 23:12     ` Eric Sandeen
2013-10-21 23:18       ` Ben Myers
2013-10-21 23:56         ` Dave Chinner [this message]
2013-10-22  0:00           ` Eric Sandeen
2013-10-22  0:17             ` Dave Chinner
2013-10-22 10:12               ` Geyslan Gregório Bem
2013-10-22 20:39                 ` Dave Chinner
2013-10-22 20:49                   ` Eric Sandeen
2013-10-22 21:03                     ` Dave Chinner
2013-10-22 21:19                       ` Eric Sandeen
2013-10-22 22:02                         ` Dave Chinner
2013-10-22 22:33                           ` Ben Myers
2013-10-25  9:15                           ` Dave Jones
2013-10-23 10:58                         ` Geyslan Gregório Bem
2013-10-23 20:34                           ` Ben Myers
2013-10-23 20:53                             ` Geyslan Gregório Bem
2013-10-30 20:08                             ` Eric Sandeen
2013-10-31 15:55                               ` Ben Myers
2013-10-31 16:15                                 ` Geyslan Gregório Bem

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=20131021235601.GG4446@dastard \
    --to=david@fromorbit.com \
    --cc=bpm@sgi.com \
    --cc=elder@kernel.org \
    --cc=geyslan@gmail.com \
    --cc=kernel-br@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    --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;
as well as URLs for NNTP newsgroup(s).