mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serge@hallyn.com>
To: "Eric W. Beiderman" <ebiederm@xmission.com>
Cc: linux-kernel@vger.kernel.org,
	Linux Containers <containers@lists.linux-foundation.org>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	linux-security-module@vger.kernel.org,
	Al Viro <viro@ZenIV.linux.org.uk>,
	linux-fsdevel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 25/43] userns: Store uid and gid types in vfs structures with kuid_t and kgid_t types
Date: Wed, 18 Apr 2012 18:57:17 +0000	[thread overview]
Message-ID: <20120418185717.GB5186@mail.hallyn.com> (raw)
In-Reply-To: <1333862139-31737-25-git-send-email-ebiederm@xmission.com>

Quoting Eric W. Beiderman (ebiederm@xmission.com):
> From: Eric W. Biederman <ebiederm@xmission.com>
> 
> The conversion of all of the users is not done yet there are too many to change
> in one go and leave the code reviewable. For now I change just the header and
> a few trivial users and rely on CONFIG_UIDGID_STRICT_TYPE_CHECKS not being set
> to ensure that the code will still compile during the transition.
> 
> Helper functions i_uid_read, i_uid_write, i_gid_read, i_gid_write are added
> so that in most cases filesystems can avoid the complexities of multiple user
> namespaces and can concentrate on moving their raw numeric values into and
> out of the vfs data structures.
> 
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>

Acked-by: Serge Hallyn <serge.hallyn@canonical.com>

