From: Christian Brauner <christian.brauner@ubuntu.com>
To: linux-kernel@vger.kernel.org
Cc: "Alexander Viro" <viro@zeniv.linux.org.uk>,
"Stéphane Graber" <stgraber@ubuntu.com>,
"Linux Containers" <containers@lists.linux-foundation.org>,
"Eric W . Biederman" <ebiederm@xmission.com>,
"Serge Hallyn" <serge@hallyn.com>, "Jann Horn" <jannh@google.com>,
"Michael Kerrisk" <mtk.manpages@gmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
linux-api@vger.kernel.org,
"Christian Brauner" <christian.brauner@ubuntu.com>
Subject: [PATCH v2 1/4] capability: add ns_capable_cred()
Date: Thu, 30 Apr 2020 18:57:14 +0200 [thread overview]
Message-ID: <20200430165717.1001605-1-christian.brauner@ubuntu.com> (raw)
Add a simple capability helper which makes it possible to determine
whether a set of creds is ns capable wrt to the passed in credentials.
This is not something exciting it's just a more pleasant wrapper around
security_capable() by allowing ns_capable_common() to ake a const struct
cred argument. In ptrace_has_cap() for example, we're using
security_capable() directly. ns_capable_cred() will be used in the next
patch to check against the target credentials the caller is going to
switch to.
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
/* v2 */
patch introduced
---
include/linux/capability.h | 3 +++
kernel/capability.c | 17 +++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/include/linux/capability.h b/include/linux/capability.h
index ecce0f43c73a..743a08d936fb 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -40,6 +40,7 @@ struct cpu_vfs_cap_data {
struct file;
struct inode;
struct dentry;
+struct cred;
struct task_struct;
struct user_namespace;
@@ -209,6 +210,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
struct user_namespace *ns, int cap);
extern bool capable(int cap);
extern bool ns_capable(struct user_namespace *ns, int cap);
+extern bool ns_capable_cred(const struct cred *cred,
+ struct user_namespace *ns, int cap);
extern bool ns_capable_noaudit(struct user_namespace *ns, int cap);
extern bool ns_capable_setid(struct user_namespace *ns, int cap);
#else
diff --git a/kernel/capability.c b/kernel/capability.c
index 1444f3954d75..84425781917e 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -361,8 +361,8 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
return has_ns_capability_noaudit(t, &init_user_ns, cap);
}
-static bool ns_capable_common(struct user_namespace *ns,
- int cap,
+static bool ns_capable_common(const struct cred *cred,
+ struct user_namespace *ns, int cap,
unsigned int opts)
{
int capable;
@@ -372,7 +372,7 @@ static bool ns_capable_common(struct user_namespace *ns,
BUG();
}
- capable = security_capable(current_cred(), ns, cap, opts);
+ capable = security_capable(cred, ns, cap, opts);
if (capable == 0) {
current->flags |= PF_SUPERPRIV;
return true;
@@ -393,10 +393,15 @@ static bool ns_capable_common(struct user_namespace *ns,
*/
bool ns_capable(struct user_namespace *ns, int cap)
{
- return ns_capable_common(ns, cap, CAP_OPT_NONE);
+ return ns_capable_common(current_cred(), ns, cap, CAP_OPT_NONE);
}
EXPORT_SYMBOL(ns_capable);
+bool ns_capable_cred(const struct cred *cred, struct user_namespace *ns, int cap)
+{
+ return ns_capable_common(cred, ns, cap, CAP_OPT_NONE);
+}
+
/**
* ns_capable_noaudit - Determine if the current task has a superior capability
* (unaudited) in effect
@@ -411,7 +416,7 @@ EXPORT_SYMBOL(ns_capable);
*/
bool ns_capable_noaudit(struct user_namespace *ns, int cap)
{
- return ns_capable_common(ns, cap, CAP_OPT_NOAUDIT);
+ return ns_capable_common(current_cred(), ns, cap, CAP_OPT_NOAUDIT);
}
EXPORT_SYMBOL(ns_capable_noaudit);
@@ -430,7 +435,7 @@ EXPORT_SYMBOL(ns_capable_noaudit);
*/
bool ns_capable_setid(struct user_namespace *ns, int cap)
{
- return ns_capable_common(ns, cap, CAP_OPT_INSETID);
+ return ns_capable_common(current_cred(), ns, cap, CAP_OPT_INSETID);
}
EXPORT_SYMBOL(ns_capable_setid);
base-commit: ae83d0b416db002fe95601e7f97f64b59514d936
--
2.26.2
next reply other threads:[~2020-04-30 16:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-30 16:57 Christian Brauner [this message]
2020-04-30 16:57 ` [PATCH v2 2/4] nsproxy: add struct nsset Christian Brauner
2020-04-30 16:57 ` [PATCH v2 3/4] nsproxy: attach to namespaces via pidfds Christian Brauner
2020-06-15 11:13 ` Michael Kerrisk (man-pages)
2020-06-15 15:45 ` Christian Brauner
2020-04-30 16:57 ` [PATCH v2 4/4] selftests/pidfd: add pidfd setns tests Christian Brauner
2020-04-30 18:09 ` [PATCH v2 1/4] capability: add ns_capable_cred() Eric W. Biederman
2020-05-01 15:42 ` Christian Brauner
2020-05-02 12:35 ` Eric W. Biederman
2020-05-02 14:32 ` Christian Brauner
2020-05-02 14:52 ` Eric W. Biederman
2020-05-02 15:13 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200430165717.1001605-1-christian.brauner@ubuntu.com \
--to=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=cyphar@cyphar.com \
--cc=ebiederm@xmission.com \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=serge@hallyn.com \
--cc=stgraber@ubuntu.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox