mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH mmotm 1/3] userns: remove unneeded extra argument in selinux's task_has_capability
@ 2011-03-03  2:56 Serge E. Hallyn
  2011-03-03  2:57 ` [PATCH mmotm 2/3] userns: don't define init_user_ns in ipc_namespace.h Serge E. Hallyn
  2011-03-03  2:58 ` [PATCH mmotm 3/3] userns: make has_capability* into real functions Serge E. Hallyn
  0 siblings, 2 replies; 3+ messages in thread
From: Serge E. Hallyn @ 2011-03-03  2:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Stephen Smalley, Nathan Lynch, lkml, serge.hallyn

The user_namespace argument is not used by task_has_capability, so get
rid of it.  Note that it was spuriously added by the user namespace
patchset, so we're just cleaning up our own mess.

Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
---
 security/selinux/hooks.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Index: linux-2.6/security/selinux/hooks.c
===================================================================
--- linux-2.6.orig/security/selinux/hooks.c	2011-03-03 01:47:01.113745084 +0000
+++ linux-2.6/security/selinux/hooks.c	2011-03-03 01:47:48.017090039 +0000
@@ -1419,7 +1419,6 @@
 /* Check whether a task is allowed to use a capability. */
 static int task_has_capability(struct task_struct *tsk,
 			       const struct cred *cred,
-			       struct user_namespace *ns,
 			       int cap, int audit)
 {
 	struct common_audit_data ad;
@@ -1856,7 +1855,7 @@
 	if (rc)
 		return rc;
 
-	return task_has_capability(tsk, cred, ns, cap, audit);
+	return task_has_capability(tsk, cred, cap, audit);
 }
 
 static int selinux_quotactl(int cmds, int type, int id, struct super_block *sb)
@@ -2886,8 +2885,8 @@
 
 	case KDSKBENT:
 	case KDSKBSENT:
-		error = task_has_capability(current, cred, &init_user_ns,
-					CAP_SYS_TTY_CONFIG, SECURITY_CAP_AUDIT);
+		error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG,
+					SECURITY_CAP_AUDIT);
 		break;
 
 	/* default case assumes that the command will go

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

* [PATCH mmotm 2/3] userns: don't define init_user_ns in ipc_namespace.h
  2011-03-03  2:56 [PATCH mmotm 1/3] userns: remove unneeded extra argument in selinux's task_has_capability Serge E. Hallyn
@ 2011-03-03  2:57 ` Serge E. Hallyn
  2011-03-03  2:58 ` [PATCH mmotm 3/3] userns: make has_capability* into real functions Serge E. Hallyn
  1 sibling, 0 replies; 3+ messages in thread
From: Serge E. Hallyn @ 2011-03-03  2:57 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Stephen Smalley, Nathan Lynch, lkml, Serge E. Hallyn

It shouldn't be needed since ipc/msgutil.c includes security.h
which includes fs.h, which forward declares it.

---
 include/linux/ipc_namespace.h |    1 -
 1 file changed, 1 deletion(-)

Index: linux-2.6/include/linux/ipc_namespace.h
===================================================================
--- linux-2.6.orig/include/linux/ipc_namespace.h	2011-03-03 01:55:46.191177396 +0000
+++ linux-2.6/include/linux/ipc_namespace.h	2011-03-03 01:58:51.964414007 +0000
@@ -17,7 +17,6 @@
 #define IPCNS_CALLBACK_PRI 0
 
 struct user_namespace;
-extern struct user_namespace init_user_ns;
 
 struct ipc_ids {
 	int in_use;

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

* [PATCH mmotm 3/3] userns: make has_capability* into real functions
  2011-03-03  2:56 [PATCH mmotm 1/3] userns: remove unneeded extra argument in selinux's task_has_capability Serge E. Hallyn
  2011-03-03  2:57 ` [PATCH mmotm 2/3] userns: don't define init_user_ns in ipc_namespace.h Serge E. Hallyn
@ 2011-03-03  2:58 ` Serge E. Hallyn
  1 sibling, 0 replies; 3+ messages in thread
From: Serge E. Hallyn @ 2011-03-03  2:58 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Stephen Smalley, Nathan Lynch, lkml, Serge E. Hallyn

so we can let type safety keep things sane, and as a bonus we can
remove the declaration of init_user_ns in capability.h.

---
 include/linux/capability.h |   34 +++-----------------------
 kernel/capability.c        |   57 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 30 deletions(-)

Index: linux-2.6/include/linux/capability.h
===================================================================
--- linux-2.6.orig/include/linux/capability.h	2011-03-03 02:17:17.533467959 +0000
+++ linux-2.6/include/linux/capability.h	2011-03-03 02:26:56.524786760 +0000
@@ -371,8 +371,6 @@
 struct dentry;
 struct user_namespace;
 
-extern struct user_namespace init_user_ns;
-
 struct user_namespace *current_user_ns(void);
 
 extern const kernel_cap_t __cap_empty_set;
@@ -541,34 +539,10 @@
 			   cap_intersect(permitted, __cap_nfsd_set));
 }
 
-/**
- * has_capability - Determine if a task has a superior capability available
- * @t: The task in question
- * @cap: The capability to be tested for
- *
- * Return true if the specified task has the given superior capability
- * currently in effect, false if not.
- *
- * Note that this does not set PF_SUPERPRIV on the task.
- */
-#define has_capability(t, cap) (security_real_capable((t), &init_user_ns, (cap)) == 0)
-
-#define has_ns_capability(t, ns, cap) (security_real_capable((t), (ns), (cap)) == 0)
-
-/**
- * has_capability_noaudit - Determine if a task has a superior capability available (unaudited)
- * @t: The task in question
- * @cap: The capability to be tested for
- *
- * Return true if the specified task has the given superior capability
- * currently in effect, false if not, but don't write an audit message for the
- * check.
- *
- * Note that this does not set PF_SUPERPRIV on the task.
- */
-#define has_capability_noaudit(t, cap) \
-	(security_real_capable_noaudit((t), &init_user_ns, (cap)) == 0)
-
+extern bool has_capability(struct task_struct *t, int cap);
+extern bool has_ns_capability(struct task_struct *t,
+			      struct user_namespace *ns, int cap);
+extern bool has_capability_noaudit(struct task_struct *t, int cap);
 extern bool capable(int cap);
 extern bool ns_capable(struct user_namespace *ns, int cap);
 extern bool task_ns_capable(struct task_struct *t, int cap);
