Linux filesystem development
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Chuck Lever III <chuck.lever@oracle.com>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Jeff Layton <jlayton@kernel.org>,
	Frank van der Linden <fllinden@amazon.com>,
	Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH] nfsd: don't use GFP_KERNEL from nfsd_getxattr()/nfsd_listxattr()
Date: Thu, 20 Apr 2023 09:32:43 +1000	[thread overview]
Message-ID: <20230419233243.GM447837@dread.disaster.area> (raw)
In-Reply-To: <A23409BB-9BA1-44E5-96A8-C080B417CCB5@oracle.com>

On Wed, Apr 19, 2023 at 01:51:12PM +0000, Chuck Lever III wrote:
> 
> 
> > On Apr 16, 2023, at 7:37 PM, Dave Chinner <david@fromorbit.com> wrote:
> > 
> > On Sun, Apr 16, 2023 at 07:51:41AM -0400, Jeff Layton wrote:
> >> On Sun, 2023-04-16 at 08:21 +0900, Tetsuo Handa wrote:
> >>> On 2023/04/16 3:40, Jeff Layton wrote:
> >>>> On Sun, 2023-04-16 at 02:11 +0900, Tetsuo Handa wrote:
> >>>>> On 2023/04/16 1:13, Chuck Lever III wrote:
> >>>>>>> On Apr 15, 2023, at 7:07 AM, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> >>>>>>> 
> >>>>>>> Since GFP_KERNEL is GFP_NOFS | __GFP_FS, usage like GFP_KERNEL | GFP_NOFS
> >>>>>>> does not make sense. Drop __GFP_FS flag in order to avoid deadlock.
> >>>>>> 
> >>>>>> The server side threads run in process context. GFP_KERNEL
> >>>>>> is safe to use here -- as Jeff said, this code is not in
> >>>>>> the server's reclaim path. Plenty of other call sites in
> >>>>>> the NFS server code use GFP_KERNEL.
> >>>>> 
> >>>>> GFP_KERNEL memory allocation calls filesystem's shrinker functions
> >>>>> because of __GFP_FS flag. My understanding is
> >>>>> 
> >>>>>  Whether this code is in memory reclaim path or not is irrelevant.
> >>>>>  Whether memory reclaim path might hold lock or not is relevant.
> >>>>> 
> >>>>> . Therefore, question is, does nfsd hold i_rwsem during memory reclaim path?
> >>>>> 
> >>>> 
> >>>> No. At the time of these allocations, the i_rwsem is not held.
> >>> 
> >>> Excuse me? nfsd_getxattr()/nfsd_listxattr() _are_ holding i_rwsem
> >>> via inode_lock_shared(inode) before kvmalloc(GFP_KERNEL | GFP_NOFS) allocation.
> >>> That's why
> >>> 
> >>> /*
> >>>  * We're holding i_rwsem - use GFP_NOFS.
> >>>  */
> >>> 
> >>> is explicitly there in nfsd_listxattr() side.
> > 
> > You can do GFP_KERNEL allocations holding the i_rwsem just fine.
> > All that it requires is the caller holds a reference to the inode,
> > and at that point inode will should skip the given inode without
> > every locking it.
> 
> This suggests that the fix is to replace "GFP_KERNEL | GFP_NOFS"
> with "GFP_KERNEL" /and/ ensure those paths are holding an
> appropriate inode reference.

If the code that provided the inode to nfsd_listxattr() did not
already have an active inode reference in the first place then there
are much, much bigger UAF problems to worry about than simple
memory reclaim deadlocks.

That said, nfsd_listxattr() does:

        dentry = fhp->fh_dentry;
        inode = d_inode(dentry);
        *lenp = 0;

        inode_lock_shared(inode);

        len = vfs_listxattr(dentry, NULL, 0);

Given that a dentry pointing to an inode *must* hold an active
reference to that inode, I don't see how it is possible this code
path could be using an unreferenced inode.

nfsd_getxattr() has a similar code fragment to obtain the inode as
well, so same goes for that...

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2023-04-19 23:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <72bf692e-bb6b-c1f2-d1ba-3205ab649b43@I-love.SAKURA.ne.jp>
     [not found] ` <4BC7955B-40E4-4A43-B2D1-2E9302E84337@oracle.com>
     [not found]   ` <b014047a-4a70-b38f-c5bb-01bc3c53d6f2@I-love.SAKURA.ne.jp>
     [not found]     ` <aee35d52ab19e7e95f69742be8329764db72cbf8.camel@kernel.org>
     [not found]       ` <c310695e-4279-b1a7-5c2a-2771cc19aa66@I-love.SAKURA.ne.jp>
2023-04-16 11:51         ` [PATCH] nfsd: don't use GFP_KERNEL from nfsd_getxattr()/nfsd_listxattr() Jeff Layton
2023-04-16 16:20           ` Chuck Lever III
2023-04-16 23:37           ` Dave Chinner
2023-04-17 22:25             ` Frank van der Linden
2023-04-17 23:07               ` Frank van der Linden
2023-04-19 13:51             ` Chuck Lever III
2023-04-19 23:32               ` Dave Chinner [this message]
2023-04-20 13:41                 ` Chuck Lever III
2023-04-20 14:05                   ` Tetsuo Handa
2023-04-20 14:41                     ` Chuck Lever III
2023-04-20 15:20             ` Jeff Layton

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=20230419233243.GM447837@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=chuck.lever@oracle.com \
    --cc=fllinden@amazon.com \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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