Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1412786 > unrolled thread
| Started by | Tyler Hicks <tyhicks@canonical.com> |
|---|---|
| First post | 2016-06-03 06:50 +0200 |
| Last post | 2016-06-03 06:50 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks <tyhicks@canonical.com> - 2016-06-03 06:50 +0200
[PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks <tyhicks@canonical.com> - 2016-06-03 06:50 +0200
Re: [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions James Morris <jmorris@namei.org> - 2016-06-06 12:00 +0200
[PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks <tyhicks@canonical.com> - 2016-06-03 06:50 +0200
| From | Tyler Hicks <tyhicks@canonical.com> |
|---|---|
| Date | 2016-06-03 06:50 +0200 |
| Subject | [PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl |
| Message-ID | <rFPdv-73m-1@gated-at.bofh.it> |
I'm resending this patch set at the request of James Morris. This pair of
patches does away with what I believe is a useless denial audit message
when a privileged process initially accesses a net sysctl.
The bug was first discovered when running Go applications under AppArmor
confinement. It can be triggered like so:
$ echo "profile test { file, }" | sudo apparmor_parser -rq
Once the profile is loaded, invoke Go as root under confinement:
$ sudo aa-exec -p test -- go version
go version go1.6.1 linux/amd64
Here's the denial:
audit: type=1400 audit(1462575436.832:29): apparmor="DENIED" operation="capable" profile="test" pid=1157 comm="go" capability=12 capname="net_admin"
The reproducer in minimal form is:
$ sudo aa-exec -p test -- cat /proc/sys/net/core/somaxconn
128
The denial:
audit: type=1400 audit(1462575670.000:29): apparmor="DENIED" operation="capable" profile="test" pid=1161 comm="cat" capability=12 capname="net_admin"
Thanks!
Tyler
[toc] | [next] | [standalone]
| From | Tyler Hicks <tyhicks@canonical.com> |
|---|---|
| Date | 2016-06-03 06:50 +0200 |
| Subject | [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions |
| Message-ID | <rFPdv-73m-3@gated-at.bofh.it> |
| In reply to | #1412786 |
The capability check should not be audited since it is only being used
to determine the inode permissions. A failed check does not indicate a
violation of security policy but, when an LSM is enabled, a denial audit
message was being generated.
The denial audit message caused confusion for some application authors
because root-running Go applications always triggered the denial. To
prevent this confusion, the capability check in net_ctl_permissions() is
switched to the noaudit variant.
BugLink: https://launchpad.net/bugs/1465724
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
---
net/sysctl_net.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index ed98c1f..46a71c7 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
kgid_t root_gid = make_kgid(net->user_ns, 0);
/* Allow network administrator to have same access as root. */
- if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
+ if (ns_capable_noaudit(net->user_ns, CAP_NET_ADMIN) ||
uid_eq(root_uid, current_euid())) {
int mode = (table->mode >> 6) & 7;
return (mode << 6) | (mode << 3) | mode;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | James Morris <jmorris@namei.org> |
|---|---|
| Date | 2016-06-06 12:00 +0200 |
| Subject | Re: [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions |
| Message-ID | <rGZua-3a3-15@gated-at.bofh.it> |
| In reply to | #1412787 |
On Thu, 2 Jun 2016, Tyler Hicks wrote: > The capability check should not be audited since it is only being used > to determine the inode permissions. A failed check does not indicate a > violation of security policy but, when an LSM is enabled, a denial audit > message was being generated. > > The denial audit message caused confusion for some application authors > because root-running Go applications always triggered the denial. To > prevent this confusion, the capability check in net_ctl_permissions() is > switched to the noaudit variant. > > BugLink: https://launchpad.net/bugs/1465724 > > Signed-off-by: Tyler Hicks <tyhicks@canonical.com> > Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Both applied to git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next -- James Morris <jmorris@namei.org>
[toc] | [prev] | [next] | [standalone]
| From | Tyler Hicks <tyhicks@canonical.com> |
|---|---|
| Date | 2016-06-03 06:50 +0200 |
| Subject | [PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable() |
| Message-ID | <rFPdv-73m-5@gated-at.bofh.it> |
| In reply to | #1412786 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web