linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kinglong Mee <kinglongmee@gmail.com>
To: houlinfei <hou.linfei@h3c.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	linux-nfs@vger.kernel.org, NeilBrown <neilb@suse.com>,
	Steve Dickson <SteveD@redhat.com>,
	Kinglong Mee <kinglongmee@gmail.com>
Subject: Re: some problems about permission of subdirectory
Date: Sat, 25 Feb 2017 18:45:02 +0800	[thread overview]
Message-ID: <159b79d2-78f5-17e8-5287-069ed7943975@gmail.com> (raw)
In-Reply-To: <20170224191435.GA26378@fieldses.org>

On 2/25/2017 03:14, J. Bruce Fields wrote:
> On Tue, Feb 21, 2017 at 09:50:01PM +0800, Kinglong Mee wrote:
>> On 2/21/2017 16:52, houlinfei wrote:
>>>
>>> hi everyone:
>>> I met a problem about subdirectory permission when client mount this subdirectory using nfs4. For example:
>>> the contents of the /etc/exports file is
>>> /root/hh *(ro,sync,insecure,no_subtree_check)
>>> /root/hh/hh1 *(rw,sync,insecure,no_subtree_check)
>>> and the two directory permission is 777. And the parent directory's export permission is read-only, the subdirectory's export permission is read-write.
>>> Then client mount /root/hh/hh1 on /mnt/yy using nfs4. But the /mnt/yy directory only can read.If client mount /root/hh/hh1 on /mnt/yy using nfs3, the /mnt/yy can write.
>>
>> nfs3 gets the filehandle of /root/hh/hh1 from rpc.mountd before really mounting, 
>> so that, nfs3 do the later process with the filehandle of /root/hh/hh1,
>> with the second exports entry.
>>  
>> But, nfs4 get the filehandle by LOOKUP through nfsd step by step, 
>> at first, LOOKUP "/" as the pseudo filesystem with an pseudo exports entry,
>> second, LOOKUP "/root/" also use the pseudo export entry, 
>> next, LOOKUP "/root/hh/" will get a new export entry
>> for "/root/" use a pseudo export entry, but at last LOOKUP "/root/hh/hh1",
>> nfsd uses the export entry for "/root/hh/" that isn't a pseudo entry entry.
>>
>> So that, nfsv3 client can write the directory, but nfsv4 client can't.
>>
>>> Who know how to solve this problem about nfs4? Thanks very much~
>>
>> Without change any codes of rpc.mountd and nfsd, there is a hacker method for it.
>> # chmod -x /root/hh/hh1
>> # chmod +t /root/hh/hh1
>> # setfattr -n "trusted.junction.nfs" -v "anything" /root/hh/hh1
>>
>> Umount the nfs and remount as nfsv4.
>>
>> Cc Bruce, Neil, Steve,
>>
>> Is it needed adding an xattr as "junction.nfs" for fixing this problem?
> 
> Maybe.  Or another trick you can use right now is to create a mountpoint
> there by mounting that directory on top of itself:
> 
> 	mount --bind /root/hh/hh1 /root/hh/hh1
> 
> However, I strongly discourage this kind of setup.
> 
> The problem is that it's very easy for an attacker to fake up a
> filehandle that points to a file under /root/hh while looking like it
> points to a file under /root/hh/hh1, and therefore get rw access to
> something outside /root/hh/hh1.  Turning on "subtree_check" will fix
> that problem, but can cause other problems.
> 
> It's much better, whenever possible, to use entirely different
> filesystems whenever you need to grant different access.

Hi linfei,

Can the two suggestions resolve your requirements?
I don't think the hacker method that change the code is sensible.

thanks,
Kinglong Mee

  reply	other threads:[~2017-02-25 11:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21  8:52 some problems about permission of subdirectory houlinfei
2017-02-21 13:50 ` Kinglong Mee
2017-02-24 19:14   ` J. Bruce Fields
2017-02-25 10:45     ` Kinglong Mee [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-02-22  7:16 houlinfei
2017-02-22  8:00 ` Kinglong Mee
2017-02-23  3:53 houlinfei
2017-02-23  8:18 ` Kinglong Mee
2017-02-23 15:21 houlinfei
2017-02-25  9:44 houlinfei
2017-02-25 10:51 ` Kinglong Mee
2017-02-25 13:26 houlinfei
2017-02-26  0:23 ` Kinglong Mee

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=159b79d2-78f5-17e8-5287-069ed7943975@gmail.com \
    --to=kinglongmee@gmail.com \
    --cc=SteveD@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=hou.linfei@h3c.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.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).