Skip to content

Commit 3496f92

Browse files
committed
Merge branch 'serge-next' into next
2 parents 200036c + 6ded6ab commit 3496f92

13 files changed

Lines changed: 96 additions & 129 deletions

File tree

‎fs/ecryptfs/messaging.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
360360
struct ecryptfs_msg_ctx *msg_ctx;
361361
size_t msg_size;
362362
struct nsproxy *nsproxy;
363-
struct user_namespace *current_user_ns;
363+
struct user_namespace *tsk_user_ns;
364364
uid_t ctx_euid;
365365
int rc;
366366

@@ -385,9 +385,9 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
385385
mutex_unlock(&ecryptfs_daemon_hash_mux);
386386
goto wake_up;
387387
}
388-
current_user_ns = nsproxy->user_ns;
388+
tsk_user_ns = __task_cred(msg_ctx->task)->user->user_ns;
389389
ctx_euid = task_euid(msg_ctx->task);
390-
rc = ecryptfs_find_daemon_by_euid(&daemon, ctx_euid, current_user_ns);
390+
rc = ecryptfs_find_daemon_by_euid(&daemon, ctx_euid, tsk_user_ns);
391391
rcu_read_unlock();
392392
mutex_unlock(&ecryptfs_daemon_hash_mux);
393393
if (rc) {
@@ -405,11 +405,11 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
405405
euid, ctx_euid);
406406
goto unlock;
407407
}
408-
if (current_user_ns != user_ns) {
408+
if (tsk_user_ns != user_ns) {
409409
rc = -EBADMSG;
410410
printk(KERN_WARNING "%s: Received message from user_ns "
411411
"[0x%p]; expected message from user_ns [0x%p]\n",
412-
__func__, user_ns, nsproxy->user_ns);
412+
__func__, user_ns, tsk_user_ns);
413413
goto unlock;
414414
}
415415
if (daemon->pid != pid) {
@@ -468,8 +468,7 @@ ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type,
468468
uid_t euid = current_euid();
469469
int rc;
470470

471-
rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
472-
current->nsproxy->user_ns);
471+
rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
473472
if (rc || !daemon) {
474473
rc = -ENOTCONN;
475474
printk(KERN_ERR "%s: User [%d] does not have a daemon "

‎fs/ecryptfs/miscdev.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ ecryptfs_miscdev_poll(struct file *file, poll_table *pt)
4747

4848
mutex_lock(&ecryptfs_daemon_hash_mux);
4949
/* TODO: Just use file->private_data? */
50-
rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
51-
current->nsproxy->user_ns);
50+
rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
5251
BUG_ON(rc || !daemon);
5352
mutex_lock(&daemon->mux);
5453
mutex_unlock(&ecryptfs_daemon_hash_mux);
@@ -95,11 +94,9 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
9594
"count; rc = [%d]\n", __func__, rc);
9695
goto out_unlock_daemon_list;
9796
}
98-
rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
99-
current->nsproxy->user_ns);
97+
rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
10098
if (rc || !daemon) {
101-
rc = ecryptfs_spawn_daemon(&daemon, euid,
102-
current->nsproxy->user_ns,
99+
rc = ecryptfs_spawn_daemon(&daemon, euid, current_user_ns(),
103100
task_pid(current));
104101
if (rc) {
105102
printk(KERN_ERR "%s: Error attempting to spawn daemon; "
@@ -153,8 +150,7 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
153150
int rc;
154151

155152
mutex_lock(&ecryptfs_daemon_hash_mux);
156-
rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
157-
current->nsproxy->user_ns);
153+
rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
158154
BUG_ON(rc || !daemon);
159155
mutex_lock(&daemon->mux);
160156
BUG_ON(daemon->pid != task_pid(current));
@@ -254,8 +250,7 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
254250

255251
mutex_lock(&ecryptfs_daemon_hash_mux);
256252
/* TODO: Just use file->private_data? */
257-
rc = ecryptfs_find_daemon_by_euid(&daemon, euid,
258-
current->nsproxy->user_ns);
253+
rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
259254
BUG_ON(rc || !daemon);
260255
mutex_lock(&daemon->mux);
261256
if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) {
@@ -295,7 +290,7 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
295290
goto check_list;
296291
}
297292
BUG_ON(euid != daemon->euid);
298-
BUG_ON(current->nsproxy->user_ns != daemon->user_ns);
293+
BUG_ON(current_user_ns() != daemon->user_ns);
299294
BUG_ON(task_pid(current) != daemon->pid);
300295
msg_ctx = list_first_entry(&daemon->msg_ctx_out_queue,
301296
struct ecryptfs_msg_ctx, daemon_out_list);
@@ -468,7 +463,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
468463
goto out_free;
469464
}
470465
rc = ecryptfs_miscdev_response(&data[i], packet_size,
471-
euid, current->nsproxy->user_ns,
466+
euid, current_user_ns(),
472467
task_pid(current), seq);
473468
if (rc)
474469
printk(KERN_WARNING "%s: Failed to deliver miscdev "

‎include/linux/cred.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ do { \
6060
} while (0)
6161

6262
extern struct group_info *groups_alloc(int);
63+
extern struct group_info init_groups;
6364
extern void groups_free(struct group_info *);
6465
extern int set_current_groups(struct group_info *);
6566
extern int set_groups(struct cred *, struct group_info *);
@@ -315,6 +316,7 @@ static inline void put_cred(const struct cred *_cred)
315316
#define current_fsgid() (current_cred_xxx(fsgid))
316317
#define current_cap() (current_cred_xxx(cap_effective))
317318
#define current_user() (current_cred_xxx(user))
319+
#define current_user_ns() (current_cred_xxx(user)->user_ns)
318320
#define current_security() (current_cred_xxx(security))
319321

320322
#define current_uid_gid(_uid, _gid) \

‎include/linux/init_task.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ extern struct nsproxy init_nsproxy;
5757
.mnt_ns = NULL, \
5858
INIT_NET_NS(net_ns) \
5959
INIT_IPC_NS(ipc_ns) \
60-
.user_ns = &init_user_ns, \
6160
}
6261

6362
#define INIT_SIGHAND(sighand) { \

‎include/linux/nsproxy.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct nsproxy {
2727
struct ipc_namespace *ipc_ns;
2828
struct mnt_namespace *mnt_ns;
2929
struct pid_namespace *pid_ns;
30-
struct user_namespace *user_ns;
3130
struct net *net_ns;
3231
};
3332
extern struct nsproxy init_nsproxy;

‎include/linux/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ struct user_struct {
638638
/* Hash table maintenance information */
639639
struct hlist_node uidhash_node;
640640
uid_t uid;
641+
struct user_namespace *user_ns;
641642

642643
#ifdef CONFIG_USER_SCHED
643644
struct task_group *tg;

‎include/linux/user_namespace.h‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
struct user_namespace {
1313
struct kref kref;
1414
struct hlist_head uidhash_table[UIDHASH_SZ];
15-
struct user_struct *root_user;
15+
struct user_struct *creator;
1616
};
1717

1818
extern struct user_namespace init_user_ns;
@@ -26,8 +26,7 @@ static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
2626
return ns;
2727
}
2828

29-
extern struct user_namespace *copy_user_ns(int flags,
30-
struct user_namespace *old_ns);
29+
extern int create_user_ns(struct cred *new);
3130
extern void free_user_ns(struct kref *kref);
3231

3332
static inline void put_user_ns(struct user_namespace *ns)
@@ -43,13 +42,9 @@ static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
4342
return &init_user_ns;
4443
}
4544

