linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Seth Forshee <sforshee@digitalocean.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>,
	linux-fsdevel@vger.kernel.org, Aleksa Sarai <cyphar@cyphar.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH v2 8/8] attr: port attribute changes to new types
Date: Thu, 23 Jun 2022 15:48:38 -0500	[thread overview]
Message-ID: <YrTRpsZuOnjFUObl@do-x1extreme> (raw)
In-Reply-To: <20220621141454.2914719-9-brauner@kernel.org>

On Tue, Jun 21, 2022 at 04:14:54PM +0200, Christian Brauner wrote:
> diff --git a/fs/attr.c b/fs/attr.c
> index 88e2ca30d42e..22e310dd483f 100644
> --- a/fs/attr.c
> +++ b/fs/attr.c
> @@ -31,15 +31,15 @@
>   * performed on the raw inode simply passs init_user_ns.
>   */
>  static bool chown_ok(struct user_namespace *mnt_userns,
> -		     const struct inode *inode,
> -		     kuid_t uid)
> +		     const struct inode *inode, vfsuid_t ia_vfsuid)
>  {
> -	kuid_t kuid = i_uid_into_mnt(mnt_userns, inode);
> -	if (uid_eq(current_fsuid(), kuid) && uid_eq(uid, inode->i_uid))
> +	vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
> +	if (kuid_eq_vfsuid(current_fsuid(), vfsuid) &&
> +	    vfsuid_eq(ia_vfsuid, vfsuid))
>  		return true;
>  	if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_CHOWN))
>  		return true;
> -	if (uid_eq(kuid, INVALID_UID) &&
> +	if (vfsuid_eq(vfsuid, INVALID_VFSUID) &&

If you use my suggestion that comparison to invalid ids should always be
false, this check will need to change to !vfsuid_valid(vfsuid). I'd
argue that this makes the code clearer regardless.

>  	    ns_capable(inode->i_sb->s_user_ns, CAP_CHOWN))
>  		return true;
>  	return false;
> @@ -58,21 +58,19 @@ static bool chown_ok(struct user_namespace *mnt_userns,
>   * performed on the raw inode simply passs init_user_ns.
>   */
>  static bool chgrp_ok(struct user_namespace *mnt_userns,
> -		     const struct inode *inode, kgid_t gid)
> +		     const struct inode *inode, vfsgid_t ia_vfsgid)
>  {
> -	kgid_t kgid = i_gid_into_mnt(mnt_userns, inode);
> -	if (uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode))) {
> -		kgid_t mapped_gid;
> -
> -		if (gid_eq(gid, inode->i_gid))
> +	vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
> +	vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
> +	if (kuid_eq_vfsuid(current_fsuid(), vfsuid)) {
> +		if (vfsgid_eq(ia_vfsgid, vfsgid))
>  			return true;
> -		mapped_gid = mapped_kgid_fs(mnt_userns, i_user_ns(inode), gid);
> -		if (in_group_p(mapped_gid))
> +		if (vfsgid_in_group_p(ia_vfsgid))
>  			return true;
>  	}
>  	if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_CHOWN))
>  		return true;
> -	if (gid_eq(kgid, INVALID_GID) &&
> +	if (vfsgid_eq(ia_vfsgid, INVALID_VFSGID) &&

Likewise here.

  parent reply	other threads:[~2022-06-23 20:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 14:14 [PATCH v2 0/8] introduce dedicated type for idmapped mounts Christian Brauner
2022-06-21 14:14 ` [PATCH v2 1/8] mnt_idmapping: add vfs{g,u}id_t Christian Brauner
2022-06-21 18:22   ` Seth Forshee
2022-06-22  4:10     ` Christian Brauner
2022-06-21 14:14 ` [PATCH v2 2/8] fs: add two type safe mapping helpers Christian Brauner
2022-06-21 14:14 ` [PATCH v2 3/8] fs: use mount types in iattr Christian Brauner
2022-06-21 14:14 ` [PATCH v2 4/8] fs: introduce tiny iattr ownership update helpers Christian Brauner
2022-06-21 14:14 ` [PATCH v2 5/8] fs: port to " Christian Brauner
2022-06-21 14:14 ` [PATCH v2 6/8] quota: port quota helpers mount ids Christian Brauner
2022-06-21 14:14 ` [PATCH v2 7/8] security: pass down mount idmapping to setattr hook Christian Brauner
2022-06-21 14:14 ` [PATCH v2 8/8] attr: port attribute changes to new types Christian Brauner
2022-06-21 17:33   ` Linus Torvalds
2022-06-22  4:06     ` Christian Brauner
2022-06-23 20:48   ` Seth Forshee [this message]
2022-06-23 21:03     ` Christian Brauner
2022-06-23 21:01 ` [PATCH v2 0/8] introduce dedicated type for idmapped mounts Seth Forshee

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=YrTRpsZuOnjFUObl@do-x1extreme \
    --to=sforshee@digitalocean.com \
    --cc=brauner@kernel.org \
    --cc=cyphar@cyphar.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).