Index: linux-2.6/kernel/capability.c
===================================================================
--- linux-2.6.orig/kernel/capability.c	2011-03-03 02:17:17.523467247 +0000
+++ linux-2.6/kernel/capability.c	2011-03-03 02:52:11.652778780 +0000
@@ -291,6 +291,60 @@
 }
 
 /**
+ * has_capability - Does a task have a capability in init_user_ns
+ * @t: The task in question
+ * @cap: The capability to be tested for
+ *
+ * Return true if the specified task has the given superior capability
+ * currently in effect to the initial user namespace, false if not.
+ *
+ * Note that this does not set PF_SUPERPRIV on the task.
+ */
+bool has_capability(struct task_struct *t, int cap)
+{
+	int ret = security_real_capable(t, &init_user_ns, cap);
+
+	return (ret == 0);
+}
+
+/**
+ * has_capability - Does a task have a capability in a specific user ns
+ * @t: The task in question
+ * @ns: target user namespace
+ * @cap: The capability to be tested for
+ *
+ * Return true if the specified task has the given superior capability
+ * currently in effect to the specified user namespace, false if not.
+ *
+ * Note that this does not set PF_SUPERPRIV on the task.
+ */
+bool has_ns_capability(struct task_struct *t,
+		       struct user_namespace *ns, int cap)
+{
+	int ret = security_real_capable(t, ns, cap);
+
+	return (ret == 0);
+}
+
+/**
+ * has_capability_noaudit - Does a task have a capability (unaudited)
+ * @t: The task in question
+ * @cap: The capability to be tested for
+ *
+ * Return true if the specified task has the given superior capability
+ * currently in effect to init_user_ns, false if not.  Don't write an
+ * audit message for the check.
+ *
+ * Note that this does not set PF_SUPERPRIV on the task.
+ */
+bool has_capability_noaudit(struct task_struct *t, int cap)
+{
+	int ret = security_real_capable_noaudit(t, &init_user_ns, cap);
+
+	return (ret == 0);
+}
+
+/**
  * capable - Determine if the current task has a superior capability in effect
  * @cap: The capability to be tested for
  *

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

end of thread, other threads:[~2011-03-03  2:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-03  2:56 [PATCH mmotm 1/3] userns: remove unneeded extra argument in selinux's task_has_capability Serge E. Hallyn
2011-03-03  2:57 ` [PATCH mmotm 2/3] userns: don't define init_user_ns in ipc_namespace.h Serge E. Hallyn
2011-03-03  2:58 ` [PATCH mmotm 3/3] userns: make has_capability* into real functions Serge E. Hallyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®