qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PULL] VirtFS update
Date: Mon, 10 Dec 2012 10:58:53 -0600	[thread overview]
Message-ID: <87ip89269e.fsf@codemonkey.ws> (raw)
In-Reply-To: <87d2yoe9q2.fsf@linux.vnet.ibm.com>

"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> writes:

> The following changes since commit 16c6c80ac3a772b42a87b77dfdf0fdac7c607b0e:
>
>   Open up 1.4 development branch (2012-12-03 14:08:40 -0600)
>
> are available in the git repository at:
>
>   git://github.com/kvaneesh/qemu.git for-upstream
>
> for you to fetch changes up to 9fd2ecdc8cb2dc1a8a7c57b6c9c60bc9947b6a73:
>
>   virtfs-proxy-helper: use setresuid and setresgid (2012-12-05 21:55:54 +0530)
>

Pulled. Thanks.

Regards,

Anthony Liguori

> ----------------------------------------------------------------
> Paolo Bonzini (1):
>       virtfs-proxy-helper: use setresuid and setresgid
>
>  fsdev/virtfs-proxy-helper.c |   93 +++++++++++++++++++++++++++++--------------
>  1 file changed, 64 insertions(+), 29 deletions(-)
>
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index f9a8270..df2a939 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -272,31 +272,76 @@ static int send_status(int sockfd, struct iovec *iovec, int status)
>  /*
>   * from man 7 capabilities, section
>   * Effect of User ID Changes on Capabilities:
> - * 4. If the file system user ID is changed from 0 to nonzero (see setfsuid(2))
> - * then the following capabilities are cleared from the effective set:
> - * CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH,  CAP_FOWNER, CAP_FSETID,
> - * CAP_LINUX_IMMUTABLE  (since  Linux 2.2.30), CAP_MAC_OVERRIDE, and CAP_MKNOD
> - * (since Linux 2.2.30). If the file system UID is changed from nonzero to 0,
> - * then any of these capabilities that are enabled in the permitted set
> - * are enabled in the effective set.
> + * If the effective user ID is changed from nonzero to 0, then the permitted
> + * set is copied to the effective set.  If the effective user ID is changed
> + * from 0 to nonzero, then all capabilities are are cleared from the effective
> + * set.
> + *
> + * The setfsuid/setfsgid man pages warn that changing the effective user ID may
> + * expose the program to unwanted signals, but this is not true anymore: for an
> + * unprivileged (without CAP_KILL) program to send a signal, the real or
> + * effective user ID of the sending process must equal the real or saved user
> + * ID of the target process.  Even when dropping privileges, it is enough to
> + * keep the saved UID to a "privileged" value and virtfs-proxy-helper won't
> + * be exposed to signals.  So just use setresuid/setresgid.
>   */
> -static int setfsugid(int uid, int gid)
> +static int setugid(int uid, int gid, int *suid, int *sgid)
>  {
> +    int retval;
> +
>      /*
> -     * We still need DAC_OVERRIDE because  we don't change
> +     * We still need DAC_OVERRIDE because we don't change
>       * supplementary group ids, and hence may be subjected DAC rules
>       */
>      cap_value_t cap_list[] = {
>          CAP_DAC_OVERRIDE,
>      };
>  
> -    setfsgid(gid);
> -    setfsuid(uid);
> +    *suid = geteuid();
> +    *sgid = getegid();
> +
> +    if (setresgid(-1, gid, *sgid) == -1) {
> +        retval = -errno;
> +        goto err_out;
> +    }
> +
> +    if (setresuid(-1, uid, *suid) == -1) {
> +        retval = -errno;
> +        goto err_sgid;
> +    }
>  
>      if (uid != 0 || gid != 0) {
> -        return do_cap_set(cap_list, ARRAY_SIZE(cap_list), 0);
> +        if (do_cap_set(cap_list, ARRAY_SIZE(cap_list), 0) < 0) {
> +            retval = -errno;
> +            goto err_suid;
> +        }
>      }
>      return 0;
> +
> +err_suid:
> +    if (setresuid(-1, *suid, *suid) == -1) {
> +        abort();
> +    }
> +err_sgid:
> +    if (setresgid(-1, *sgid, *sgid) == -1) {
> +        abort();
> +    }
> +err_out:
> +    return retval;
> +}
> +
> +/*
> + * This is used to reset the ugid back with the saved values
> + * There is nothing much we can do checking error values here.
> + */
> +static void resetugid(int suid, int sgid)
> +{
> +    if (setresgid(-1, sgid, sgid) == -1) {
> +        abort();
> +    }
> +    if (setresuid(-1, suid, suid) == -1) {
> +        abort();
> +    }
>  }
>  
>  /*
> @@ -578,18 +623,15 @@ static int do_create_others(int type, struct iovec *iovec)
>  
>      v9fs_string_init(&path);
>      v9fs_string_init(&oldpath);
> -    cur_uid = geteuid();
> -    cur_gid = getegid();
>  
>      retval = proxy_unmarshal(iovec, offset, "dd", &uid, &gid);
>      if (retval < 0) {
>          return retval;
>      }
>      offset += retval;
> -    retval = setfsugid(uid, gid);
> +    retval = setugid(uid, gid, &cur_uid, &cur_gid);
>      if (retval < 0) {
> -        retval = -errno;
> -        goto err_out;
> +        goto unmarshal_err_out;
>      }
>      switch (type) {
>      case T_MKNOD:
> @@ -619,9 +661,10 @@ static int do_create_others(int type, struct iovec *iovec)
>      }
>  
>  err_out:
> +    resetugid(cur_uid, cur_gid);
> +unmarshal_err_out:
>      v9fs_string_free(&path);
>      v9fs_string_free(&oldpath);
> -    setfsugid(cur_uid, cur_gid);
>      return retval;
>  }
>  
> @@ -641,24 +684,16 @@ static int do_create(struct iovec *iovec)
>      if (ret < 0) {
>          goto unmarshal_err_out;
>      }
> -    cur_uid = geteuid();
> -    cur_gid = getegid();
> -    ret = setfsugid(uid, gid);
> +    ret = setugid(uid, gid, &cur_uid, &cur_gid);
>      if (ret < 0) {
> -        /*
> -         * On failure reset back to the
> -         * old uid/gid
> -         */
> -        ret = -errno;
> -        goto err_out;
> +        goto unmarshal_err_out;
>      }
>      ret = open(path.data, flags, mode);
>      if (ret < 0) {
>          ret = -errno;
>      }
>  
> -err_out:
> -    setfsugid(cur_uid, cur_gid);
> +    resetugid(cur_uid, cur_gid);
>  unmarshal_err_out:
>      v9fs_string_free(&path);
>      return ret;

  reply	other threads:[~2012-12-10 16:59 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05 16:37 [Qemu-devel] [PULL] VirtFS update Aneesh Kumar K.V
2012-12-10 16:58 ` Anthony Liguori [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-16 15:29 Aneesh Kumar K.V
2015-06-17 11:26 ` Peter Maydell
2015-03-16 10:09 Aneesh Kumar K.V
2015-03-16 13:55 ` Peter Maydell
2014-09-04 16:01 Aneesh Kumar K.V
2014-09-04 18:21 ` Peter Maydell
2014-03-07 15:16 Aneesh Kumar K.V
2014-03-08 12:52 ` Peter Maydell
2014-02-05  7:14 Aneesh Kumar K.V
2014-02-05  7:58 ` Aneesh Kumar K.V
2014-02-10 18:48 ` Peter Maydell
2014-02-10 19:21 ` Andreas Färber
2014-02-10 19:43   ` Peter Maydell
2014-02-10 19:48     ` Andreas Färber
2014-02-10 19:51       ` Peter Maydell
2013-05-29 11:33 Aneesh Kumar K.V
2013-05-31 18:48 ` Anthony Liguori
2012-07-31 17:27 Aneesh Kumar K.V
2012-08-03 20:45 ` Anthony Liguori
2012-02-26 17:44 Aneesh Kumar K.V
2012-02-28 15:33 ` Anthony Liguori
2012-01-30 16:14 Aneesh Kumar K.V
2012-02-07 12:36 ` Aneesh Kumar K.V
2012-01-23 13:02 Aneesh Kumar K.V
2012-01-23 17:05 ` Anthony Liguori
2012-01-23 18:25   ` Aneesh Kumar K.V
2011-12-21  7:57 Aneesh Kumar K.V
2011-12-27 16:36 ` Anthony Liguori
2011-12-17 13:31 Aneesh Kumar K.V
2011-12-05  9:04 Aneesh Kumar K.V
2011-11-02 10:22 [Qemu-devel] [PULL] Virtfs update Aneesh Kumar K.V
2011-11-02 12:42 ` Anthony Liguori
2011-11-02 14:09   ` Aneesh Kumar K.V
2011-11-03 13:09     ` Anthony Liguori
2011-11-02 15:55   ` Markus Armbruster
2011-09-27  9:11 [Qemu-devel] [PULL] VirtFS update Aneesh Kumar K.V
2011-09-29 20:05 ` Anthony Liguori
2011-09-13 13:27 Aneesh Kumar K.V
2011-09-15 19:10 ` Anthony Liguori

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=87ip89269e.fsf@codemonkey.ws \
    --to=aliguori@us.ibm.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.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).