linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl
@ 2016-06-03  4:43 Tyler Hicks
  2016-06-03  4:43 ` [PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks
  2016-06-03  4:43 ` [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks
  0 siblings, 2 replies; 4+ messages in thread
From: Tyler Hicks @ 2016-06-03  4:43 UTC (permalink / raw)
  To: James Morris; +Cc: linux-kernel, linux-security-module

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable()
  2016-06-03  4:43 [PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks
@ 2016-06-03  4:43 ` Tyler Hicks
  2016-06-03  4:43 ` [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks
  1 sibling, 0 replies; 4+ messages in thread
From: Tyler Hicks @ 2016-06-03  4:43 UTC (permalink / raw)
  To: James Morris; +Cc: linux-kernel, linux-security-module

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions
  2016-06-03  4:43 [PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks
  2016-06-03  4:43 ` [PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks
@ 2016-06-03  4:43 ` Tyler Hicks
  2016-06-06  9:51   ` James Morris
  1 sibling, 1 reply; 4+ messages in thread
From: Tyler Hicks @ 2016-06-03  4:43 UTC (permalink / raw)
  To: James Morris; +Cc: linux-kernel, linux-security-module

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions
  2016-06-03  4:43 ` [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks
@ 2016-06-06  9:51   ` James Morris
  0 siblings, 0 replies; 4+ messages in thread
From: James Morris @ 2016-06-06  9:51 UTC (permalink / raw)
  To: Tyler Hicks; +Cc: linux-kernel, linux-security-module

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-06  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03  4:43 [PATCH RESEND 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks
2016-06-03  4:43 ` [PATCH RESEND 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks
2016-06-03  4:43 ` [PATCH RESEND 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks
2016-06-06  9:51   ` James Morris

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).