aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:42:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:42:39 -0400
commit644473e9c60c1ff4f6351fed637a6e5551e3dce7 (patch)
tree10316518bedc735a2c6552886658d69dfd9f1eb0 /net/sunrpc
parentfb827ec68446c83e9e8754fa9b55aed27ecc4661 (diff)
parent4b06a81f1daee668fbd6de85557bfb36dd36078f (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull user namespace enhancements from Eric Biederman: "This is a course correction for the user namespace, so that we can reach an inexpensive, maintainable, and reasonably complete implementation. Highlights: - Config guards make it impossible to enable the user namespace and code that has not been converted to be user namespace safe. - Use of the new kuid_t type ensures the if you somehow get past the config guards the kernel will encounter type errors if you enable user namespaces and attempt to compile in code whose permission checks have not been updated to be user namespace safe. - All uids from child user namespaces are mapped into the initial user namespace before they are processed. Removing the need to add an additional check to see if the user namespace of the compared uids remains the same. - With the user namespaces compiled out the performance is as good or better than it is today. - For most operations absolutely nothing changes performance or operationally with the user namespace enabled. - The worst case performance I could come up with was timing 1 billion cache cold stat operations with the user namespace code enabled. This went from 156s to 164s on my laptop (or 156ns to 164ns per stat operation). - (uid_t)-1 and (gid_t)-1 are reserved as an internal error value. Most uid/gid setting system calls treat these value specially anyway so attempting to use -1 as a uid would likely cause entertaining failures in userspace. - If setuid is called with a uid that can not be mapped setuid fails. I have looked at sendmail, login, ssh and every other program I could think of that would call setuid and they all check for and handle the case where setuid fails. - If stat or a similar system call is called from a context in which we can not map a uid we lie and return overflowuid. The LFS experience suggests not lying and returning an error code might be better, but the historical precedent with uids is different and I can not think of anything that would break by lying about a uid we can't map. - Capabilities are localized to the current user namespace making it safe to give the initial user in a user namespace all capabilities. My git tree covers all of the modifications needed to convert the core kernel and enough changes to make a system bootable to runlevel 1." Fix up trivial conflicts due to nearby independent changes in fs/stat.c * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (46 commits) userns: Silence silly gcc warning. cred: use correct cred accessor with regards to rcu read lock userns: Convert the move_pages, and migrate_pages permission checks to use uid_eq userns: Convert cgroup permission checks to use uid_eq userns: Convert tmpfs to use kuid and kgid where appropriate userns: Convert sysfs to use kgid/kuid where appropriate userns: Convert sysctl permission checks to use kuid and kgids. userns: Convert proc to use kuid/kgid where appropriate userns: Convert ext4 to user kuid/kgid where appropriate userns: Convert ext3 to use kuid/kgid where appropriate userns: Convert ext2 to use kuid/kgid where appropriate. userns: Convert devpts to use kuid/kgid where appropriate userns: Convert binary formats to use kuid/kgid where appropriate userns: Add negative depends on entries to avoid building code that is userns unsafe userns: signal remove unnecessary map_cred_ns userns: Teach inode_capable to understand inodes whose uids map to other namespaces. userns: Fail exec for suid and sgid binaries with ids outside our user namespace. userns: Convert stat to return values mapped from kuids and kgids userns: Convert user specfied uids and gids in chown into kuids and kgid userns: Use uid_eq gid_eq helpers when comparing kuids and kgids in the vfs ...
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/auth_generic.c4
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c7
-rw-r--r--net/sunrpc/auth_unix.c15
-rw-r--r--net/sunrpc/svcauth_unix.c18
4 files changed, 33 insertions, 11 deletions
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
index 75762f346975..6ed6f201b022 100644
--- a/net/sunrpc/auth_generic.c
+++ b/net/sunrpc/auth_generic.c
@@ -160,8 +160,8 @@ generic_match(struct auth_cred *acred, struct rpc_cred *cred, int flags)
160 if (gcred->acred.group_info->ngroups != acred->group_info->ngroups) 160 if (gcred->acred.group_info->ngroups != acred->group_info->ngroups)
161 goto out_nomatch; 161 goto out_nomatch;
162 for (i = 0; i < gcred->acred.group_info->ngroups; i++) { 162 for (i = 0; i < gcred->acred.group_info->ngroups; i++) {
163 if (GROUP_AT(gcred->acred.group_info, i) != 163 if (!gid_eq(GROUP_AT(gcred->acred.group_info, i),
164 GROUP_AT(acred->group_info, i)) 164 GROUP_AT(acred->group_info, i)))
165 goto out_nomatch; 165 goto out_nomatch;
166 } 166 }
167out_match: 167out_match:
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 1600cfb1618c..28b62dbb6d1e 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -41,6 +41,7 @@
41#include <linux/types.h> 41#include <linux/types.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/pagemap.h> 43#include <linux/pagemap.h>
44#include <linux/user_namespace.h>
44 45
45#include <linux/sunrpc/auth_gss.h> 46#include <linux/sunrpc/auth_gss.h>
46#include <linux/sunrpc/gss_err.h> 47#include <linux/sunrpc/gss_err.h>
@@ -470,9 +471,13 @@ static int rsc_parse(struct cache_detail *cd,
470 status = -EINVAL; 471 status = -EINVAL;
471 for (i=0; i<N; i++) { 472 for (i=0; i<N; i++) {
472 gid_t gid; 473 gid_t gid;
474 kgid_t kgid;
473 if (get_int(&mesg, &gid)) 475 if (get_int(&mesg, &gid))
474 goto out; 476 goto out;
475 GROUP_AT(rsci.cred.cr_group_info, i) = gid; 477 kgid = make_kgid(&init_user_ns, gid);
478 if (!gid_valid(kgid))
479 goto out;
480 GROUP_AT(rsci.cred.cr_group_info, i) = kgid;
476 } 481 }
477 482
478 /* mech name */ 483 /* mech name */
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index e50502d8ceb7..52c5abdee211 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/sunrpc/clnt.h> 13#include <linux/sunrpc/clnt.h>
14#include <linux/sunrpc/auth.h> 14#include <linux/sunrpc/auth.h>
15#include <linux/user_namespace.h>
15 16
16#define NFS_NGROUPS 16 17#define NFS_NGROUPS 16
17 18
@@ -78,8 +79,11 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
78 groups = NFS_NGROUPS; 79 groups = NFS_NGROUPS;
79 80
80 cred->uc_gid = acred->gid; 81 cred->uc_gid = acred->gid;
81 for (i = 0; i < groups; i++) 82 for (i = 0; i < groups; i++) {
82 cred->uc_gids[i] = GROUP_AT(acred->group_info, i); 83 gid_t gid;
84 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
85 cred->uc_gids[i] = gid;
86 }
83 if (i < NFS_NGROUPS) 87 if (i < NFS_NGROUPS)
84 cred->uc_gids[i] = NOGROUP; 88 cred->uc_gids[i] = NOGROUP;
85 89
@@ -126,9 +130,12 @@ unx_match(struct auth_cred *acred, struct rpc_cred *rcred, int flags)
126 groups = acred->group_info->ngroups; 130 groups = acred->group_info->ngroups;
127 if (groups > NFS_NGROUPS) 131 if (groups > NFS_NGROUPS)
128 groups = NFS_NGROUPS; 132 groups = NFS_NGROUPS;
129 for (i = 0; i < groups ; i++) 133 for (i = 0; i < groups ; i++) {
130 if (cred->uc_gids[i] != GROUP_AT(acred->group_info, i)) 134 gid_t gid;
135 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
136 if (cred->uc_gids[i] != gid)
131 return 0; 137 return 0;
138 }
132 if (groups < NFS_NGROUPS && 139 if (groups < NFS_NGROUPS &&
133 cred->uc_gids[groups] != NOGROUP) 140 cred->uc_gids[groups] != NOGROUP)
134 return 0; 141 return 0;
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 521d8f7dc833..71ec8530ec8c 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -14,6 +14,7 @@
14#include <net/sock.h> 14#include <net/sock.h>
15#include <net/ipv6.h> 15#include <net/ipv6.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/user_namespace.h>
17#define RPCDBG_FACILITY RPCDBG_AUTH 18#define RPCDBG_FACILITY RPCDBG_AUTH
18 19
19#include <linux/sunrpc/clnt.h> 20#include <linux/sunrpc/clnt.h>
@@ -530,11 +531,15 @@ static int unix_gid_parse(struct cache_detail *cd,
530 531
531 for (i = 0 ; i < gids ; i++) { 532 for (i = 0 ; i < gids ; i++) {
532 int gid; 533 int gid;
534 kgid_t kgid;
533 rv = get_int(&mesg, &gid); 535 rv = get_int(&mesg, &gid);
534 err = -EINVAL; 536 err = -EINVAL;
535 if (rv) 537 if (rv)
536 goto out; 538 goto out;
537 GROUP_AT(ug.gi, i) = gid; 539 kgid = make_kgid(&init_user_ns, gid);
540 if (!gid_valid(kgid))
541 goto out;
542 GROUP_AT(ug.gi, i) = kgid;
538 } 543 }
539 544
540 ugp = unix_gid_lookup(cd, uid); 545 ugp = unix_gid_lookup(cd, uid);
@@ -563,6 +568,7 @@ static int unix_gid_show(struct seq_file *m,
563 struct cache_detail *cd, 568 struct cache_detail *cd,
564 struct cache_head *h) 569 struct cache_head *h)
565{ 570{
571 struct user_namespace *user_ns = current_user_ns();
566 struct unix_gid *ug; 572 struct unix_gid *ug;
567 int i; 573 int i;
568 int glen; 574 int glen;
@@ -580,7 +586,7 @@ static int unix_gid_show(struct seq_file *m,
580 586
581 seq_printf(m, "%u %d:", ug->uid, glen); 587 seq_printf(m, "%u %d:", ug->uid, glen);
582 for (i = 0; i < glen; i++) 588 for (i = 0; i < glen; i++)
583 seq_printf(m, " %d", GROUP_AT(ug->gi, i)); 589 seq_printf(m, " %d", from_kgid_munged(user_ns, GROUP_AT(ug->gi, i)));
584 seq_printf(m, "\n"); 590 seq_printf(m, "\n");
585 return 0; 591 return 0;
586} 592}
@@ -831,8 +837,12 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
831 cred->cr_group_info = groups_alloc(slen); 837 cred->cr_group_info = groups_alloc(slen);
832 if (cred->cr_group_info == NULL) 838 if (cred->cr_group_info == NULL)
833 return SVC_CLOSE; 839 return SVC_CLOSE;
834 for (i = 0; i < slen; i++) 840 for (i = 0; i < slen; i++) {
835 GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv); 841 kgid_t kgid = make_kgid(&init_user_ns, svc_getnl(argv));
842 if (!gid_valid(kgid))
843 goto badcred;
844 GROUP_AT(cred->cr_group_info, i) = kgid;
845 }
836 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) { 846 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
837 *authp = rpc_autherr_badverf; 847 *authp = rpc_autherr_badverf;
838 return SVC_DENIED; 848 return SVC_DENIED;