proc: use ns_capable instead of capable for timerslack_ns
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.
--- fs/proc/base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +2 -2
@@ -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
Quoted 51 lines · On Wed, Oct 17, 2018 at 04:47:38PM -0600, [email protected] wrote:
Access to
timerslack_nsis controlled by a process havingCAP_SYS_NICEin 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 byCAP_SYS_NICEinside a namespace, it should also be able to adjusttimerslack_ns.Signed-off-by Benjamin Gordon <[email protected]>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@@ -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
Quoted 42 lines · On Wed, Oct 17, 2018 at 3:47 PM, <[email protected]> wrote:
From: Benjamin Gordon <[email protected]>
Access to
timerslack_nsis controlled by a process havingCAP_SYS_NICEin 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 byCAP_SYS_NICEinside a namespace, it should also be able to adjusttimerslack_ns.Signed-off-by Benjamin Gordon <[email protected]>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@@ -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
Quoted 7 lines · [email protected] writes:
From: Benjamin Gordon <[email protected]>
Access to
timerslack_nsis controlled by a process havingCAP_SYS_NICEin 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 byCAP_SYS_NICEinside a namespace, it should also be able to adjusttimerslack_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
Signed-off-by Benjamin Gordon <[email protected]>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@@ -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; }
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines
Access to
timerslack_nsis controlled by a process havingCAP_SYS_NICEin 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 byCAP_SYS_NICEinside a namespace, it should also be able to adjusttimerslack_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 haveCAP_SYS_NICEin the same namespace as the task that is being modified.Testing
file->f_cred->user_nsit 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