46-
static inline struct user_namespace *copy_user_ns(int flags,
47-
struct user_namespace *old_ns)
45+
static inline int create_user_ns(struct cred *new)
4846
{
49-
if (flags & CLONE_NEWUSER)
50-
return ERR_PTR(-EINVAL);
51-
52-
return old_ns;
47+
return -EINVAL;
5348
}
5449

5550
static inline void put_user_ns(struct user_namespace *ns)

‎kernel/cred.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
274274
struct thread_group_cred *tgcred;
275275
#endif
276276
struct cred *new;
277+
int ret;
277278

278279
mutex_init(&p->cred_exec_mutex);
279280

@@ -293,6 +294,12 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
293294
if (!new)
294295
return -ENOMEM;
295296

297+
if (clone_flags & CLONE_NEWUSER) {
298+
ret = create_user_ns(new);
299+
if (ret < 0)
300+
goto error_put;
301+
}
302+
296303
#ifdef CONFIG_KEYS
297304
/* new threads get their own thread keyrings if their parent already
298305
* had one */
@@ -309,8 +316,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
309316
if (!(clone_flags & CLONE_THREAD)) {
310317
tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
311318
if (!tgcred) {
312-
put_cred(new);
313-
return -ENOMEM;
319+
ret = -ENOMEM;
320+
goto error_put;
314321
}
315322
atomic_set(&tgcred->usage, 1);
316323
spin_lock_init(&tgcred->lock);
@@ -325,6 +332,10 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
325332
atomic_inc(&new->user->processes);
326333
p->cred = p->real_cred = get_cred(new);
327334
return 0;
335+
336+
error_put:
337+
put_cred(new);
338+
return ret;
328339
}
329340

330341
/**

‎kernel/fork.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
976976
if (atomic_read(&p->real_cred->user->processes) >=
977977
p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
978978
if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
979-
p->real_cred->user != current->nsproxy->user_ns->root_user)
979+
p->real_cred->user != INIT_USER)
980980
goto bad_fork_free;
981981
}
982982

@@ -1334,6 +1334,20 @@ long do_fork(unsigned long clone_flags,
13341334
int trace = 0;
13351335
long nr;
13361336

1337+
/*
1338+
* Do some preliminary argument and permissions checking before we
1339+
* actually start allocating stuff
1340+
*/
1341+
if (clone_flags & CLONE_NEWUSER) {
1342+
if (clone_flags & CLONE_THREAD)
1343+
return -EINVAL;
1344+
/* hopefully this check will go away when userns support is
1345+
* complete
1346+
*/
1347+
if (!capable(CAP_SYS_ADMIN))
1348+
return -EPERM;
1349+
}
1350+
13371351
/*
13381352
* We hope to recycle these flags after 2.6.26
13391353
*/
@@ -1581,8 +1595,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
15811595
err = -EINVAL;
15821596
if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND|
15831597
CLONE_VM|CLONE_FILES|CLONE_SYSVSEM|
1584-
CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWUSER|
1585-
CLONE_NEWNET))
1598+
CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET))
15861599
goto bad_unshare_out;
15871600

15881601
/*

‎kernel/nsproxy.c‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
8080
goto out_pid;
8181
}
8282

83-
new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
84-
if (IS_ERR(new_nsp->user_ns)) {
85-
err = PTR_ERR(new_nsp->user_ns);
86-
goto out_user;
87-
}
88-
8983
new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
9084
if (IS_ERR(new_nsp->net_ns)) {
9185
err = PTR_ERR(new_nsp->net_ns);
@@ -95,9 +89,6 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
9589
return new_nsp;
9690

9791
out_net:
98-
if (new_nsp->user_ns)
99-
put_user_ns(new_nsp->user_ns);
100-
out_user:
10192
if (new_nsp->pid_ns)
10293
put_pid_ns(new_nsp->pid_ns);
10394
out_pid:
@@ -130,7 +121,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
130121
get_nsproxy(old_ns);
131122

132123
if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
133-
CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNET)))
124+
CLONE_NEWPID | CLONE_NEWNET)))
134125
return 0;
135126

136127
if (!capable(CAP_SYS_ADMIN)) {
@@ -173,8 +164,6 @@ void free_nsproxy(struct nsproxy *ns)
173164
put_ipc_ns(ns->ipc_ns);
174165
if (ns->pid_ns)
175166
put_pid_ns(ns->pid_ns);
176-
if (ns->user_ns)
177-
put_user_ns(ns->user_ns);
178167
put_net(ns->net_ns);
179168
kmem_cache_free(nsproxy_cachep, ns);
180169
}
@@ -189,7 +178,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
189178
int err = 0;
190179

191180
if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
192-
CLONE_NEWUSER | CLONE_NEWNET)))
181+
CLONE_NEWNET)))
193182
return 0;
194183

195184
if (!capable(CAP_SYS_ADMIN))

0 commit comments

Comments
 (0)