Skip to content

Commit c7b96ac

Browse files
committed
userns: Kill nsown_capable it makes the wrong thing easy
nsown_capable is a special case of ns_capable essentially for just CAP_SETUID and CAP_SETGID. For the existing users it doesn't noticably simplify things and from the suggested patches I have seen it encourages people to do the wrong thing. So remove nsown_capable. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent f54fb86 commit c7b96ac

12 files changed

Lines changed: 21 additions & 34 deletions

File tree

‎fs/namespace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,8 +2929,8 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
29292929
struct path root;
29302930

29312931
if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) ||
2932-
!nsown_capable(CAP_SYS_CHROOT) ||
2933-
!nsown_capable(CAP_SYS_ADMIN))
2932+
!ns_capable(current_user_ns(), CAP_SYS_CHROOT) ||
2933+
!ns_capable(current_user_ns(), CAP_SYS_ADMIN))
29342934
return -EPERM;
29352935

29362936
if (fs->users != 1)

‎fs/open.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
443443
goto dput_and_out;
444444

445445
error = -EPERM;
446-
if (!nsown_capable(CAP_SYS_CHROOT))
446+
if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
447447
goto dput_and_out;
448448
error = security_path_chroot(&path);
449449
if (error)

‎include/linux/capability.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
210210
struct user_namespace *ns, int cap);
211211
extern bool capable(int cap);
212212
extern bool ns_capable(struct user_namespace *ns, int cap);
213-
extern bool nsown_capable(int cap);
214213
extern bool inode_capable(const struct inode *inode, int cap);
215214
extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
216215

‎ipc/namespace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new)
171171
{
172172
struct ipc_namespace *ns = new;
173173
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
174-
!nsown_capable(CAP_SYS_ADMIN))
174+
!ns_capable(current_user_ns(), CAP_SYS_ADMIN))
175175
return -EPERM;
176176

177177
/* Ditch state from the old ipc namespace */

‎kernel/capability.c‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,6 @@ bool capable(int cap)
432432
}
433433
EXPORT_SYMBOL(capable);
434434

