linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Jeff Layton <jlayton@kernel.org>, linux-nfs@vger.kernel.org
Subject: Re: nfs4_show_superblock considered harmful :-)
Date: Mon, 01 Jun 2020 12:01:07 +1000	[thread overview]
Message-ID: <87a71n7dek.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <20200529220608.GA22758@fieldses.org>

[-- Attachment #1: Type: text/plain, Size: 1880 bytes --]

On Fri, May 29 2020, J. Bruce Fields wrote:

> On Fri, May 29, 2020 at 10:53:15AM +1000, NeilBrown wrote:
>>  I've received a report of a 5.3 kernel crashing in
>>  nfs4_show_superblock().
>>  I was part way through preparing a patch when I concluded that
>>  the problem wasn't as straight forward as I thought.
>>
>>  In the crash, the 'struct file *' passed to nfs4_show_superblock()
>>  was NULL.
>>  This file was acquired from find_any_file(), and every other caller
>>  of find_any_file() checks that the returned value is not NULL (though
>>  one BUGs if it is NULL - another WARNs).
>>  But nfs4_show_open() and nfs4_show_lock() don't.
>>  Maybe they should.  I didn't double check, but I suspect they don't
>>  hold enough locks to ensure that the files don't get removed.
>
> I think the only lock held is cl_lock, acquired in states_start.
>
> We're starting here with an nfs4_stid that was found in the cl_stateids
> idr.
>
> A struct nfs4_stid is freed by nfs4_put_stid(), which removes it from
> that idr under cl_lock before freeing the nfs4_stid and anything it
> points to.
>
> I think that was the theory....
>
> One possible problem is downgrades, like nfs4_stateid_downgrade.
>
> I'll keep mulling it over, thanks.

I had another look at code and maybe move_to_close_lru() is the problem.
It can clear remove the files and clear sc_file without taking
cl_lock.  So some protection is needed against that.

I think that only applies to nfs4_show_open() - not show_lock etc.
But I wonder it is might be best to include some extra protection
for each different case, just in case some future code change
allow sc_file to become NULL before the state is detached.

I'd feel more comforatable about nfs4_show_superblock() if it ignored
nf_inode and just used nf_file - it is isn't NULL.  It looks like it
can never be set from non-NULL to NULL.

Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2020-06-01  2:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29  0:53 nfs4_show_superblock considered harmful :-) NeilBrown
2020-05-29 22:06 ` J. Bruce Fields
2020-06-01  2:01   ` NeilBrown [this message]
2020-07-15 18:54     ` J. Bruce Fields
2020-07-15 23:05       ` NeilBrown
2020-07-15 23:43         ` J. Bruce Fields
2020-07-16 17:19       ` J. Bruce Fields
2020-07-16 23:43         ` NeilBrown
2020-07-17  1:03           ` J. Bruce Fields
2020-07-17  1:31             ` NeilBrown
2020-07-17  2:18               ` J. Bruce Fields

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=87a71n7dek.fsf@notabene.neil.brown.name \
    --to=neilb@suse.de \
    --cc=bfields@fieldses.org \
    --cc=jlayton@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).