Commit 45634cd8 authored by Eric W. Biederman's avatar Eric W. Biederman

userns: Support autofs4 interacing with multiple user namespaces

Use kuid_t and kgid_t in struct autofs_info and struct autofs_wait_queue.

When creating directories and symlinks default the uid and gid of
the mount requester to the global root uid and gid.  autofs4_wait
will update these fields when a mount is requested.

When generating autofsv5 packets report the uid and gid of the mount
requestor in user namespace of the process that opened the pipe,
reporting unmapped uids and gids as overflowuid and overflowgid.

In autofs_dev_ioctl_requester return the uid and gid of the last mount
requester converted into the calling processes user namespace.  When the
uid or gid don't map return overflowuid and overflowgid as appropriate,
allowing failure to find a mount requester to be distinguished from
failure to map a mount requester.

The uid and gid mount options specifying the user and group of the
root autofs inode are converted into kuid and kgid as they are parsed
defaulting to the current uid and current gid of the process that
mounts autofs.

Mounting of autofs for the present remains confined to processes in
the initial user namespace.

Cc: Ian Kent <raven@themaw.net>
Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent 8f0d8163
...@@ -74,8 +74,8 @@ struct autofs_info { ...@@ -74,8 +74,8 @@ struct autofs_info {
unsigned long last_used; unsigned long last_used;
atomic_t count; atomic_t count;
uid_t uid; kuid_t uid;
gid_t gid; kgid_t gid;
}; };
#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */ #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
...@@ -89,8 +89,8 @@ struct autofs_wait_queue { ...@@ -89,8 +89,8 @@ struct autofs_wait_queue {
struct qstr name; struct qstr name;
u32 dev; u32 dev;
u64 ino; u64 ino;
uid_t uid; kuid_t uid;
gid_t gid; kgid_t gid;
pid_t pid; pid_t pid;
pid_t tgid; pid_t tgid;
/* This is for status reporting upon return */ /* This is for status reporting upon return */
......
...@@ -437,8 +437,8 @@ static int autofs_dev_ioctl_requester(struct file *fp, ...@@ -437,8 +437,8 @@ static int autofs_dev_ioctl_requester(struct file *fp,
err = 0; err = 0;
autofs4_expire_wait(path.dentry); autofs4_expire_wait(path.dentry);
spin_lock(&sbi->fs_lock); spin_lock(&sbi->fs_lock);
param->requester.uid = ino->uid; param->requester.uid = from_kuid_munged(current_user_ns(), ino->uid);
param->requester.gid = ino->gid; param->requester.gid = from_kgid_munged(current_user_ns(), ino->gid);
spin_unlock(&sbi->fs_lock); spin_unlock(&sbi->fs_lock);
} }
path_put(&path); path_put(&path);
......
...@@ -36,8 +36,8 @@ struct autofs_info *autofs4_new_ino(struct autofs_sb_info *sbi) ...@@ -36,8 +36,8 @@ struct autofs_info *autofs4_new_ino(struct autofs_sb_info *sbi)
void autofs4_clean_ino(struct autofs_info *ino) void autofs4_clean_ino(struct autofs_info *ino)
{ {
ino->uid = 0; ino->uid = GLOBAL_ROOT_UID;
ino->gid = 0; ino->gid = GLOBAL_ROOT_GID;
ino->last_used = jiffies; ino->last_used = jiffies;
} }
...@@ -79,10 +79,12 @@ static int autofs4_show_options(struct seq_file *m, struct dentry *root) ...@@ -79,10 +79,12 @@ static int autofs4_show_options(struct seq_file *m, struct dentry *root)
return 0; return 0;
seq_printf(m, ",fd=%d", sbi->pipefd); seq_printf(m, ",fd=%d", sbi->pipefd);
if (root_inode->i_uid != 0) if (!uid_eq(root_inode->i_uid, GLOBAL_ROOT_UID))
seq_printf(m, ",uid=%u", root_inode->i_uid); seq_printf(m, ",uid=%u",
if (root_inode->i_gid != 0) from_kuid_munged(&init_user_ns, root_inode->i_uid));
seq_printf(m, ",gid=%u", root_inode->i_gid); if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, root_inode->i_gid));
seq_printf(m, ",pgrp=%d", sbi->oz_pgrp); seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ); seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
seq_printf(m, ",minproto=%d", sbi->min_proto); seq_printf(m, ",minproto=%d", sbi->min_proto);
...@@ -126,7 +128,7 @@ static const match_table_t tokens = { ...@@ -126,7 +128,7 @@ static const match_table_t tokens = {
{Opt_err, NULL} {Opt_err, NULL}
}; };
static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,
pid_t *pgrp, unsigned int *type, int *minproto, int *maxproto) pid_t *pgrp, unsigned int *type, int *minproto, int *maxproto)
{ {
char *p; char *p;
...@@ -159,12 +161,16 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, ...@@ -159,12 +161,16 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
case Opt_uid: case Opt_uid:
if (match_int(args, &option)) if (match_int(args, &option))
return 1; return 1;
*uid = option; *uid = make_kuid(current_user_ns(), option);
if (!uid_valid(*uid))
return 1;
break; break;
case Opt_gid: case Opt_gid:
if (match_int(args, &option)) if (match_int(args, &option))
return 1; return 1;
*gid = option; *gid = make_kgid(current_user_ns(), option);
if (!gid_valid(*gid))
return 1;
break; break;
case Opt_pgrp: case Opt_pgrp:
if (match_int(args, &option)) if (match_int(args, &option))
......
...@@ -154,6 +154,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, ...@@ -154,6 +154,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
case autofs_ptype_expire_direct: case autofs_ptype_expire_direct:
{ {
struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet; struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
pktsz = sizeof(*packet); pktsz = sizeof(*packet);
...@@ -163,8 +164,8 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, ...@@ -163,8 +164,8 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
packet->name[wq->name.len] = '\0'; packet->name[wq->name.len] = '\0';
packet->dev = wq->dev; packet->dev = wq->dev;
packet->ino = wq->ino; packet->ino = wq->ino;
packet->uid = wq->uid; packet->uid = from_kuid_munged(user_ns, wq->uid);
packet->gid = wq->gid; packet->gid = from_kgid_munged(user_ns, wq->gid);
packet->pid = wq->pid; packet->pid = wq->pid;
packet->tgid = wq->tgid; packet->tgid = wq->tgid;
break; break;
......
...@@ -1004,7 +1004,6 @@ config UIDGID_CONVERTED ...@@ -1004,7 +1004,6 @@ config UIDGID_CONVERTED
# Filesystems # Filesystems
depends on 9P_FS = n depends on 9P_FS = n
depends on AFS_FS = n depends on AFS_FS = n
depends on AUTOFS4_FS = n
depends on CEPH_FS = n depends on CEPH_FS = n
depends on CIFS = n depends on CIFS = n
depends on CODA_FS = n depends on CODA_FS = n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment