Skip to content

Commit 437589a

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull user namespace changes from Eric Biederman: "This is a mostly modest set of changes to enable basic user namespace support. This allows the code to code to compile with user namespaces enabled and removes the assumption there is only the initial user namespace. Everything is converted except for the most complex of the filesystems: autofs4, 9p, afs, ceph, cifs, coda, fuse, gfs2, ncpfs, nfs, ocfs2 and xfs as those patches need a bit more review. The strategy is to push kuid_t and kgid_t values are far down into subsystems and filesystems as reasonable. Leaving the make_kuid and from_kuid operations to happen at the edge of userspace, as the values come off the disk, and as the values come in from the network. Letting compile type incompatible compile errors (present when user namespaces are enabled) guide me to find the issues. The most tricky areas have been the places where we had an implicit union of uid and gid values and were storing them in an unsigned int. Those places were converted into explicit unions. I made certain to handle those places with simple trivial patches. Out of that work I discovered we have generic interfaces for storing quota by projid. I had never heard of the project identifiers before. Adding full user namespace support for project identifiers accounts for most of the code size growth in my git tree. Ultimately there will be work to relax privlige checks from "capable(FOO)" to "ns_capable(user_ns, FOO)" where it is safe allowing root in a user names to do those things that today we only forbid to non-root users because it will confuse suid root applications. While I was pushing kuid_t and kgid_t changes deep into the audit code I made a few other cleanups. I capitalized on the fact we process netlink messages in the context of the message sender. I removed usage of NETLINK_CRED, and started directly using current->tty. Some of these patches have also made it into maintainer trees, with no problems from identical code from different trees showing up in linux-next. After reading through all of this code I feel like I might be able to win a game of kernel trivial pursuit." Fix up some fairly trivial conflicts in netfilter uid/git logging code. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (107 commits) userns: Convert the ufs filesystem to use kuid/kgid where appropriate userns: Convert the udf filesystem to use kuid/kgid where appropriate userns: Convert ubifs to use kuid/kgid userns: Convert squashfs to use kuid/kgid where appropriate userns: Convert reiserfs to use kuid and kgid where appropriate userns: Convert jfs to use kuid/kgid where appropriate userns: Convert jffs2 to use kuid and kgid where appropriate userns: Convert hpfs to use kuid and kgid where appropriate userns: Convert btrfs to use kuid/kgid where appropriate userns: Convert bfs to use kuid/kgid where appropriate userns: Convert affs to use kuid/kgid wherwe appropriate userns: On alpha modify linux_to_osf_stat to use convert from kuids and kgids userns: On ia64 deal with current_uid and current_gid being kuid and kgid userns: On ppc convert current_uid from a kuid before printing. userns: Convert s390 getting uid and gid system calls to use kuid and kgid userns: Convert s390 hypfs to use kuid and kgid where appropriate userns: Convert binder ipc to use kuids userns: Teach security_path_chown to take kuids and kgids userns: Add user namespace support to IMA userns: Convert EVM to deal with kuids and kgids in it's hmac computation ...
2 parents 68d47a1 + 7223546 commit 437589a

245 files changed

Lines changed: 2474 additions & 1307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ linux_to_osf_stat(struct kstat *lstat, struct osf_stat __user *osf_stat)
278278
tmp.st_dev = lstat->dev;
279279
tmp.st_mode = lstat->mode;
280280
tmp.st_nlink = lstat->nlink;
281-
tmp.st_uid = lstat->uid;
282-
tmp.st_gid = lstat->gid;
281+
tmp.st_uid = from_kuid_munged(current_user_ns(), lstat->uid);
282+
tmp.st_gid = from_kgid_munged(current_user_ns(), lstat->gid);
283283
tmp.st_rdev = lstat->rdev;
284284
tmp.st_ldev = lstat->rdev;
285285
tmp.st_size = lstat->size;

‎arch/ia64/kernel/mca_drv.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
158158
ia64_mlogbuf_dump();
159159
printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
160160
"iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
161-
raw_smp_processor_id(), current->pid, current_uid(),
161+
raw_smp_processor_id(), current->pid,
162+
from_kuid(&init_user_ns, current_uid()),
162163
iip, ipsr, paddr, current->comm);
163164

