qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH v3 01/10] virtiofsd: Limit setxattr()'s creds-dropped region
Date: Mon, 9 Aug 2021 12:30:40 +0200	[thread overview]
Message-ID: <65036c43-8ea6-769c-d616-3ebe1c626f53@redhat.com> (raw)
In-Reply-To: <YQ1EJxcBlUHA8uek@redhat.com>

On 06.08.21 16:16, Vivek Goyal wrote:
> On Fri, Jul 30, 2021 at 05:01:25PM +0200, Max Reitz wrote:
>> We only need to drop/switch our credentials for the (f)setxattr() call
>> alone, not for the openat() or fchdir() around it.
>>
>> (Right now, this may not be that big of a problem, but with inodes being
>> identified by file handles instead of an O_PATH fd, we will need
>> open_by_handle_at() calls here, which is really fickle when it comes to
>> credentials being dropped.)
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   tools/virtiofsd/passthrough_ll.c | 34 +++++++++++++++++++++++---------
>>   1 file changed, 25 insertions(+), 9 deletions(-)
>>
>> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
>> index 38b2af8599..1f27eeabc5 100644
>> --- a/tools/virtiofsd/passthrough_ll.c
>> +++ b/tools/virtiofsd/passthrough_ll.c
>> @@ -3121,6 +3121,7 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
>>       bool switched_creds = false;
>>       bool cap_fsetid_dropped = false;
>>       struct lo_cred old = {};
>> +    bool open_inode;
>>   
>>       if (block_xattr(lo, in_name)) {
>>           fuse_reply_err(req, EOPNOTSUPP);
>> @@ -3155,7 +3156,24 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
>>       fuse_log(FUSE_LOG_DEBUG, "lo_setxattr(ino=%" PRIu64
>>                ", name=%s value=%s size=%zd)\n", ino, name, value, size);
>>   
>> +    /*
>> +     * We can only open regular files or directories.  If the inode is
>> +     * something else, we have to enter /proc/self/fd and use
>> +     * setxattr() on the link's filename there.
>> +     */
>> +    open_inode = S_ISREG(inode->filetype) || S_ISDIR(inode->filetype);
>>       sprintf(procname, "%i", inode->fd);
>> +    if (open_inode) {
>> +        fd = openat(lo->proc_self_fd, procname, O_RDONLY);
>> +        if (fd < 0) {
>> +            saverr = errno;
>> +            goto out;
>> +        }
>> +    } else {
>> +        /* fchdir should not fail here */
>> +        FCHDIR_NOFAIL(lo->proc_self_fd);
>> +    }
>> +
>>       /*
>>        * If we are setting posix access acl and if SGID needs to be
>>        * cleared, then switch to caller's gid and drop CAP_FSETID
>> @@ -3176,20 +3194,13 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
>>           }
>>           switched_creds = true;
>>       }
>> -    if (S_ISREG(inode->filetype) || S_ISDIR(inode->filetype)) {
>> -        fd = openat(lo->proc_self_fd, procname, O_RDONLY);
>> -        if (fd < 0) {
>> -            saverr = errno;
>> -            goto out;
>> -        }
>> +    if (open_inode) {
>> +        assert(fd >= 0);
>>           ret = fsetxattr(fd, name, value, size, flags);
>>           saverr = ret == -1 ? errno : 0;
>>       } else {
>> -        /* fchdir should not fail here */
>> -        FCHDIR_NOFAIL(lo->proc_self_fd);
>>           ret = setxattr(procname, name, value, size, flags);
>>           saverr = ret == -1 ? errno : 0;
>> -        FCHDIR_NOFAIL(lo->root.fd);
>>       }
>>       if (switched_creds) {
>>           if (cap_fsetid_dropped)
>> @@ -3198,6 +3209,11 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
>>               lo_restore_cred(&old, false);
>>       }
>>   
>> +    if (!open_inode) {
>> +        /* Change CWD back, fchdir should not fail here */
>> +        FCHDIR_NOFAIL(lo->root.fd);
>> +    }
>> +
> This FCHDIR_NOFAIL() will also need to be called if lo_drop_cap_change_cred()
> fails.
>
>          ret = lo_drop_cap_change_cred(req, &old, false, "FSETID",
>                                        &cap_fsetid_dropped);
>          if (ret) {
>              saverr = ret;
>              goto out;
>          }

