Skip to contentSkip to conversation

proc: use ns_capable instead of capable for timerslack_ns

PATCH Superseded [email protected] 3 participants 5 messages Oct 17, 2018 – Oct 30, 2018 Proc filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: use ns_capable instead of capable for timerslack_ns

From: Benjamin Gordon <[email protected]>

Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns.

Cc John Stultz <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arjan van de Ven <[email protected]>
Cc Oren Laadan <[email protected]>
Cc Ruchi Kandoi <[email protected]>
Cc Rom Lemarchand <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Colin Cross <[email protected]>
Cc Nick Kralevich <[email protected]>
Cc Dmitry Shmidt <[email protected]>
Cc Elliott Hughes <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Andrew Morton <[email protected]>
---
 fs/proc/base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +2 -2
index 7e9f07bf260d..4b50937dff80 100644
@@ -2356,7 +2356,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
 		return -ESRCH;
 
 	if (p != current) {
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(file->f_cred->user_ns, CAP_SYS_NICE)) {
 			count = -EPERM;
 			goto out;
 		}
@@ -2393,7 +2393,7 @@ static int timerslack_ns_show(struct seq_file *m, void *v)
 
 	if (p != current) {
 
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(seq_user_ns(m), CAP_SYS_NICE)) {
 			err = -EPERM;
 			goto out;
 		}
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog
#1 lore raw
Quoted 51 lines · On Wed, Oct 17, 2018 at 04:47:38PM -0600, [email protected] wrote:

Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns.

Cc John Stultz <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arjan van de Ven <[email protected]>
Cc Oren Laadan <[email protected]>
Cc Ruchi Kandoi <[email protected]>
Cc Rom Lemarchand <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Colin Cross <[email protected]>
Cc Nick Kralevich <[email protected]>
Cc Dmitry Shmidt <[email protected]>
Cc Elliott Hughes <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Andrew Morton <[email protected]>
---
 fs/proc/base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +2 -2
index 7e9f07bf260d..4b50937dff80 100644
@@ -2356,7 +2356,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
 		return -ESRCH;
 
 	if (p != current) {
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(file->f_cred->user_ns, CAP_SYS_NICE)) {
 			count = -EPERM;
 			goto out;
 		}
@@ -2393,7 +2393,7 @@ static int timerslack_ns_show(struct seq_file *m, void *v)
 
 	if (p != current) {
 
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(seq_user_ns(m), CAP_SYS_NICE)) {
 			err = -EPERM;
 			goto out;
 		}
Signature · 1 line
2.19.1.331.ge82ca0e54c-goog

Friendly ping. Does anybody have time to take a look at this?

Thanks,
Benjamin

Acked-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 42 lines · On Wed, Oct 17, 2018 at 3:47 PM, <[email protected]> wrote:

From: Benjamin Gordon <[email protected]>

Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns.

Cc John Stultz <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arjan van de Ven <[email protected]>
Cc Oren Laadan <[email protected]>
Cc Ruchi Kandoi <[email protected]>
Cc Rom Lemarchand <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Colin Cross <[email protected]>
Cc Nick Kralevich <[email protected]>
Cc Dmitry Shmidt <[email protected]>
Cc Elliott Hughes <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Andrew Morton <[email protected]>
---
 fs/proc/base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +1 -1
index 7e9f07bf260d..4b50937dff80 100644
@@ -2356,7 +2356,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
                return -ESRCH;
 
        if (p != current) {
-               if (!capable(CAP_SYS_NICE)) {
+               if (!ns_capable(file->f_cred->user_ns, CAP_SYS_NICE)) {
                        count = -EPERM;
                        goto out;
                }

fs/proc/base.c static int timerslack_ns_show(struct seq_file *m, void *v) · line 2399

Quoted 8 lines
fs/proc/base.c +1 -1
@@ -2393,7 +2393,7 @@ static int timerslack_ns_show(struct seq_file *m, void *v)
 
        if (p != current) {
 
-               if (!capable(CAP_SYS_NICE)) {
+               if (!ns_capable(seq_user_ns(m), CAP_SYS_NICE)) {
                        err = -EPERM;
                        goto out;
                }

Looks reasonable to me.

thanks
-john

#3 lore raw
In reply to [email protected]
Quoted 7 lines · [email protected] writes:

From: Benjamin Gordon <[email protected]>

Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns.

The goal seems legitimate. However the permission checks look wrong.

In particular the choice of user namespace should be "p->cred->user_ns". This will limit this to tasks that have CAP_SYS_NICE in the same namespace as the task that is being modified.

Testing file->f_cred->user_ns it is testing whoever opened the file and that could be anyone.

Eric

Quoted 42 lines
Cc John Stultz <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arjan van de Ven <[email protected]>
Cc Oren Laadan <[email protected]>
Cc Ruchi Kandoi <[email protected]>
Cc Rom Lemarchand <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Colin Cross <[email protected]>
Cc Nick Kralevich <[email protected]>
Cc Dmitry Shmidt <[email protected]>
Cc Elliott Hughes <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Andrew Morton <[email protected]>
---
 fs/proc/base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +2 -2
index 7e9f07bf260d..4b50937dff80 100644
@@ -2356,7 +2356,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
 		return -ESRCH;
 
 	if (p != current) {
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(file->f_cred->user_ns, CAP_SYS_NICE)) {
 			count = -EPERM;
 			goto out;
 		}
@@ -2393,7 +2393,7 @@ static int timerslack_ns_show(struct seq_file *m, void *v)
 
 	if (p != current) {
 
-		if (!capable(CAP_SYS_NICE)) {
+		if (!ns_capable(seq_user_ns(m), CAP_SYS_NICE)) {
 			err = -EPERM;
 			goto out;
 		}
#4 lore raw
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines

Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns.

Quoted 8 lines

The goal seems legitimate. However the permission checks look wrong.

In particular the choice of user namespace should be "p->cred->user_ns". This will limit this to tasks that have CAP_SYS_NICE in the same namespace as the task that is being modified.

Testing file->f_cred->user_ns it is testing whoever opened the file and that could be anyone.

Thanks, that seems like the right answer here. I'll send a v2 to fix it.

Thanks,
Benjamin