From: Jeff Layton <jlayton@kernel.org>
To: "Hanxiao Chen (Fujitsu)" <chenhx.fnst@fujitsu.com>,
Chuck Lever <chuck.lever@oracle.com>, Neil Brown <neilb@suse.de>,
Olga Kornievskaia <kolga@netapp.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH] NFSD: nfsctl: remove read permission of filehandle
Date: Wed, 20 Mar 2024 12:27:36 -0400 [thread overview]
Message-ID: <21f3580de20445ddd9bdae6eecc316a58b6df97d.camel@kernel.org> (raw)
In-Reply-To: <TYWPR01MB1208550A963443FA4F3FC5335E6332@TYWPR01MB12085.jpnprd01.prod.outlook.com>
On Wed, 2024-03-20 at 15:49 +0000, Hanxiao Chen (Fujitsu) wrote:
>
> > -----邮件原件-----
> > 发件人: Jeff Layton <jlayton@kernel.org>
> > 发送时间: 2024年3月19日 21:09
> > 收件人: Chen, Hanxiaochenhx.fnst@fujitsu.com>; Chuck Lever
> > <chuck.lever@oracle.com>; Neil Brown <neilb@suse.de>; Olga Kornievskaia
> > <kolga@netapp.com>; Dai Ngo <Dai.Ngo@oracle.com>; Tom Talpey
> > <tom@talpey.com>
> > 抄送: linux-nfs@vger.kernel.org
> > 主题: Re: [PATCH] NFSD: nfsctl: remove read permission of filehandle
> >
> > On Tue, 2024-03-19 at 18:47 +0800, Chen Hanxiao wrote:
> > > As write_filehandle can't accept zero-bytes writting,
> > > remove read permission of /proc/fs/nfsd/filehandle
> > >
> > > Signed-off-by: Chen Hanxiao <chenhx.fnst@fujitsu.com>
> ...
> >
> >
> > I don't think we can do this. mountd does this to get the rootfh for an
> > exported fs and it'll probably start failing if it can't open that file
> > for read:
> >
> > f = open("/proc/fs/nfsd/filehandle", O_RDWR);
> >
> > That write_filehandle interface sure is weird though. Could we get rid
> > of it by teaching cache_get_filehandle how to use name_to_handle_at
> > instead? That would be a lot cleaner and would get rid of yet another
> > dependency on /proc/fs/nfsd.
>
> name_to_handle_at return struct file_handle
> cache_get_filehandle return hexed struct knfsd_fh
>
> Could you please give some hints on how to convert from file_handle. f_handle to knfsd_fh.fh_raw?
>
I started looking at this yesterday. knfsd_fh is mostly constructed in
fh_compose. The exportfs_encode_fh call is in _fh_update. If we look at
the comments over knfsd_fh, it explains pretty well what we need to fill
out:
fh_version : should always be 1
fh_auth_type: always 0
fh_fsid_type: this is the tricky part (see below)
fh_fileid_type: returned by name_to_handle_at
fh_fsid: fsid concatenated with the fileid for the inode
name_to_handle_at should be able to fill out the fileid portion of the
knfsd_fh. The harder part is: how do we get the fh_fsid_type and its
content?
The types are shown here:
* The fsid_type identifies how the filesystem (or export point) is
* encoded.
* Current values:
* 0 - 4 byte device id (ms-2-bytes major, ls-2-bytes minor), 4byte inode number
* NOTE: we cannot use the kdev_t device id value, because kdev_t.h
* says we mustn't. We must break it up and reassemble.
* 1 - 4 byte user specified identifier
* 2 - 4 byte major, 4 byte minor, 4 byte inode number - DEPRECATED
* 3 - 4 byte device id, encoded for user-space, 4 byte inode number
* 4 - 4 byte inode number and 4 byte uuid
* 5 - 8 byte uuid
* 6 - 16 byte uuid
* 7 - 8 byte inode number and 16 byte uuid
The kernel decides this in set_version_and_fsid_type, so I suppose we
could try to replicate that logic in userland.
There is the problem though of what to do about exports with the fsid=
option set. That's tougher to determine from userland, but maybe we can
somehow get that from the export record?
That's about as far as I got with it yesterday...
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2024-03-20 16:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 10:47 [PATCH] NFSD: nfsctl: remove read permission of filehandle Chen Hanxiao
2024-03-19 13:09 ` Jeff Layton
2024-03-20 15:49 ` Hanxiao Chen (Fujitsu)
2024-03-20 16:27 ` Jeff Layton [this message]
2024-03-27 6:40 ` Chen Hanxiao
2024-03-27 10:50 ` 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=21f3580de20445ddd9bdae6eecc316a58b6df97d.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chenhx.fnst@fujitsu.com \
--cc=chuck.lever@oracle.com \
--cc=kolga@netapp.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
--cc=tom@talpey.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