From: Serge Hallyn <serge.hallyn@ubuntu.com>
To: Tyler Hicks <tyhicks@canonical.com>
Cc: linux-security-module@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Serge Hallyn <serge.hallyn@canonical.com>,
"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH 1/2] kernel: Add noaudit variant of ns_capable()
Date: Mon, 9 May 2016 04:23:47 +0000 [thread overview]
Message-ID: <20160509042347.GA22508@ubuntumail> (raw)
In-Reply-To: <1462575854-4301-2-git-send-email-tyhicks@canonical.com>
Quoting Tyler Hicks (tyhicks@canonical.com):
> When checking the current cred for a capability in a specific user
> namespace, it isn't always desirable to have the LSMs audit the check.
> This patch adds a noaudit variant of ns_capable() for when those
> situations arise.
>
> The common logic between ns_capable() and the new ns_capable_noaudit()
> is moved into a single, shared function to keep duplicated code to a
> minimum and ease maintainability.
>
> Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
> ---
> include/linux/capability.h | 5 +++++
> kernel/capability.c | 46 ++++++++++++++++++++++++++++++++++++----------
> 2 files changed, 41 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/capability.h b/include/linux/capability.h
> index 00690ff..5f3c63d 100644
> --- a/include/linux/capability.h
> +++ b/include/linux/capability.h
> @@ -206,6 +206,7 @@ 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_noaudit(struct user_namespace *ns, int cap);
> #else
> static inline bool has_capability(struct task_struct *t, int cap)
> {
> @@ -233,6 +234,10 @@ static inline bool ns_capable(struct user_namespace *ns, int cap)
> {
> return true;
> }
> +static inline bool ns_capable_noaudit(struct user_namespace *ns, int cap)
> +{
> + return true;
> +}
> #endif /* CONFIG_MULTIUSER */
> extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
> extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
> diff --git a/kernel/capability.c b/kernel/capability.c
> index 45432b5..00411c8 100644
> --- a/kernel/capability.c
> +++ b/kernel/capability.c
> @@ -361,6 +361,24 @@ 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, bool audit)
> +{
> + int capable;
> +
> + if (unlikely(!cap_valid(cap))) {
> + pr_crit("capable() called with invalid cap=%u\n", cap);
> + BUG();
> + }
> +
> + capable = audit ? security_capable(current_cred(), ns, cap) :
> + security_capable_noaudit(current_cred(), ns, cap);
> + if (capable == 0) {
> + current->flags |= PF_SUPERPRIV;
> + return true;
> + }
> + return false;
> +}
> +
> /**
> * ns_capable - Determine if the current task has a superior capability in effect
> * @ns: The usernamespace we want the capability in
> @@ -374,19 +392,27 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
> */
> bool ns_capable(struct user_namespace *ns, int cap)
> {
> - if (unlikely(!cap_valid(cap))) {
> - pr_crit("capable() called with invalid cap=%u\n", cap);
> - BUG();
> - }
> -
> - if (security_capable(current_cred(), ns, cap) == 0) {
> - current->flags |= PF_SUPERPRIV;
> - return true;
> - }
> - return false;
> + return ns_capable_common(ns, cap, true);
> }
> EXPORT_SYMBOL(ns_capable);
>
> +/**
> + * ns_capable_noaudit - Determine if the current task has a superior capability
> + * (unaudited) in effect
> + * @ns: The usernamespace we want the capability in
> + * @cap: The capability to be tested for
> + *
> + * Return true if the current task has the given superior capability currently
> + * available for use, false if not.
> + *
> + * This sets PF_SUPERPRIV on the task if the capability is available on the
> + * assumption that it's about to be used.
> + */
> +bool ns_capable_noaudit(struct user_namespace *ns, int cap)
> +{
> + return ns_capable_common(ns, cap, false);
> +}
> +EXPORT_SYMBOL(ns_capable_noaudit);
>
> /**
> * capable - Determine if the current task has a superior capability in effect
> --
> 2.7.4
>
next prev parent reply other threads:[~2016-05-09 4:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-06 23:04 [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks
2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks
2016-05-09 4:23 ` Serge Hallyn [this message]
2016-05-06 23:04 ` [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks
2016-05-09 4:24 ` Serge Hallyn
2016-05-09 3:56 ` [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl David Miller
2016-05-17 14:13 ` Tyler Hicks
2016-06-02 16:30 ` Tyler Hicks
2016-06-03 1:00 ` James Morris
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=20160509042347.GA22508@ubuntumail \
--to=serge.hallyn@ubuntu.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=serge.hallyn@canonical.com \
--cc=tyhicks@canonical.com \
/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;
as well as URLs for NNTP newsgroup(s).