164165
spin_lock(&mca_bh_lock);

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,29 +2380,29 @@ static int
23802380
pfm_bad_permissions(struct task_struct *task)
23812381
{
23822382
const struct cred *tcred;
2383-
uid_t uid = current_uid();
2384-
gid_t gid = current_gid();
2383+
kuid_t uid = current_uid();
2384+
kgid_t gid = current_gid();
23852385
int ret;
23862386

23872387
rcu_read_lock();
23882388
tcred = __task_cred(task);
23892389

23902390
/* inspired by ptrace_attach() */
23912391
DPRINT(("cur: uid=%d gid=%d task: euid=%d suid=%d uid=%d egid=%d sgid=%d\n",
2392-
uid,
2393-
gid,
2394-
tcred->euid,
2395-
tcred->suid,
2396-
tcred->uid,
2397-
tcred->egid,
2398-
tcred->sgid));
2399-
2400-
ret = ((uid != tcred->euid)
2401-
|| (uid != tcred->suid)
2402-
|| (uid != tcred->uid)
2403-
|| (gid != tcred->egid)
2404-
|| (gid != tcred->sgid)
2405-
|| (gid != tcred->gid)) && !capable(CAP_SYS_PTRACE);
2392+
from_kuid(&init_user_ns, uid),
2393+
from_kgid(&init_user_ns, gid),
2394+
from_kuid(&init_user_ns, tcred->euid),
2395+
from_kuid(&init_user_ns, tcred->suid),
2396+
from_kuid(&init_user_ns, tcred->uid),
2397+
from_kgid(&init_user_ns, tcred->egid),
2398+
from_kgid(&init_user_ns, tcred->sgid)));
2399+
2400+
ret = ((!uid_eq(uid, tcred->euid))
2401+
|| (!uid_eq(uid, tcred->suid))
2402+
|| (!uid_eq(uid, tcred->uid))
2403+
|| (!gid_eq(gid, tcred->egid))
2404+
|| (!gid_eq(gid, tcred->sgid))
2405+
|| (!gid_eq(gid, tcred->gid))) && !capable(CAP_SYS_PTRACE);
24062406

24072407
rcu_read_unlock();
24082408
return ret;

‎arch/ia64/kernel/signal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ ia64_rt_sigreturn (struct sigscratch *scr)
220220
si.si_errno = 0;
221221
si.si_code = SI_KERNEL;
222222
si.si_pid = task_pid_vnr(current);
223-
si.si_uid = current_uid();
223+
si.si_uid = from_kuid_munged(current_user_ns(), current_uid());
224224
si.si_addr = sc;
225225
force_sig_info(SIGSEGV, &si, current);
226226
return retval;
@@ -317,7 +317,7 @@ force_sigsegv_info (int sig, void __user *addr)
317317
si.si_errno = 0;
318318
si.si_code = SI_KERNEL;
319319
si.si_pid = task_pid_vnr(current);
320-
si.si_uid = current_uid();
320+
si.si_uid = from_kuid_munged(current_user_ns(), current_uid());
321321
si.si_addr = addr;
322322
force_sig_info(SIGSEGV, &si, current);
323323
return 0;

‎arch/powerpc/mm/fault.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
470470
if (is_exec && (error_code & DSISR_PROTFAULT))
471471
printk_ratelimited(KERN_CRIT "kernel tried to execute NX-protected"
472472
" page (%lx) - exploit attempt? (uid: %d)\n",
473-
address, current_uid());
473+
address, from_kuid(&init_user_ns, current_uid()));
474474

475475
return SIGSEGV;
476476

‎arch/s390/hypfs/inode.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static struct dentry *hypfs_create_update_file(struct super_block *sb,
3131
struct dentry *dir);
3232

