lsm: smack: smack callbacks for kdbus security hooks
authorPaul Osmialowski <p.osmialowsk@samsung.com>
Tue, 23 Jun 2015 14:11:46 +0000 (16:11 +0200)
committerPaul Osmialowski <p.osmialowsk@samsung.com>
Thu, 9 Jul 2015 14:40:43 +0000 (16:40 +0200)
This adds implementation of three smack callbacks sitting behind kdbus
security hooks as proposed by Karol Lewandowski.

Originates from:

git://git.infradead.org/users/pcmoore/selinux (branch: working-kdbus)
commit: fc3505d058c001fe72a6f66b833e0be5b2d118f3

https://github.com/lmctl/linux.git (branch: kdbus-lsm-v4.for-systemd-v212)
commit: 103c26fd27d1ec8c32d85dd3d85681f936ac66fb

Change-Id: I8f850ffdc8f2a5f38abde47f2996b6ff8defdc1f
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
Signed-off-by: Paul Osmialowski <p.osmialowsk@samsung.com>
security/smack/smack_lsm.c

index bb3f6041552dac97b24523c683b77c5d7375b99e..9b7cecc427125243d073ba50bbbed8e0ee5fe739 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/msg.h>
 #include <linux/shm.h>
 #include <linux/binfmts.h>
+#include <kdbus/connection.h>
 #include "smack.h"
 
 #define TRANS_TRUE     "TRUE"
@@ -3303,6 +3304,69 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        return size;
 }
 
+/**
+ * smack_kdbus_connect - Set the security blob for a KDBus connection
+ * @conn: the connection
+ * @secctx: smack label
+ * @seclen: smack label length
+ *
+ * Returns 0
+ */
+static int smack_kdbus_connect(struct kdbus_conn *conn,
+                              const char *secctx, u32 seclen)
+{
+       struct smack_known *skp;
+
+       if (secctx && seclen > 0)
+               skp = smk_import_entry(secctx, seclen);
+       else
+               skp = smk_of_current();
+       conn->security = skp;
+
+       return 0;
+}
+
+/**
+ * smack_kdbus_conn_free - Clear the security blob for a KDBus connection
+ * @conn: the connection
+ *
+ * Clears the blob pointer
+ */
+static void smack_kdbus_conn_free(struct kdbus_conn *conn)
+{
+       conn->security = NULL;
+}
+
+/**
+ * smack_kdbus_talk - Smack access on KDBus
+ * @src: source kdbus connection
+ * @dst: destination kdbus connection
+ *
+ * Return 0 if a subject with the smack of sock could access
+ * an object with the smack of other, otherwise an error code
+ */
+static int smack_kdbus_talk(const struct kdbus_conn *src,
+                           const struct kdbus_conn *dst)
+{
+       struct smk_audit_info ad;
+       struct smack_known *sskp = src->security;
+       struct smack_known *dskp = dst->security;
+       int ret;
+
+       BUG_ON(sskp == NULL);
+       BUG_ON(dskp == NULL);
+
+       if (smack_privileged(CAP_MAC_OVERRIDE))
+               return 0;
+
+       smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NONE);
+
+       ret = smk_access(sskp, dskp, MAY_WRITE, &ad);
+       if (ret)
+               return ret;
+       return 0;
+}
+
 /**
  * smack_unix_stream_connect - Smack access on UDS
  * @sock: one sock
@@ -4290,6 +4354,10 @@ struct security_operations smack_ops = {
        .getprocattr =                  smack_getprocattr,
        .setprocattr =                  smack_setprocattr,
 
+       .kdbus_connect =                smack_kdbus_connect,
+       .kdbus_conn_free =              smack_kdbus_conn_free,
+       .kdbus_talk =                   smack_kdbus_talk,
+
        .unix_stream_connect =          smack_unix_stream_connect,
        .unix_may_send =                smack_unix_may_send,