linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jesper Juhl <jj@chaosbits.net>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kendrick Smith <kmsmith@umich.edu>,
	Andy Adamson <kandros@umich.edu>,
	Trond Myklebust <Trond.Myklebust@netapp.com>
Subject: Re: [PATCH] NFS4: Fix NULL deref in nfsd4_lock() by makeing unhash_lockowner() safe to call with NULL arg
Date: Mon, 30 Jan 2012 16:43:51 -0500	[thread overview]
Message-ID: <20120130214351.GA1518@fieldses.org> (raw)
In-Reply-To: <alpine.LNX.2.00.1201292226380.27749@swampdragon.chaosbits.net>

On Sun, Jan 29, 2012 at 10:29:24PM +0100, Jesper Juhl wrote:
> The Coverity checker noticed a path through nfsd4_lock() where we call
> release_lockowner(lock_sop); (at the 'out:' label) where 'lock_sop' is
> NULL.
> That goes bad since release_lockowner() calls unhash_lockowner() which
> dereferences its argument.
> release_lockowner() also calls nfs4_free_lockowner(), but that's not a
> problem since that function just calls kfree() and kmem_cache_free(),
> both of which are safe to call with NULL as argument.
> 
> There are several ways to fix the bug.
>  - rework nfsd4_lock() so the call to release_lockowner(NULL) will never happen.
>  - let release_lockowner() test for NULL and return if given one.
>  - let unhash_lockowner() test for NULL and return if given one (which makes both it and release_lockowner() safe).
> 
> I chose the last option for this patch.
> 
> For information, the path Coverity spotted (in defect report 201504) is this:
> 
...


> [...]
> 4098out:
> At conditional (12): "status" taking the true branch.
> At conditional (13): "new_state" taking the true branch.
> 4099        if (status && new_state)

new_state is initialized false, and referenced otherwise only once,
when a reference ot is is passed here:


> 4010                status = lookup_or_create_lock_state(cstate, open_stp, lock,
> 4011                                                        &lock_stp, &new_state);

so if new_state is true, then lookup_or_create_lock_state() set it to
true.  But it sets that only in one spot, at the end:

	*new = true;
	return nfs_ok;

Note nfs_ok is zero.  Therefore:

> At conditional (11): "status" taking the true branch.
> 4012                if (status)
> 4013                        goto out;

this could not have happened.

So it looks like a Coverity bug.

--b.

  reply	other threads:[~2012-01-30 21:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29 21:29 [PATCH] NFS4: Fix NULL deref in nfsd4_lock() by makeing unhash_lockowner() safe to call with NULL arg Jesper Juhl
2012-01-30 21:43 ` J. Bruce Fields [this message]
2012-07-22 21:01   ` 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=20120130214351.GA1518@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=Trond.Myklebust@netapp.com \
    --cc=jj@chaosbits.net \
    --cc=kandros@umich.edu \
    --cc=kmsmith@umich.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /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).