435-
/**
436-
* nsown_capable - Check superior capability to one's own user_ns
437-
* @cap: The capability in question
438-
*
439-
* Return true if the current task has the given superior capability
440-
* targeted at its own user namespace.
441-
*/
442-
bool nsown_capable(int cap)
443-
{
444-
return ns_capable(current_user_ns(), cap);
445-
}
446-
447435
/**
448436
* inode_capable - Check superior capability over inode
449437
* @inode: The inode in question

‎kernel/groups.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist)
233233
struct group_info *group_info;
234234
int retval;
235235

236-
if (!nsown_capable(CAP_SETGID))
236+
if (!ns_capable(current_user_ns(), CAP_SETGID))
237237
return -EPERM;
238238
if ((unsigned)gidsetsize > NGROUPS_MAX)
239239
return -EINVAL;

‎kernel/pid_namespace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
329329
struct pid_namespace *ancestor, *new = ns;
330330

331331
if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) ||
332-
!nsown_capable(CAP_SYS_ADMIN))
332+
!ns_capable(current_user_ns(), CAP_SYS_ADMIN))
333333
return -EPERM;
334334

335335
/*

‎kernel/sys.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
337337
if (rgid != (gid_t) -1) {
338338
if (gid_eq(old->gid, krgid) ||
339339
gid_eq(old->egid, krgid) ||
340-
nsown_capable(CAP_SETGID))
340+
ns_capable(old->user_ns, CAP_SETGID))
341341
new->gid = krgid;
342342
else
343343
goto error;
@@ -346,7 +346,7 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
346346
if (gid_eq(old->gid, kegid) ||
347347
gid_eq(old->egid, kegid) ||
348348
gid_eq(old->sgid, kegid) ||
349-
nsown_capable(CAP_SETGID))
349+
ns_capable(old->user_ns, CAP_SETGID))
350350
new->egid = kegid;
351351
else
352352
goto error;
@@ -387,7 +387,7 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
387387
old = current_cred();
388388

389389
retval = -EPERM;
390-
if (nsown_capable(CAP_SETGID))
390+
if (ns_capable(old->user_ns, CAP_SETGID))
391391
new->gid = new->egid = new->sgid = new->fsgid = kgid;
392392
else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
393393
new->egid = new->fsgid = kgid;
@@ -471,7 +471,7 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
471471
new->uid = kruid;
472472
if (!uid_eq(old->uid, kruid) &&
473473
!uid_eq(old->euid, kruid) &&
474-
!nsown_capable(CAP_SETUID))
474+
!ns_capable(old->user_ns, CAP_SETUID))
475475
goto error;
476476
}
477477

@@ -480,7 +480,7 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
480480
if (!uid_eq(old->uid, keuid) &&
481481
!uid_eq(old->euid, keuid) &&
482482
!uid_eq(old->suid, keuid) &&
483-
!nsown_capable(CAP_SETUID))
483+
!ns_capable(old->user_ns, CAP_SETUID))
484484
goto error;
485485
}
486486

@@ -534,7 +534,7 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
534534
old = current_cred();
535535

536536
retval = -EPERM;
537-
if (nsown_capable(CAP_SETUID)) {
537+
if (ns_capable(old->user_ns, CAP_SETUID)) {
538538
new->suid = new->uid = kuid;
539539
if (!uid_eq(kuid, old->uid)) {
540540
retval = set_user(new);
@@ -591,7 +591,7 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
591591
old = current_cred();
592592

593593
retval = -EPERM;
594-
if (!nsown_capable(CAP_SETUID)) {
594+
if (!ns_capable(old->user_ns, CAP_SETUID)) {
595595
if (ruid != (uid_t) -1 && !uid_eq(kruid, old->uid) &&
596596
!uid_eq(kruid, old->euid) && !uid_eq(kruid, old->suid))
597597
goto error;
@@ -673,7 +673,7 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
673673
old = current_cred();
674674

675675
retval = -EPERM;
676-
if (!nsown_capable(CAP_SETGID)) {
676+
if (!ns_capable(old->user_ns, CAP_SETGID)) {
677677
if (rgid != (gid_t) -1 && !gid_eq(krgid, old->gid) &&
678678
!gid_eq(krgid, old->egid) && !gid_eq(krgid, old->sgid))
679679
goto error;
@@ -744,7 +744,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
744744

745745
if (uid_eq(kuid, old->uid) || uid_eq(kuid, old->euid) ||
746746
uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
747-
nsown_capable(CAP_SETUID)) {
747+
ns_capable(old->user_ns, CAP_SETUID)) {
748748
if (!uid_eq(kuid, old->fsuid)) {
749749
new->fsuid = kuid;
750750
if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
@@ -783,7 +783,7 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
783783

784784
if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
785785
gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
786-
nsown_capable(CAP_SETGID)) {
786+
ns_capable(old->user_ns, CAP_SETGID)) {
787787
if (!gid_eq(kgid, old->fsgid)) {
788788
new->fsgid = kgid;
789789
goto change_okay;

‎kernel/uid16.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
176176
struct group_info *group_info;
177177
int retval;
178178

179-
if (!nsown_capable(CAP_SETGID))
179+
if (!ns_capable(current_user_ns(), CAP_SETGID))
180180
return -EPERM;
181181
if ((unsigned)gidsetsize > NGROUPS_MAX)
182182
return -EINVAL;

‎kernel/utsname.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int utsns_install(struct nsproxy *nsproxy, void *new)
114114
struct uts_namespace *ns = new;
115115

116116
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) ||
117-
!nsown_capable(CAP_SYS_ADMIN))
117+
!ns_capable(current_user_ns(), CAP_SYS_ADMIN))
118118
return -EPERM;
119119

120120
get_uts_ns(ns);

0 commit comments

Comments
 (0)