Oh, right, thanks!

Max



  reply	other threads:[~2021-08-09 10:31 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30 15:01 [PATCH v3 00/10] virtiofsd: Allow using file handles instead of O_PATH FDs Max Reitz
2021-07-30 15:01 ` [PATCH v3 01/10] virtiofsd: Limit setxattr()'s creds-dropped region Max Reitz
2021-08-06 14:16   ` Vivek Goyal
2021-08-09 10:30     ` Max Reitz [this message]
2021-07-30 15:01 ` [PATCH v3 02/10] virtiofsd: Add TempFd structure Max Reitz
2021-08-06 14:41   ` Vivek Goyal
2021-08-09 10:44     ` Max Reitz
2021-07-30 15:01 ` [PATCH v3 03/10] virtiofsd: Use lo_inode_open() instead of openat() Max Reitz
2021-08-06 15:42   ` Vivek Goyal
2021-07-30 15:01 ` [PATCH v3 04/10] virtiofsd: Add lo_inode_fd() helper Max Reitz
2021-08-06 18:25   ` Vivek Goyal
2021-08-09 10:48     ` Max Reitz
2021-07-30 15:01 ` [PATCH v3 05/10] virtiofsd: Let lo_fd() return a TempFd Max Reitz
2021-07-30 15:01 ` [PATCH v3 06/10] virtiofsd: Let lo_inode_open() " Max Reitz
2021-08-06 19:55   ` Vivek Goyal
2021-08-09 13:40     ` Max Reitz
2021-07-30 15:01 ` [PATCH v3 07/10] virtiofsd: Add lo_inode.fhandle Max Reitz
2021-08-09 15:21   ` Vivek Goyal
2021-08-09 16:41     ` Hanna Reitz
2021-07-30 15:01 ` [PATCH v3 08/10] virtiofsd: Add inodes_by_handle hash table Max Reitz
2021-08-09 16:10   ` Vivek Goyal
2021-08-09 16:47     ` Hanna Reitz
2021-08-10 14:07       ` Vivek Goyal
2021-08-10 14:13         ` Hanna Reitz
2021-08-10 17:51           ` Vivek Goyal
2021-07-30 15:01 ` [PATCH v3 09/10] virtiofsd: Optionally fill lo_inode.fhandle Max Reitz
2021-08-09 18:41   ` Vivek Goyal
2021-08-10  8:32     ` Hanna Reitz
2021-08-10 15:23       ` Vivek Goyal
2021-08-10 15:26         ` Hanna Reitz
2021-08-10 15:57           ` Vivek Goyal
2021-08-11  6:41             ` Hanna Reitz
2021-08-16 19:44               ` Vivek Goyal
2021-08-17  8:27                 ` Hanna Reitz
2021-08-17 19:45                   ` Vivek Goyal
2021-08-18  0:14                     ` Vivek Goyal
2021-08-18 13:32                       ` Vivek Goyal
2021-08-18 13:48                         ` Hanna Reitz
2021-08-19 16:38   ` Dr. David Alan Gilbert
2021-07-30 15:01 ` [PATCH v3 10/10] virtiofsd: Add lazy lo_do_find() Max Reitz
2021-08-09 19:08   ` Vivek Goyal
2021-08-10  8:38     ` Hanna Reitz
2021-08-10 14:12       ` Vivek Goyal
2021-08-10 14:17         ` Hanna Reitz

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=65036c43-8ea6-769c-d616-3ebe1c626f53@redhat.com \
    --to=mreitz@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@redhat.com \
    --cc=virtio-fs@redhat.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).