3333
struct hypfs_sb_info {
34-
uid_t uid; /* uid used for files and dirs */
35-
gid_t gid; /* gid used for files and dirs */
34+
kuid_t uid; /* uid used for files and dirs */
35+
kgid_t gid; /* gid used for files and dirs */
3636
struct dentry *update_file; /* file to trigger update */
3737
time_t last_update; /* last update time in secs since 1970 */
3838
struct mutex lock; /* lock to protect update process */
@@ -229,6 +229,8 @@ static int hypfs_parse_options(char *options, struct super_block *sb)
229229
{
230230
char *str;
231231
substring_t args[MAX_OPT_ARGS];
232+
kuid_t uid;
233+
kgid_t gid;
232234

233235
if (!options)
234236
return 0;
@@ -243,12 +245,18 @@ static int hypfs_parse_options(char *options, struct super_block *sb)
243245
case opt_uid:
244246
if (match_int(&args[0], &option))
245247
return -EINVAL;
246-
hypfs_info->uid = option;
248+
uid = make_kuid(current_user_ns(), option);
249+
if (!uid_valid(uid))
250+
return -EINVAL;
251+
hypfs_info->uid = uid;
247252
break;
248253
case opt_gid:
249254
if (match_int(&args[0], &option))
250255
return -EINVAL;
251-
hypfs_info->gid = option;
256+
gid = make_kgid(current_user_ns(), option);
257+
if (!gid_valid(gid))
258+
return -EINVAL;
259+
hypfs_info->gid = gid;
252260
break;
253261
case opt_err:
254262
default:
@@ -263,8 +271,8 @@ static int hypfs_show_options(struct seq_file *s, struct dentry *root)
263271
{
264272
struct hypfs_sb_info *hypfs_info = root->d_sb->s_fs_info;
265273

266-
seq_printf(s, ",uid=%u", hypfs_info->uid);
267-
seq_printf(s, ",gid=%u", hypfs_info->gid);
274+
seq_printf(s, ",uid=%u", from_kuid_munged(&init_user_ns, hypfs_info->uid));
275+
seq_printf(s, ",gid=%u", from_kgid_munged(&init_user_ns, hypfs_info->gid));
268276
return 0;
269277
}
270278

‎arch/s390/kernel/compat_linux.c‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,19 @@ asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
131131
low2highuid(suid));
132132
}
133133

134-
asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
134+
asmlinkage long sys32_getresuid16(u16 __user *ruidp, u16 __user *euidp, u16 __user *suidp)
135135
{
136+
const struct cred *cred = current_cred();
136137
int retval;
138+
u16 ruid, euid, suid;
137139

138-
if (!(retval = put_user(high2lowuid(current->cred->uid), ruid)) &&
139-
!(retval = put_user(high2lowuid(current->cred->euid), euid)))
140-
retval = put_user(high2lowuid(current->cred->suid), suid);
140+
ruid = high2lowuid(from_kuid_munged(cred->user_ns, cred->uid));
141+
euid = high2lowuid(from_kuid_munged(cred->user_ns, cred->euid));
142+
suid = high2lowuid(from_kuid_munged(cred->user_ns, cred->suid));
143+
144+
if (!(retval = put_user(ruid, ruidp)) &&
145+
!(retval = put_user(euid, euidp)))
146+
retval = put_user(suid, suidp);
141147

142148
return retval;
143149
}
@@ -148,13 +154,19 @@ asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
148154
low2highgid(sgid));
149155
}
150156

151-
asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
157+
asmlinkage long sys32_getresgid16(u16 __user *rgidp, u16 __user *egidp, u16 __user *sgidp)
152158
{
159+
const struct cred *cred = current_cred();
153160
int retval;
161+
u16 rgid, egid, sgid;
162+
163+
rgid = high2lowgid(from_kgid_munged(cred->user_ns, cred->gid));
164+
egid = high2lowgid(from_kgid_munged(cred->user_ns, cred->egid));
165+
sgid = high2lowgid(from_kgid_munged(cred->user_ns, cred->sgid));
154166

155-
if (!(retval = put_user(high2lowgid(current->cred->gid), rgid)) &&
156-
!(retval = put_user(high2lowgid(current->cred->egid), egid)))
157-
retval = put_user(high2lowgid(current->cred->sgid), sgid);
167+
if (!(retval = put_user(rgid, rgidp)) &&
168+
!(retval = put_user(egid, egidp)))
169+
retval = put_user(sgid, sgidp);
158170

159171
return retval;
160172
}
@@ -258,22 +270,22 @@ asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
258270