> ---
>  fs/inode.c         |    6 +++---
>  include/linux/fs.h |   36 +++++++++++++++++++++++++++++++-----
>  2 files changed, 34 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index f0c4ace..deb72f6 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -135,8 +135,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
>  	inode->i_fop = &empty_fops;
>  	inode->__i_nlink = 1;
>  	inode->i_opflags = 0;
> -	inode->i_uid = 0;
> -	inode->i_gid = 0;
> +	i_uid_write(inode, 0);
> +	i_gid_write(inode, 0);
>  	atomic_set(&inode->i_writecount, 0);
>  	inode->i_size = 0;
>  	inode->i_blocks = 0;
> @@ -1732,7 +1732,7 @@ EXPORT_SYMBOL(inode_init_owner);
>   */
>  bool inode_owner_or_capable(const struct inode *inode)
>  {
> -	if (current_fsuid() == inode->i_uid)
> +	if (uid_eq(current_fsuid(), inode->i_uid))
>  		return true;
>  	if (inode_capable(inode, CAP_FOWNER))
>  		return true;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index a6c5efb..797eb26 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -402,6 +402,7 @@ struct inodes_stat_t {
>  #include <linux/atomic.h>
>  #include <linux/shrinker.h>
>  #include <linux/migrate_mode.h>
> +#include <linux/uidgid.h>
>  
>  #include <asm/byteorder.h>
>  
> @@ -469,8 +470,8 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
>  struct iattr {
>  	unsigned int	ia_valid;
>  	umode_t		ia_mode;
> -	uid_t		ia_uid;
> -	gid_t		ia_gid;
> +	kuid_t		ia_uid;
> +	kgid_t		ia_gid;
>  	loff_t		ia_size;
>  	struct timespec	ia_atime;
>  	struct timespec	ia_mtime;
> @@ -761,8 +762,8 @@ struct posix_acl;
>  struct inode {
>  	umode_t			i_mode;
>  	unsigned short		i_opflags;
> -	uid_t			i_uid;
> -	gid_t			i_gid;
> +	kuid_t			i_uid;
> +	kgid_t			i_gid;
>  	unsigned int		i_flags;
>  
>  #ifdef CONFIG_FS_POSIX_ACL
> @@ -927,6 +928,31 @@ static inline void i_size_write(struct inode *inode, loff_t i_size)
>  #endif
>  }
>  
> +/* Helper functions so that in most cases filesystems will
> + * not need to deal directly with kuid_t and kgid_t and can
> + * instead deal with the raw numeric values that are stored
> + * in the filesystem.
> + */
> +static inline uid_t i_uid_read(const struct inode *inode)
> +{
> +	return from_kuid(&init_user_ns, inode->i_uid);
> +}
> +
> +static inline gid_t i_gid_read(const struct inode *inode)
> +{
> +	return from_kgid(&init_user_ns, inode->i_gid);
> +}
> +
> +static inline void i_uid_write(struct inode *inode, uid_t uid)
> +{
> +	inode->i_uid = make_kuid(&init_user_ns, uid);
> +}
> +
> +static inline void i_gid_write(struct inode *inode, gid_t gid)
> +{
> +	inode->i_gid = make_kgid(&init_user_ns, gid);
> +}
> +
>  static inline unsigned iminor(const struct inode *inode)
>  {
>  	return MINOR(inode->i_rdev);
> @@ -943,7 +969,7 @@ struct fown_struct {
>  	rwlock_t lock;          /* protects pid, uid, euid fields */
>  	struct pid *pid;	/* pid or -pgrp where SIGIO should be sent */
>  	enum pid_type pid_type;	/* Kind of process group SIGIO should be sent to */
> -	uid_t uid, euid;	/* uid/euid of process setting the owner */
> +	kuid_t uid, euid;	/* uid/euid of process setting the owner */
>  	int signum;		/* posix.1b rt signal to be delivered on IO */
>  };
>  
> -- 
> 1.7.2.5
> 
> _______________________________________________
> Containers mailing list
> Containers@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers

  reply	other threads:[~2012-04-18 18:56 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-08  5:10 [REVIEW][PATCH 0/43] Completing the user namespace Eric W. Biederman
2012-04-08  5:14 ` [PATCH 01/43] vfs: Don't allow a user namespace root to make device nodes "Eric W. Beiderman
2012-04-08  5:14 ` [PATCH 02/43] userns: Kill bogus declaration of function release_uids "Eric W. Beiderman
2012-04-08  5:14 ` [PATCH 03/43] userns: Replace netlink uses of cap_raised with capable "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 04/43] userns: Remove unnecessary cast to struct user_struct when copying cred->user "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 05/43] cred: Add forward declaration of init_user_ns in all cases "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 06/43] userns: Use cred->user_ns instead of cred->user->user_ns "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 07/43] cred: Refcount the user_ns pointed to by the cred "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 08/43] userns: Add an explicit reference to the parent user namespace "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 09/43] mqueue: Explicitly capture the user namespace to send the notification to "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 10/43] userns: Deprecate and rename the user_namespace reference in the user_struct "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 11/43] userns: Start out with a full set of capabilities "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 12/43] userns: Replace the hard to write inode_userns with inode_capable "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 13/43] userns: Add kuid_t and kgid_t and associated infrastructure in uidgid.h "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 14/43] userns: Add a Kconfig option to enforce strict kuid and kgid type checks "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 15/43] userns: Disassociate user_struct from the user_namespace "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 16/43] userns: Simplify the user_namespace by making userns->creator a kuid "Eric W. Beiderman
2012-04-18 18:48   ` Serge E. Hallyn
2012-04-20 22:58     ` Eric W. Biederman
2012-04-24 17:33       ` Serge E. Hallyn
2012-04-24 19:41         ` Eric W. Biederman
2012-04-24 20:23           ` Serge E. Hallyn
2012-04-26  9:09             ` Eric W. Biederman
2012-04-26 16:21               ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 18/43] userns: Convert group_info values from gid_t to kgid_t "Eric W. Beiderman
2012-04-18 18:49   ` Serge E. Hallyn
2012-04-20 23:05     ` Eric W. Biederman
2012-04-08  5:15 ` [PATCH 19/43] userns: Store uid and gid values in struct cred with kuid_t and kgid_t types "Eric W. Beiderman
2012-04-18 18:49   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 20/43] userns: Replace user_ns_map_uid and user_ns_map_gid with from_kuid and from_kgid "Eric W. Beiderman
2012-04-18 18:49   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 21/43] userns: Convert sched_set_affinity and sched_set_scheduler's permission checks "Eric W. Beiderman
2012-04-18 18:50   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 22/43] userns: Convert capabilities related permsion checks "Eric W. Beiderman
2012-04-18 18:51   ` Serge E. Hallyn
2012-04-20 23:18     ` Eric W. Biederman
2012-04-08  5:15 ` [PATCH 23/43] userns: Convert setting and getting uid and gid system calls to use kuid and kgid "Eric W. Beiderman
2012-04-26 16:20   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 24/43] userns: Convert ptrace, kill, set_priority permission checks to work with kuids and kgids "Eric W. Beiderman
2012-04-18 18:56   ` Serge E. Hallyn
2012-04-20 23:51     ` Eric W. Biederman
2012-04-08  5:15 ` [PATCH 25/43] userns: Store uid and gid types in vfs structures with kuid_t and kgid_t types "Eric W. Beiderman
2012-04-18 18:57   ` Serge E. Hallyn [this message]
2012-04-08  5:15 ` [PATCH 26/43] userns: Convert in_group_p and in_egroup_p to use kgid_t "Eric W. Beiderman
2012-04-18 18:58   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 27/43] userns: Use uid_eq gid_eq helpers when comparing kuids and kgids in the vfs "Eric W. Beiderman
2012-04-18 19:02   ` Serge E. Hallyn
2012-04-21  0:05     ` Eric W. Biederman
2012-04-18 19:03   ` Serge E. Hallyn
2012-04-21  0:58     ` Eric W. Biederman
2012-04-24 17:41       ` Serge E. Hallyn
2012-04-26  0:11       ` Serge E. Hallyn
2012-04-26  5:33         ` Eric W. Biederman
2012-04-08  5:15 ` [PATCH 28/43] userns: Convert user specfied uids and gids in chown into kuids and kgid "Eric W. Beiderman
2012-04-18 19:03   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 29/43] userns: Convert stat to return values mapped from kuids and kgids "Eric W. Beiderman
2012-04-18 19:03   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 30/43] userns: Fail exec for suid and sgid binaries with ids outside our user namespace "Eric W. Beiderman
2012-04-18 19:05   ` Serge E. Hallyn
2012-04-18 19:09   ` Serge E. Hallyn
2012-04-24  2:28     ` Eric W. Biederman
2012-04-24 15:10       ` Serge Hallyn
2012-04-08  5:15 ` [PATCH 31/43] userns: Teach inode_capable to understand inodes whose uids map to other namespaces "Eric W. Beiderman
2012-04-18 19:06   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 32/43] userns: signal remove unnecessary map_cred_ns "Eric W. Beiderman
2012-04-18 19:07   ` Serge E. Hallyn
2012-04-08  5:15 ` [PATCH 33/43] userns: Convert binary formats to use kuid/kgid where appropriate "Eric W. Beiderman
2012-04-18 19:10   ` Serge E. Hallyn
2012-04-24  2:44     ` Eric W. Biederman
2012-04-08  5:15 ` [PATCH 34/43] userns: Convert devpts " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 35/43] userns: Convert ext2 " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 36/43] userns: Convert ext3 " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 37/43] userns: Convert ext4 to user " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 38/43] userns: Convert proc to use " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 39/43] userns: Convert sysctl permission checks to use kuid and kgids "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 40/43] userns: Convert sysfs to use kgid/kuid where appropriate "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 41/43] userns: Convert tmpfs to use kuid and kgid " "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 42/43] userns: Convert cgroup permission checks to use uid_eq "Eric W. Beiderman
2012-04-08  5:15 ` [PATCH 43/43] userns: Convert the move_pages, and migrate_pages " "Eric W. Beiderman
2012-04-08 14:54 ` [REVIEW][PATCH 0/43] Completing the user namespace Serge Hallyn
2012-04-08 17:40 ` richard -rw- weinberger
2012-04-08 21:30   ` Eric W. Biederman
2012-04-08 22:04     ` richard -rw- weinberger
2012-04-08 22:52       ` Eric W. Biederman
     [not found] ` <1333862139-31737-17-git-send-email-ebiederm@xmission.com>
2012-04-18 18:49   ` [PATCH 17/43] userns: Rework the user_namespace adding uid/gid mapping support Serge E. Hallyn
2012-05-11 23:20 ` Please include user-namespace.git in linux-next Eric W. Biederman
2012-05-13 23:35   ` Stephen Rothwell
2012-05-21  2:25   ` Tetsuo Handa
2012-05-22 17:26     ` Eric W. Biederman

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=20120418185717.GB5186@mail.hallyn.com \
    --to=serge@hallyn.com \
    --cc=akpm@linux-foundation.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gorcunov@openvz.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@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

all inboxes | Powered by JetHome®