aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/proc.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-02 14:11:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-02 14:11:09 -0400
commit437589a74b6a590d175f86cf9f7b2efcee7765e7 (patch)
tree37bf8635b1356d80ef002b00e84f3faf3d555a63 /security/keys/proc.c
parent68d47a137c3bef754923bccf73fb639c9b0bbd5e (diff)
parent72235465864d84cedb2d9f26f8e1de824ee20339 (diff)
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 ...
Diffstat (limited to 'security/keys/proc.c')
-rw-r--r--security/keys/proc.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/security/keys/proc.c b/security/keys/proc.c
index 30d1ddfd9cef..217b6855e815 100644
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -88,14 +88,14 @@ __initcall(key_proc_init);
88 */ 88 */
89#ifdef CONFIG_KEYS_DEBUG_PROC_KEYS 89#ifdef CONFIG_KEYS_DEBUG_PROC_KEYS
90 90
91static struct rb_node *key_serial_next(struct rb_node *n) 91static struct rb_node *key_serial_next(struct seq_file *p, struct rb_node *n)
92{ 92{
93 struct user_namespace *user_ns = current_user_ns(); 93 struct user_namespace *user_ns = seq_user_ns(p);
94 94
95 n = rb_next(n); 95 n = rb_next(n);
96 while (n) { 96 while (n) {
97 struct key *key = rb_entry(n, struct key, serial_node); 97 struct key *key = rb_entry(n, struct key, serial_node);
98 if (key->user->user_ns == user_ns) 98 if (kuid_has_mapping(user_ns, key->user->uid))
99 break; 99 break;
100 n = rb_next(n); 100 n = rb_next(n);
101 } 101 }
@@ -107,9 +107,9 @@ static int proc_keys_open(struct inode *inode, struct file *file)
107 return seq_open(file, &proc_keys_ops); 107 return seq_open(file, &proc_keys_ops);
108} 108}
109 109
110static struct key *find_ge_key(key_serial_t id) 110static struct key *find_ge_key(struct seq_file *p, key_serial_t id)
111{ 111{
112 struct user_namespace *user_ns = current_user_ns(); 112 struct user_namespace *user_ns = seq_user_ns(p);
113 struct rb_node *n = key_serial_tree.rb_node; 113 struct rb_node *n = key_serial_tree.rb_node;
114 struct key *minkey = NULL; 114 struct key *minkey = NULL;
115 115
@@ -132,7 +132,7 @@ static struct key *find_ge_key(key_serial_t id)
132 return NULL; 132 return NULL;
133 133
134 for (;;) { 134 for (;;) {
135 if (minkey->user->user_ns == user_ns) 135 if (kuid_has_mapping(user_ns, minkey->user->uid))
136 return minkey; 136 return minkey;
137 n = rb_next(&minkey->serial_node); 137 n = rb_next(&minkey->serial_node);
138 if (!n) 138 if (!n)
@@ -151,7 +151,7 @@ static void *proc_keys_start(struct seq_file *p, loff_t *_pos)
151 151
152 if (*_pos > INT_MAX) 152 if (*_pos > INT_MAX)
153 return NULL; 153 return NULL;
154 key = find_ge_key(pos); 154 key = find_ge_key(p, pos);
155 if (!key) 155 if (!key)
156 return NULL; 156 return NULL;
157 *_pos = key->serial; 157 *_pos = key->serial;
@@ -168,7 +168,7 @@ static void *proc_keys_next(struct seq_file *p, void *v, loff_t *_pos)
168{ 168{
169 struct rb_node *n; 169 struct rb_node *n;
170 170
171 n = key_serial_next(v); 171 n = key_serial_next(p, v);
172 if (n) 172 if (n)
173 *_pos = key_node_serial(n); 173 *_pos = key_node_serial(n);
174 return n; 174 return n;
@@ -254,8 +254,8 @@ static int proc_keys_show(struct seq_file *m, void *v)
254 atomic_read(&key->usage), 254 atomic_read(&key->usage),
255 xbuf, 255 xbuf,
256 key->perm, 256 key->perm,
257 key->uid, 257 from_kuid_munged(seq_user_ns(m), key->uid),
258 key->gid, 258 from_kgid_munged(seq_user_ns(m), key->gid),
259 key->type->name); 259 key->type->name);
260 260
261#undef showflag 261#undef showflag
@@ -270,26 +270,26 @@ static int proc_keys_show(struct seq_file *m, void *v)
270 270
271#endif /* CONFIG_KEYS_DEBUG_PROC_KEYS */ 271#endif /* CONFIG_KEYS_DEBUG_PROC_KEYS */
272 272
273static struct rb_node *__key_user_next(struct rb_node *n) 273static struct rb_node *__key_user_next(struct user_namespace *user_ns, struct rb_node *n)
274{ 274{
275 while (n) { 275 while (n) {
276 struct key_user *user = rb_entry(n, struct key_user, node); 276 struct key_user *user = rb_entry(n, struct key_user, node);
277 if (user->user_ns == current_user_ns()) 277 if (kuid_has_mapping(user_ns, user->uid))
278 break; 278 break;
279 n = rb_next(n); 279 n = rb_next(n);
280 } 280 }
281 return n; 281 return n;
282} 282}
283 283
284static struct rb_node *key_user_next(struct rb_node *n) 284static struct rb_node *key_user_next(struct user_namespace *user_ns, struct rb_node *n)
285{ 285{
286 return __key_user_next(rb_next(n)); 286 return __key_user_next(user_ns, rb_next(n));
287} 287}
288 288
289static struct rb_node *key_user_first(struct rb_root *r) 289static struct rb_node *key_user_first(struct user_namespace *user_ns, struct rb_root *r)
290{ 290{
291 struct rb_node *n = rb_first(r); 291 struct rb_node *n = rb_first(r);
292 return __key_user_next(n); 292 return __key_user_next(user_ns, n);
293} 293}
294 294
295/* 295/*
@@ -309,10 +309,10 @@ static void *proc_key_users_start(struct seq_file *p, loff_t *_pos)
309 309
310 spin_lock(&key_user_lock); 310 spin_lock(&key_user_lock);
311 311
312 _p = key_user_first(&key_user_tree); 312 _p = key_user_first(seq_user_ns(p), &key_user_tree);
313 while (pos > 0 && _p) { 313 while (pos > 0 && _p) {
314 pos--; 314 pos--;
315 _p = key_user_next(_p); 315 _p = key_user_next(seq_user_ns(p), _p);
316 } 316 }
317 317
318 return _p; 318 return _p;
@@ -321,7 +321,7 @@ static void *proc_key_users_start(struct seq_file *p, loff_t *_pos)
321static void *proc_key_users_next(struct seq_file *p, void *v, loff_t *_pos) 321static void *proc_key_users_next(struct seq_file *p, void *v, loff_t *_pos)
322{ 322{
323 (*_pos)++; 323 (*_pos)++;
324 return key_user_next((struct rb_node *)v); 324 return key_user_next(seq_user_ns(p), (struct rb_node *)v);
325} 325}
326 326
327static void proc_key_users_stop(struct seq_file *p, void *v) 327static void proc_key_users_stop(struct seq_file *p, void *v)
@@ -334,13 +334,13 @@ static int proc_key_users_show(struct seq_file *m, void *v)
334{ 334{
335 struct rb_node *_p = v; 335 struct rb_node *_p = v;
336 struct key_user *user = rb_entry(_p, struct key_user, node); 336 struct key_user *user = rb_entry(_p, struct key_user, node);
337 unsigned maxkeys = (user->uid == 0) ? 337 unsigned maxkeys = uid_eq(user->uid, GLOBAL_ROOT_UID) ?
338 key_quota_root_maxkeys : key_quota_maxkeys; 338 key_quota_root_maxkeys : key_quota_maxkeys;
339 unsigned maxbytes = (user->uid == 0) ? 339 unsigned maxbytes = uid_eq(user->uid, GLOBAL_ROOT_UID) ?
340 key_quota_root_maxbytes : key_quota_maxbytes; 340 key_quota_root_maxbytes : key_quota_maxbytes;
341 341
342 seq_printf(m, "%5u: %5d %d/%d %d/%d %d/%d\n", 342 seq_printf(m, "%5u: %5d %d/%d %d/%d %d/%d\n",
343 user->uid, 343 from_kuid_munged(seq_user_ns(m), user->uid),
344 atomic_read(&user->usage), 344 atomic_read(&user->usage),
345 atomic_read(&user->nkeys), 345 atomic_read(&user->nkeys),
346 atomic_read(&user->nikeys), 346 atomic_read(&user->nikeys),