259271
asmlinkage long sys32_getuid16(void)
260272
{
261-
return high2lowuid(current->cred->uid);
273+
return high2lowuid(from_kuid_munged(current_user_ns(), current_uid()));
262274
}
263275

264276
asmlinkage long sys32_geteuid16(void)
265277
{
266-
return high2lowuid(current->cred->euid);
278+
return high2lowuid(from_kuid_munged(current_user_ns(), current_euid()));
267279
}
268280

269281
asmlinkage long sys32_getgid16(void)
270282
{
271-
return high2lowgid(current->cred->gid);
283+
return high2lowgid(from_kgid_munged(current_user_ns(), current_gid()));
272284
}
273285

274286
asmlinkage long sys32_getegid16(void)
275287
{
276-
return high2lowgid(current->cred->egid);
288+
return high2lowgid(from_kgid_munged(current_user_ns(), current_egid()));
277289
}
278290

279291
/*

‎drivers/base/devtmpfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ static int handle_remove(const char *nodename, struct device *dev)
309309
* before unlinking this node, reset permissions
310310
* of possible references like hardlinks
311311
*/
312-
newattrs.ia_uid = 0;
313-
newattrs.ia_gid = 0;
312+
newattrs.ia_uid = GLOBAL_ROOT_UID;
313+
newattrs.ia_gid = GLOBAL_ROOT_GID;
314314
newattrs.ia_mode = stat.mode & ~0777;
315315
newattrs.ia_valid =
316316
ATTR_UID|ATTR_GID|ATTR_MODE;

‎drivers/block/loop.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,10 +1038,10 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
10381038
{
10391039
int err;
10401040
struct loop_func_table *xfer;
1041-
uid_t uid = current_uid();
1041+
kuid_t uid = current_uid();
10421042

10431043
if (lo->lo_encrypt_key_size &&
1044-
lo->lo_key_owner != uid &&
1044+
!uid_eq(lo->lo_key_owner, uid) &&
10451045
!capable(CAP_SYS_ADMIN))
10461046
return -EPERM;
10471047
if (lo->lo_state != Lo_bound)

‎drivers/connector/cn_proc.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/gfp.h>
3131
#include <linux/ptrace.h>
3232
#include <linux/atomic.h>
33+
#include <linux/pid_namespace.h>
3334

3435
#include <asm/unaligned.h>
3536

@@ -127,11 +128,11 @@ void proc_id_connector(struct task_struct *task, int which_id)
127128
rcu_read_lock();
128129
cred = __task_cred(task);
129130
if (which_id == PROC_EVENT_UID) {
130-
ev->event_data.id.r.ruid = cred->uid;
131-
ev->event_data.id.e.euid = cred->euid;
131+
ev->event_data.id.r.ruid = from_kuid_munged(&init_user_ns, cred->uid);
132+
ev->event_data.id.e.euid = from_kuid_munged(&init_user_ns, cred->euid);
132133
} else if (which_id == PROC_EVENT_GID) {
133-
ev->event_data.id.r.rgid = cred->gid;
134-
ev->event_data.id.e.egid = cred->egid;
134+
ev->event_data.id.r.rgid = from_kgid_munged(&init_user_ns, cred->gid);
135+
ev->event_data.id.e.egid = from_kgid_munged(&init_user_ns, cred->egid);
135136
} else {
136137
rcu_read_unlock();
137138
return;
@@ -303,6 +304,15 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
303304
if (msg->len != sizeof(*mc_op))
304305
return;
305306

307+
/*
308+
* Events are reported with respect to the initial pid
309+
* and user namespaces so ignore requestors from
310+
* other namespaces.
311+
*/
312+
if ((current_user_ns() != &init_user_ns) ||
313+
(task_active_pid_ns(current) != &init_pid_ns))
314+
return;
315+
306316
mc_op = (enum proc_cn_mcast_op *)msg->data;
307317
switch (*mc_op) {
308318
case PROC_CN_MCAST_LISTEN:

0 commit comments

Comments
 (0)