Skip to contentSkip to conversation

LSM: Infrastructure management of the sock security

PATCH In review Casey Schaufler 3 participants 13 messages Jul 10, 2024 – Jul 29, 2024 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Casey Schaufler

author maintainer
#1 lore raw

v2 cover LSM: Infrastructure blob allocation

When more than one Linux Security Module (LSM) can use the security blob for a partincular object the management of the memory associated with that blob needs to be done by the infrastructure rather than the individual modules. Until now, this has been done on an as needed basis, with the blob management remaining in the modules until such time as a new configuration of modules requires sharing the blob. This piecemeal approach makes adding new modules that use blobs more difficult, as moving the blob management to the infrastructure isn't as simple as it might seem. This patch set moves management of the security blobs that is done in the modules into the infrastructure. Making security blob management more consistant improves mantainablity and makes the possibilty of general improvement of LSM blob managment easier.

No effort has been put into pursuing the possible performance optimizations these changes introduce. For example, sk_security blobs might be moved to use kmem_zone_alloc(). The option of changing the blob sizes to being compile time determined rather than calculated at run time has been considered for future exploration.

In the cases where infrastructure blob freeing no longer requires any special action on the part of any security module the hook definition has been removed as it is no long necessary.

Security blobs for the xfrm subsystem are problematic as the only security module that implements them (SELinux) has a variable size blob that has a published external API. Management of these blobs by the infrastructure will require significant consideration and negotiation with the maintainers of the existing code. This has been deferred until such time as another user of xfrm appears.

Casey Schaufler (6):
LSM: Infrastructure management of the sock security
LSM: Infrastructure management of the key security blob
LSM: Add helper for blob allocations
LSM: Infrastructure management of the dev_tun blob
LSM: Infrastructure management of the infiniband blob
LSM: Infrastructure management of the perf_event security blob

 include/linux/lsm_hook_defs.h     |   8 +-
 include/linux/lsm_hooks.h         |   5 +
 security/apparmor/include/net.h   |   3 +-
 security/apparmor/lsm.c           |  17 +--
 security/apparmor/net.c           |   2 +-
 security/security.c               | 184 +++++++++++++++++++++---------
 security/selinux/hooks.c          | 157 +++++++++----------------
 security/selinux/include/objsec.h |  30 +++++
 security/selinux/netlabel.c       |  23 ++--
 security/smack/smack.h            |  12 ++
 security/smack/smack_lsm.c        | 101 ++++++++--------
 security/smack/smack_netfilter.c  |   4 +-
 12 files changed, 298 insertions(+), 248 deletions(-)
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH v2 1/6 LSM: Infrastructure management of the sock security

Move management of the sock->sk_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there.

---
 include/linux/lsm_hooks.h         |  1 +
 security/apparmor/include/net.h   |  3 +-
 security/apparmor/lsm.c           | 17 +------
 security/apparmor/net.c           |  2 +-
 security/security.c               | 36 +++++++++++++-
 security/selinux/hooks.c          | 80 ++++++++++++++-----------------
 security/selinux/include/objsec.h |  5 ++
 security/selinux/netlabel.c       | 23 ++++-----
 security/smack/smack.h            |  5 ++
 security/smack/smack_lsm.c        | 70 +++++++++++++--------------
 security/smack/smack_netfilter.c  |  4 +-
 11 files changed, 133 insertions(+), 113 deletions(-)
include/linux/lsm_hooks.h +1 -0
index a2ade0ffe9e7..efd4a0655159 100644
@@ -73,6 +73,7 @@ struct lsm_blob_sizes {
 	int	lbs_cred;
 	int	lbs_file;
 	int	lbs_inode;
+	int	lbs_sock;
 	int	lbs_superblock;
 	int	lbs_ipc;
 	int	lbs_msg_msg;
security/apparmor/include/net.h +1 -2
index 67bf888c3bd6..c42ed8a73f1c 100644
@@ -51,10 +51,9 @@ struct aa_sk_ctx {
 	struct aa_label *peer;
 };
 
-#define SK_CTX(X) ((X)->sk_security)
 static inline struct aa_sk_ctx *aa_sock(const struct sock *sk)
 {
-	return sk->sk_security;
+	return sk->sk_security + apparmor_blob_sizes.lbs_sock;
 }
 
 #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P)				  \
security/apparmor/lsm.c +1 -16
index 6239777090c4..b3eb0a2f999a 100644
@@ -1057,27 +1057,12 @@ static int apparmor_userns_create(const struct cred *cred)
 	return error;
 }
 
-static int apparmor_sk_alloc_security(struct sock *sk, int family, gfp_t flags)
-{
-	struct aa_sk_ctx *ctx;
-
-	ctx = kzalloc(sizeof(*ctx), flags);
-	if (!ctx)
-		return -ENOMEM;
-
-	sk->sk_security = ctx;
-
-	return 0;
-}
-
 static void apparmor_sk_free_security(struct sock *sk)
 {
 	struct aa_sk_ctx *ctx = aa_sock(sk);
 
-	sk->sk_security = NULL;
 	aa_put_label(ctx->label);
 	aa_put_label(ctx->peer);
-	kfree(ctx);
 }
 
 /**
@@ -1425,6 +1410,7 @@ struct lsm_blob_sizes apparmor_blob_sizes __ro_after_init = {
 	.lbs_cred = sizeof(struct aa_label *),
 	.lbs_file = sizeof(struct aa_file_ctx),
 	.lbs_task = sizeof(struct aa_task_ctx),
+	.lbs_sock = sizeof(struct aa_sk_ctx),
 };
 
 static const struct lsm_id apparmor_lsmid = {
@@ -1470,7 +1456,6 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(getprocattr, apparmor_getprocattr),
 	LSM_HOOK_INIT(setprocattr, apparmor_setprocattr),
 
-	LSM_HOOK_INIT(sk_alloc_security, apparmor_sk_alloc_security),
 	LSM_HOOK_INIT(sk_free_security, apparmor_sk_free_security),
 	LSM_HOOK_INIT(sk_clone_security, apparmor_sk_clone_security),
 
security/apparmor/net.c +1 -1
index 87e934b2b548..77413a519117 100644
@@ -151,7 +151,7 @@ static int aa_label_sk_perm(const struct cred *subj_cred,
 			    const char *op, u32 request,
 			    struct sock *sk)
 {
-	struct aa_sk_ctx *ctx = SK_CTX(sk);
+	struct aa_sk_ctx *ctx = aa_sock(sk);
 	int error = 0;
 
 	AA_BUG(!label);
security/security.c +35 -1
index e5ca08789f74..5e93a72bdca6 100644
@@ -29,6 +29,7 @@
 #include <linux/msg.h>
 #include <linux/overflow.h>
 #include <net/flow.h>
+#include <net/sock.h>
 
 /* How many LSMs were built into the kernel? */
 #define LSM_COUNT (__end_lsm_info - __start_lsm_info)
@@ -227,6 +228,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 	lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
 	lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
 	lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
+	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
 	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
 	lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
 	lsm_set_blob_size(&needed->lbs_xattr_count,
@@ -401,6 +403,7 @@ static void __init ordered_lsm_init(void)
 	init_debug("inode blob size      = %d\n", blob_sizes.lbs_inode);
 	init_debug("ipc blob size        = %d\n", blob_sizes.lbs_ipc);
 	init_debug("msg_msg blob size    = %d\n", blob_sizes.lbs_msg_msg);
+	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
 	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
 	init_debug("task blob size       = %d\n", blob_sizes.lbs_task);
 	init_debug("xattr slots          = %d\n", blob_sizes.lbs_xattr_count);
@@ -4647,6 +4650,28 @@ int security_socket_getpeersec_dgram(struct socket *sock,
 }
 EXPORT_SYMBOL(security_socket_getpeersec_dgram);
 
+/**
+ * lsm_sock_alloc - allocate a composite sock blob
+ * @sock: the sock that needs a blob
+ * @priority: allocation mode
+ *
+ * Allocate the sock blob for all the modules
+ *
+ * Returns 0, or -ENOMEM if memory can't be allocated.
+ */
+static int lsm_sock_alloc(struct sock *sock, gfp_t priority)
+{
+	if (blob_sizes.lbs_sock == 0) {
+		sock->sk_security = NULL;
+		return 0;
+	}
+
+	sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority);
+	if (sock->sk_security == NULL)
+		return -ENOMEM;
+	return 0;
+}
+
 /**
  * security_sk_alloc() - Allocate and initialize a sock's LSM blob
  * @sk: sock
@@ -4660,7 +4685,14 @@ EXPORT_SYMBOL(security_socket_getpeersec_dgram);
  */
 int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
 {
-	return call_int_hook(sk_alloc_security, sk, family, priority);
+	int rc = lsm_sock_alloc(sk, priority);
+
+	if (unlikely(rc))
+		return rc;
+	rc = call_int_hook(sk_alloc_security, sk, family, priority);
+	if (unlikely(rc))
+		security_sk_free(sk);
+	return rc;
 }
 
 /**
@@ -4672,6 +4704,8 @@ int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
 void security_sk_free(struct sock *sk)
 {
 	call_void_hook(sk_free_security, sk);
+	kfree(sk->sk_security);
+	sk->sk_security = NULL;
 }
 
 /**
security/selinux/hooks.c +37 -43

265 lines not on this page · raw message

security/selinux/include/objsec.h +5 -0
index dea1d6f3ed2d..b074099acbaf 100644
@@ -195,4 +195,9 @@ selinux_superblock(const struct super_block *superblock)
 	return superblock->s_security + selinux_blob_sizes.lbs_superblock;
 }
 
+static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
+{
+	return sock->sk_security + selinux_blob_sizes.lbs_sock;
+}
+
 #endif /* _SELINUX_OBJSEC_H_ */
security/selinux/netlabel.c +12 -11
index 55885634e880..fbe5f8c29f81 100644
@@ -17,6 +17,7 @@
 #include <linux/gfp.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
+#include <linux/lsm_hooks.h>
 #include <net/sock.h>
 #include <net/netlabel.h>
 #include <net/ip.h>
@@ -68,7 +69,7 @@ static int selinux_netlbl_sidlookup_cached(struct sk_buff *skb,
 static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
 {
 	int rc;
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 	struct netlbl_lsm_secattr *secattr;
 
 	if (sksec->nlbl_secattr != NULL)
@@ -100,7 +101,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(
 							const struct sock *sk,
 							u32 sid)
 {
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 	struct netlbl_lsm_secattr *secattr = sksec->nlbl_secattr;
 
 	if (secattr == NULL)
@@ -240,7 +241,7 @@ int selinux_netlbl_skbuff_setsid(struct sk_buff *skb,
 	 * being labeled by it's parent socket, if it is just exit */
 	sk = skb_to_full_sk(skb);
 	if (sk != NULL) {
-		struct sk_security_struct *sksec = sk->sk_security;
+		struct sk_security_struct *sksec = selinux_sock(sk);
 
 		if (sksec->nlbl_state != NLBL_REQSKB)
 			return 0;
@@ -277,7 +278,7 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_association *asoc,
 {
 	int rc;
 	struct netlbl_lsm_secattr secattr;
-	struct sk_security_struct *sksec = asoc->base.sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(asoc->base.sk);
 	struct sockaddr_in addr4;
 	struct sockaddr_in6 addr6;
 
@@ -356,7 +357,7 @@ int selinux_netlbl_inet_conn_request(struct request_sock *req, u16 family)
  */
 void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
 {
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 
 	if (family == PF_INET)
 		sksec->nlbl_state = NLBL_LABELED;
@@ -374,8 +375,8 @@ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
  */
 void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk)
 {
-	struct sk_security_struct *sksec = sk->sk_security;
-	struct sk_security_struct *newsksec = newsk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
+	struct sk_security_struct *newsksec = selinux_sock(newsk);
 
 	newsksec->nlbl_state = sksec->nlbl_state;
 }
@@ -393,7 +394,7 @@ void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk)
 int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)
 {
 	int rc;
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 	struct netlbl_lsm_secattr *secattr;
 
 	if (family != PF_INET && family != PF_INET6)
@@ -510,7 +511,7 @@ int selinux_netlbl_socket_setsockopt(struct socket *sock,
 {
 	int rc = 0;
 	struct sock *sk = sock->sk;
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 	struct netlbl_lsm_secattr secattr;
 
 	if (selinux_netlbl_option(level, optname) &&
@@ -548,7 +549,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk,
 						struct sockaddr *addr)
 {
 	int rc;
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 	struct netlbl_lsm_secattr *secattr;
 
 	/* connected sockets are allowed to disconnect when the address family
@@ -587,7 +588,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk,
 int selinux_netlbl_socket_connect_locked(struct sock *sk,
 					 struct sockaddr *addr)
 {
-	struct sk_security_struct *sksec = sk->sk_security;
+	struct sk_security_struct *sksec = selinux_sock(sk);
 
 	if (sksec->nlbl_state != NLBL_REQSKB &&
 	    sksec->nlbl_state != NLBL_CONNLABELED)
security/smack/smack.h +5 -0
index 041688e5a77a..297f21446f45 100644
@@ -355,6 +355,11 @@ static inline struct superblock_smack *smack_superblock(
 	return superblock->s_security + smack_blob_sizes.lbs_superblock;
 }
 
+static inline struct socket_smack *smack_sock(const struct sock *sock)
+{
+	return sock->sk_security + smack_blob_sizes.lbs_sock;
+}
+
 /*
  * Is the directory transmuting?
  */
security/smack/smack_lsm.c +33 -37

243 lines not on this page · raw message

security/smack/smack_netfilter.c +2 -2
index b945c1d3a743..bad71b7e648d 100644
@@ -26,8 +26,8 @@ static unsigned int smack_ip_output(void *priv,
 	struct socket_smack *ssp;
 	struct smack_known *skp;
 
-	if (sk && sk->sk_security) {
-		ssp = sk->sk_security;
+	if (sk) {
+		ssp = smack_sock(sk);
 		skp = ssp->smk_out;
 		skb->secmark = skp->smk_secid;
 	}
Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH v2 2/6 LSM: Infrastructure management of the key security blob

In reply to Casey Schaufler

Move management of the key->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. There are no existing modules that require a key_free hook, so the call to it and the definition for it have been removed.

---
 include/linux/lsm_hook_defs.h     |  1 -
 include/linux/lsm_hooks.h         |  1 +
 security/security.c               | 39 +++++++++++++++++++++++++++++--
 security/selinux/hooks.c          | 21 ++++-------------
 security/selinux/include/objsec.h |  7 ++++++
 security/smack/smack.h            |  7 ++++++
 security/smack/smack_lsm.c        | 31 +++++++++++-------------
 7 files changed, 69 insertions(+), 38 deletions(-)
include/linux/lsm_hook_defs.h +0 -1
index 44488b1ab9a9..cc81f7f7c024 100644
@@ -402,7 +402,6 @@ LSM_HOOK(int, 0, xfrm_decode_session, struct sk_buff *skb, u32 *secid,
 #ifdef CONFIG_KEYS
 LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred,
 	 unsigned long flags)
-LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key)
 LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred,
 	 enum key_need_perm need_perm)
 LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **buffer)
include/linux/lsm_hooks.h +1 -0
index efd4a0655159..7233bc0737be 100644
@@ -76,6 +76,7 @@ struct lsm_blob_sizes {
 	int	lbs_sock;
 	int	lbs_superblock;
 	int	lbs_ipc;
+	int	lbs_key;
 	int	lbs_msg_msg;
 	int	lbs_task;
 	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
security/security.c +37 -2
index 5e93a72bdca6..92068ebd7e2b 100644
@@ -227,6 +227,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 		blob_sizes.lbs_inode = sizeof(struct rcu_head);
 	lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
 	lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
+	lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key);
 	lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
 	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
 	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
@@ -402,6 +403,9 @@ static void __init ordered_lsm_init(void)
 	init_debug("file blob size       = %d\n", blob_sizes.lbs_file);
 	init_debug("inode blob size      = %d\n", blob_sizes.lbs_inode);
 	init_debug("ipc blob size        = %d\n", blob_sizes.lbs_ipc);
+#ifdef CONFIG_KEYS
+	init_debug("key blob size        = %d\n", blob_sizes.lbs_key);
+#endif /* CONFIG_KEYS */
 	init_debug("msg_msg blob size    = %d\n", blob_sizes.lbs_msg_msg);
 	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
 	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
@@ -718,6 +722,29 @@ static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
 	return 0;
 }
 
+#ifdef CONFIG_KEYS
+/**
+ * lsm_key_alloc - allocate a composite key blob
+ * @key: the key that needs a blob
+ *
+ * Allocate the key blob for all the modules
+ *
+ * Returns 0, or -ENOMEM if memory can't be allocated.
+ */
+static int lsm_key_alloc(struct key *key)
+{
+	if (blob_sizes.lbs_key == 0) {
+		key->security = NULL;
+		return 0;
+	}
+
+	key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL);
+	if (key->security == NULL)
+		return -ENOMEM;
+	return 0;
+}
+#endif /* CONFIG_KEYS */
+
 /**
  * lsm_msg_msg_alloc - allocate a composite msg_msg blob
  * @mp: the msg_msg that needs a blob
@@ -5290,7 +5317,14 @@ EXPORT_SYMBOL(security_skb_classify_flow);
 int security_key_alloc(struct key *key, const struct cred *cred,
 		       unsigned long flags)
 {
-	return call_int_hook(key_alloc, key, cred, flags);
+	int rc = lsm_key_alloc(key);
+
+	if (unlikely(rc))
+		return rc;
+	rc = call_int_hook(key_alloc, key, cred, flags);
+	if (unlikely(rc))
+		security_key_free(key);
+	return rc;
 }
 
 /**
@@ -5301,7 +5335,8 @@ int security_key_alloc(struct key *key, const struct cred *cred,
  */
 void security_key_free(struct key *key)
 {
-	call_void_hook(key_free, key);
+	kfree(key->security);
+	key->security = NULL;
 }
 
 /**
security/selinux/hooks.c +4 -17
index 19346e1817ff..986825ba1cc5 100644
@@ -6658,11 +6658,7 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred,
 			     unsigned long flags)
 {
 	const struct task_security_struct *tsec;
-	struct key_security_struct *ksec;
-
-	ksec = kzalloc(sizeof(struct key_security_struct), GFP_KERNEL);
-	if (!ksec)
-		return -ENOMEM;
+	struct key_security_struct *ksec = selinux_key(k);
 
 	tsec = selinux_cred(cred);
 	if (tsec->keycreate_sid)
@@ -6670,18 +6666,9 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred,
 	else
 		ksec->sid = tsec->sid;
 
-	k->security = ksec;
 	return 0;
 }
 
-static void selinux_key_free(struct key *k)
-{
-	struct key_security_struct *ksec = k->security;
-
-	k->security = NULL;
-	kfree(ksec);
-}
-
 static int selinux_key_permission(key_ref_t key_ref,
 				  const struct cred *cred,
 				  enum key_need_perm need_perm)
@@ -6722,14 +6709,14 @@ static int selinux_key_permission(key_ref_t key_ref,
 
 	sid = cred_sid(cred);
 	key = key_ref_to_ptr(key_ref);
-	ksec = key->security;
+	ksec = selinux_key(key);
 
 	return avc_has_perm(sid, ksec->sid, SECCLASS_KEY, perm, NULL);
 }
 
 static int selinux_key_getsecurity(struct key *key, char **_buffer)
 {
-	struct key_security_struct *ksec = key->security;
+	struct key_security_struct *ksec = selinux_key(key);
 	char *context = NULL;
 	unsigned len;
 	int rc;
@@ -6981,6 +6968,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
 	.lbs_file = sizeof(struct file_security_struct),
 	.lbs_inode = sizeof(struct inode_security_struct),
 	.lbs_ipc = sizeof(struct ipc_security_struct),
+	.lbs_key = sizeof(struct key_security_struct),
 	.lbs_msg_msg = sizeof(struct msg_security_struct),
 	.lbs_sock = sizeof(struct sk_security_struct),
 	.lbs_superblock = sizeof(struct superblock_security_struct),
@@ -7318,7 +7306,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 #endif
 
 #ifdef CONFIG_KEYS
-	LSM_HOOK_INIT(key_free, selinux_key_free),
 	LSM_HOOK_INIT(key_permission, selinux_key_permission),
 	LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity),
 #ifdef CONFIG_KEY_NOTIFICATIONS
security/selinux/include/objsec.h +7 -0
index b074099acbaf..83b9443d6919 100644
@@ -195,6 +195,13 @@ selinux_superblock(const struct super_block *superblock)
 	return superblock->s_security + selinux_blob_sizes.lbs_superblock;
 }
 
+#ifdef CONFIG_KEYS
+static inline struct key_security_struct *selinux_key(const struct key *key)
+{
+	return key->security + selinux_blob_sizes.lbs_key;
+}
+#endif /* CONFIG_KEYS */
+
 static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
 {
 	return sock->sk_security + selinux_blob_sizes.lbs_sock;
security/smack/smack.h +7 -0
index 297f21446f45..dbf8d7226eb5 100644
@@ -360,6 +360,13 @@ static inline struct socket_smack *smack_sock(const struct sock *sock)
 	return sock->sk_security + smack_blob_sizes.lbs_sock;
 }
 
+#ifdef CONFIG_KEYS
+static inline struct smack_known **smack_key(const struct key *key)
+{
+	return key->security + smack_blob_sizes.lbs_key;
+}
+#endif /* CONFIG_KEYS */
+
 /*
  * Is the directory transmuting?
  */
security/smack/smack_lsm.c +13 -18
index a931b44bc959..c57eacf1d3b1 100644
@@ -4473,23 +4473,13 @@ static void smack_inet_csk_clone(struct sock *sk,
 static int smack_key_alloc(struct key *key, const struct cred *cred,
 			   unsigned long flags)
 {
+	struct smack_known **blob = smack_key(key);
 	struct smack_known *skp = smk_of_task(smack_cred(cred));
 
-	key->security = skp;
+	*blob = skp;
 	return 0;
 }
 
-/**
- * smack_key_free - Clear the key security blob
- * @key: the object
- *
- * Clear the blob pointer
- */
-static void smack_key_free(struct key *key)
-{
-	key->security = NULL;
-}
-
 /**
  * smack_key_permission - Smack access on a key
  * @key_ref: gets to the object
@@ -4503,6 +4493,8 @@ static int smack_key_permission(key_ref_t key_ref,
 				const struct cred *cred,
 				enum key_need_perm need_perm)
 {
+	struct smack_known **blob;
+	struct smack_known *skp;
 	struct key *keyp;
 	struct smk_audit_info ad;
 	struct smack_known *tkp = smk_of_task(smack_cred(cred));
@@ -4540,7 +4532,9 @@ static int smack_key_permission(key_ref_t key_ref,
 	 * If the key hasn't been initialized give it access so that
 	 * it may do so.
 	 */
-	if (keyp->security == NULL)
+	blob = smack_key(keyp);
+	skp = *blob;
+	if (skp == NULL)
 		return 0;
 	/*
 	 * This should not occur
@@ -4556,8 +4550,8 @@ static int smack_key_permission(key_ref_t key_ref,
 	ad.a.u.key_struct.key = keyp->serial;
 	ad.a.u.key_struct.key_desc = keyp->description;
 #endif
-	rc = smk_access(tkp, keyp->security, request, &ad);
-	rc = smk_bu_note("key access", tkp, keyp->security, request, rc);
+	rc = smk_access(tkp, skp, request, &ad);
+	rc = smk_bu_note("key access", tkp, skp, request, rc);
 	return rc;
 }
 
@@ -4572,11 +4566,12 @@ static int smack_key_permission(key_ref_t key_ref,
  */
 static int smack_key_getsecurity(struct key *key, char **_buffer)
 {
-	struct smack_known *skp = key->security;
+	struct smack_known **blob = smack_key(key);
+	struct smack_known *skp = *blob;
 	size_t length;
 	char *copy;
 
-	if (key->security == NULL) {
+	if (skp == NULL) {
 		*_buffer = NULL;
 		return 0;
 	}
@@ -5010,6 +5005,7 @@ struct lsm_blob_sizes smack_blob_sizes __ro_after_init = {
 	.lbs_file = sizeof(struct smack_known *),
 	.lbs_inode = sizeof(struct inode_smack),
 	.lbs_ipc = sizeof(struct smack_known *),
+	.lbs_key = sizeof(struct smack_known *),
 	.lbs_msg_msg = sizeof(struct smack_known *),
 	.lbs_sock = sizeof(struct socket_smack),
 	.lbs_superblock = sizeof(struct superblock_smack),
@@ -5146,7 +5142,6 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
  /* key management security hooks */
 #ifdef CONFIG_KEYS
 	LSM_HOOK_INIT(key_alloc, smack_key_alloc),
-	LSM_HOOK_INIT(key_free, smack_key_free),
 	LSM_HOOK_INIT(key_permission, smack_key_permission),
 	LSM_HOOK_INIT(key_getsecurity, smack_key_getsecurity),
 #ifdef CONFIG_KEY_NOTIFICATIONS
Signature · 1 line
2.45.2
maintainer Reviewed-by on v2 2/6
#4 lore raw

Re: [PATCH v2 2/6] LSM: Infrastructure management of the key security blob

Quoted 8 lines · Casey Schaufler

Move management of the key->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. There are no existing modules that require a key_free hook, so the call to it and the definition for it have been removed.

looks good

Quoted 309 lines
---
  include/linux/lsm_hook_defs.h     |  1 -
  include/linux/lsm_hooks.h         |  1 +
  security/security.c               | 39 +++++++++++++++++++++++++++++--
  security/selinux/hooks.c          | 21 ++++-------------
  security/selinux/include/objsec.h |  7 ++++++
  security/smack/smack.h            |  7 ++++++
  security/smack/smack_lsm.c        | 31 +++++++++++-------------
  7 files changed, 69 insertions(+), 38 deletions(-)
include/linux/lsm_hook_defs.h +0 -1
index 44488b1ab9a9..cc81f7f7c024 100644
@@ -402,7 +402,6 @@ LSM_HOOK(int, 0, xfrm_decode_session, struct sk_buff *skb, u32 *secid,
  #ifdef CONFIG_KEYS
  LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred,
  	 unsigned long flags)
-LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key)
  LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred,
  	 enum key_need_perm need_perm)
  LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **buffer)
include/linux/lsm_hooks.h +1 -0
index efd4a0655159..7233bc0737be 100644
@@ -76,6 +76,7 @@ struct lsm_blob_sizes {
  	int	lbs_sock;
  	int	lbs_superblock;
  	int	lbs_ipc;
+	int	lbs_key;
  	int	lbs_msg_msg;
  	int	lbs_task;
  	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
security/security.c +37 -2
index 5e93a72bdca6..92068ebd7e2b 100644
@@ -227,6 +227,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
  		blob_sizes.lbs_inode = sizeof(struct rcu_head);
  	lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
  	lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
+	lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key);
  	lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
  	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
  	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
@@ -402,6 +403,9 @@ static void __init ordered_lsm_init(void)
  	init_debug("file blob size       = %d\n", blob_sizes.lbs_file);
  	init_debug("inode blob size      = %d\n", blob_sizes.lbs_inode);
  	init_debug("ipc blob size        = %d\n", blob_sizes.lbs_ipc);
+#ifdef CONFIG_KEYS
+	init_debug("key blob size        = %d\n", blob_sizes.lbs_key);
+#endif /* CONFIG_KEYS */
  	init_debug("msg_msg blob size    = %d\n", blob_sizes.lbs_msg_msg);
  	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
  	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
@@ -718,6 +722,29 @@ static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
  	return 0;
  }
 
+#ifdef CONFIG_KEYS
+/**
+ * lsm_key_alloc - allocate a composite key blob
+ * @key: the key that needs a blob
+ *
+ * Allocate the key blob for all the modules
+ *
+ * Returns 0, or -ENOMEM if memory can't be allocated.
+ */
+static int lsm_key_alloc(struct key *key)
+{
+	if (blob_sizes.lbs_key == 0) {
+		key->security = NULL;
+		return 0;
+	}
+
+	key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL);
+	if (key->security == NULL)
+		return -ENOMEM;
+	return 0;
+}
+#endif /* CONFIG_KEYS */
+
  /**
   * lsm_msg_msg_alloc - allocate a composite msg_msg blob
   * @mp: the msg_msg that needs a blob
@@ -5290,7 +5317,14 @@ EXPORT_SYMBOL(security_skb_classify_flow);
  int security_key_alloc(struct key *key, const struct cred *cred,
  		       unsigned long flags)
  {
-	return call_int_hook(key_alloc, key, cred, flags);
+	int rc = lsm_key_alloc(key);
+
+	if (unlikely(rc))
+		return rc;
+	rc = call_int_hook(key_alloc, key, cred, flags);
+	if (unlikely(rc))
+		security_key_free(key);
+	return rc;
  }
 
  /**
@@ -5301,7 +5335,8 @@ int security_key_alloc(struct key *key, const struct cred *cred,
   */
  void security_key_free(struct key *key)
  {
-	call_void_hook(key_free, key);
+	kfree(key->security);
+	key->security = NULL;
  }
 
  /**
security/selinux/hooks.c +4 -17
index 19346e1817ff..986825ba1cc5 100644
@@ -6658,11 +6658,7 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred,
  			     unsigned long flags)
  {
  	const struct task_security_struct *tsec;
-	struct key_security_struct *ksec;
-
-	ksec = kzalloc(sizeof(struct key_security_struct), GFP_KERNEL);
-	if (!ksec)
-		return -ENOMEM;
+	struct key_security_struct *ksec = selinux_key(k);
 
  	tsec = selinux_cred(cred);
  	if (tsec->keycreate_sid)
@@ -6670,18 +6666,9 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred,
  	else
  		ksec->sid = tsec->sid;
 
-	k->security = ksec;
  	return 0;
  }
 
-static void selinux_key_free(struct key *k)
-{
-	struct key_security_struct *ksec = k->security;
-
-	k->security = NULL;
-	kfree(ksec);
-}
-
  static int selinux_key_permission(key_ref_t key_ref,
  				  const struct cred *cred,
  				  enum key_need_perm need_perm)
@@ -6722,14 +6709,14 @@ static int selinux_key_permission(key_ref_t key_ref,
 
  	sid = cred_sid(cred);
  	key = key_ref_to_ptr(key_ref);
-	ksec = key->security;
+	ksec = selinux_key(key);
 
  	return avc_has_perm(sid, ksec->sid, SECCLASS_KEY, perm, NULL);
  }
 
  static int selinux_key_getsecurity(struct key *key, char **_buffer)
  {
-	struct key_security_struct *ksec = key->security;
+	struct key_security_struct *ksec = selinux_key(key);
  	char *context = NULL;
  	unsigned len;
  	int rc;
@@ -6981,6 +6968,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
  	.lbs_file = sizeof(struct file_security_struct),
  	.lbs_inode = sizeof(struct inode_security_struct),
  	.lbs_ipc = sizeof(struct ipc_security_struct),
+	.lbs_key = sizeof(struct key_security_struct),
  	.lbs_msg_msg = sizeof(struct msg_security_struct),
  	.lbs_sock = sizeof(struct sk_security_struct),
  	.lbs_superblock = sizeof(struct superblock_security_struct),
@@ -7318,7 +7306,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
  #endif
 
  #ifdef CONFIG_KEYS
-	LSM_HOOK_INIT(key_free, selinux_key_free),
  	LSM_HOOK_INIT(key_permission, selinux_key_permission),
  	LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity),
  #ifdef CONFIG_KEY_NOTIFICATIONS
security/selinux/include/objsec.h +7 -0
index b074099acbaf..83b9443d6919 100644
@@ -195,6 +195,13 @@ selinux_superblock(const struct super_block *superblock)
  	return superblock->s_security + selinux_blob_sizes.lbs_superblock;
  }
 
+#ifdef CONFIG_KEYS
+static inline struct key_security_struct *selinux_key(const struct key *key)
+{
+	return key->security + selinux_blob_sizes.lbs_key;
+}
+#endif /* CONFIG_KEYS */
+
  static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
  {
  	return sock->sk_security + selinux_blob_sizes.lbs_sock;
security/smack/smack.h +7 -0
index 297f21446f45..dbf8d7226eb5 100644
@@ -360,6 +360,13 @@ static inline struct socket_smack *smack_sock(const struct sock *sock)
  	return sock->sk_security + smack_blob_sizes.lbs_sock;
  }
 
+#ifdef CONFIG_KEYS
+static inline struct smack_known **smack_key(const struct key *key)
+{
+	return key->security + smack_blob_sizes.lbs_key;
+}
+#endif /* CONFIG_KEYS */
+
  /*
   * Is the directory transmuting?
   */
security/smack/smack_lsm.c +13 -18
index a931b44bc959..c57eacf1d3b1 100644
@@ -4473,23 +4473,13 @@ static void smack_inet_csk_clone(struct sock *sk,
  static int smack_key_alloc(struct key *key, const struct cred *cred,
  			   unsigned long flags)
  {
+	struct smack_known **blob = smack_key(key);
  	struct smack_known *skp = smk_of_task(smack_cred(cred));
 
-	key->security = skp;
+	*blob = skp;
  	return 0;
  }
 
-/**
- * smack_key_free - Clear the key security blob
- * @key: the object
- *
- * Clear the blob pointer
- */
-static void smack_key_free(struct key *key)
-{
-	key->security = NULL;
-}
-
  /**
   * smack_key_permission - Smack access on a key
   * @key_ref: gets to the object
@@ -4503,6 +4493,8 @@ static int smack_key_permission(key_ref_t key_ref,
  				const struct cred *cred,
  				enum key_need_perm need_perm)
  {
+	struct smack_known **blob;
+	struct smack_known *skp;
  	struct key *keyp;
  	struct smk_audit_info ad;
  	struct smack_known *tkp = smk_of_task(smack_cred(cred));
@@ -4540,7 +4532,9 @@ static int smack_key_permission(key_ref_t key_ref,
  	 * If the key hasn't been initialized give it access so that
  	 * it may do so.
  	 */
-	if (keyp->security == NULL)
+	blob = smack_key(keyp);
+	skp = *blob;
+	if (skp == NULL)
  		return 0;
  	/*
  	 * This should not occur
@@ -4556,8 +4550,8 @@ static int smack_key_permission(key_ref_t key_ref,
  	ad.a.u.key_struct.key = keyp->serial;
  	ad.a.u.key_struct.key_desc = keyp->description;
  #endif
-	rc = smk_access(tkp, keyp->security, request, &ad);
-	rc = smk_bu_note("key access", tkp, keyp->security, request, rc);
+	rc = smk_access(tkp, skp, request, &ad);
+	rc = smk_bu_note("key access", tkp, skp, request, rc);
  	return rc;
  }
 
@@ -4572,11 +4566,12 @@ static int smack_key_permission(key_ref_t key_ref,
   */
  static int smack_key_getsecurity(struct key *key, char **_buffer)
  {
-	struct smack_known *skp = key->security;
+	struct smack_known **blob = smack_key(key);
+	struct smack_known *skp = *blob;
  	size_t length;
  	char *copy;
 
-	if (key->security == NULL) {
+	if (skp == NULL) {
  		*_buffer = NULL;
  		return 0;
  	}
@@ -5010,6 +5005,7 @@ struct lsm_blob_sizes smack_blob_sizes __ro_after_init = {
  	.lbs_file = sizeof(struct smack_known *),
  	.lbs_inode = sizeof(struct inode_smack),
  	.lbs_ipc = sizeof(struct smack_known *),
+	.lbs_key = sizeof(struct smack_known *),
  	.lbs_msg_msg = sizeof(struct smack_known *),
  	.lbs_sock = sizeof(struct socket_smack),
  	.lbs_superblock = sizeof(struct superblock_smack),
@@ -5146,7 +5142,6 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
   /* key management security hooks */
  #ifdef CONFIG_KEYS
  	LSM_HOOK_INIT(key_alloc, smack_key_alloc),
-	LSM_HOOK_INIT(key_free, smack_key_free),
  	LSM_HOOK_INIT(key_permission, smack_key_permission),
  	LSM_HOOK_INIT(key_getsecurity, smack_key_getsecurity),
  #ifdef CONFIG_KEY_NOTIFICATIONS
author maintainer
#5 lore raw

PATCH v2 3/6 LSM: Add helper for blob allocations

In reply to Casey Schaufler

Create a helper function lsm_blob_alloc() for general use in the hook specific functions that allocate LSM blobs. Change the hook specific functions to use this helper. This reduces the code size by a small amount and will make adding new instances of infrastructure managed security blobs easier.

---
 security/security.c | 97 +++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 64 deletions(-)
security/security.c +33 -64
index 92068ebd7e2b..e5af4274b8aa 100644
@@ -603,27 +603,42 @@ int unregister_blocking_lsm_notifier(struct notifier_block *nb)
 EXPORT_SYMBOL(unregister_blocking_lsm_notifier);
 
 /**
- * lsm_cred_alloc - allocate a composite cred blob
- * @cred: the cred that needs a blob
+ * lsm_blob_alloc - allocate a composite blob
+ * @dest: the destination for the blob
+ * @size: the size of the blob
  * @gfp: allocation type
  *
- * Allocate the cred blob for all the modules
+ * Allocate a blob for all the modules
  *
  * Returns 0, or -ENOMEM if memory can't be allocated.
  */
-static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
+static int lsm_blob_alloc(void **dest, size_t size, gfp_t gfp)
 {
-	if (blob_sizes.lbs_cred == 0) {
-		cred->security = NULL;
+	if (size == 0) {
+		*dest = NULL;
 		return 0;
 	}
 
-	cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
-	if (cred->security == NULL)
+	*dest = kzalloc(size, gfp);
+	if (*dest == NULL)
 		return -ENOMEM;
 	return 0;
 }
 
+/**
+ * lsm_cred_alloc - allocate a composite cred blob
+ * @cred: the cred that needs a blob
+ * @gfp: allocation type
+ *
+ * Allocate the cred blob for all the modules
+ *
+ * Returns 0, or -ENOMEM if memory can't be allocated.
+ */
+static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
+{
+	return lsm_blob_alloc(&cred->security, blob_sizes.lbs_cred, gfp);
+}
+
 /**
  * lsm_early_cred - during initialization allocate a composite cred blob
  * @cred: the cred that needs a blob
@@ -690,15 +705,7 @@ int lsm_inode_alloc(struct inode *inode)
  */
 static int lsm_task_alloc(struct task_struct *task)
 {
-	if (blob_sizes.lbs_task == 0) {
-		task->security = NULL;
-		return 0;
-	}
-
-	task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL);
-	if (task->security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&task->security, blob_sizes.lbs_task, GFP_KERNEL);
 }
 
 /**
@@ -711,15 +718,7 @@ static int lsm_task_alloc(struct task_struct *task)
  */
 static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
 {
-	if (blob_sizes.lbs_ipc == 0) {
-		kip->security = NULL;
-		return 0;
-	}
-
-	kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL);
-	if (kip->security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&kip->security, blob_sizes.lbs_ipc, GFP_KERNEL);
 }
 
 #ifdef CONFIG_KEYS
@@ -733,15 +732,7 @@ static int lsm_ipc_alloc(struct kern_ipc_perm *kip)
  */
 static int lsm_key_alloc(struct key *key)
 {
-	if (blob_sizes.lbs_key == 0) {
-		key->security = NULL;
-		return 0;
-	}
-
-	key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL);
-	if (key->security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&key->security, blob_sizes.lbs_key, GFP_KERNEL);
 }
 #endif /* CONFIG_KEYS */
 
@@ -755,15 +746,8 @@ static int lsm_key_alloc(struct key *key)
  */
 static int lsm_msg_msg_alloc(struct msg_msg *mp)
 {
-	if (blob_sizes.lbs_msg_msg == 0) {
-		mp->security = NULL;
-		return 0;
-	}
-
-	mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL);
-	if (mp->security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&mp->security, blob_sizes.lbs_msg_msg,
+			      GFP_KERNEL);
 }
 
 /**
@@ -790,15 +774,8 @@ static void __init lsm_early_task(struct task_struct *task)
  */
 static int lsm_superblock_alloc(struct super_block *sb)
 {
-	if (blob_sizes.lbs_superblock == 0) {
-		sb->s_security = NULL;
-		return 0;
-	}
-
-	sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL);
-	if (sb->s_security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&sb->s_security, blob_sizes.lbs_superblock,
+			      GFP_KERNEL);
 }
 
 /**
@@ -4680,23 +4657,15 @@ EXPORT_SYMBOL(security_socket_getpeersec_dgram);
 /**
  * lsm_sock_alloc - allocate a composite sock blob
  * @sock: the sock that needs a blob
- * @priority: allocation mode
+ * @gfp: allocation mode
  *
  * Allocate the sock blob for all the modules
  *
  * Returns 0, or -ENOMEM if memory can't be allocated.
  */
-static int lsm_sock_alloc(struct sock *sock, gfp_t priority)
+static int lsm_sock_alloc(struct sock *sock, gfp_t gfp)
 {
-	if (blob_sizes.lbs_sock == 0) {
-		sock->sk_security = NULL;
-		return 0;
-	}
-
-	sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority);
-	if (sock->sk_security == NULL)
-		return -ENOMEM;
-	return 0;
+	return lsm_blob_alloc(&sock->sk_security, blob_sizes.lbs_sock, gfp);
 }
 
 /**
Signature · 1 line
2.45.2
author maintainer
#6 lore raw

PATCH v2 4/6 LSM: Infrastructure management of the dev_tun blob

In reply to Casey Schaufler

Move management of the dev_tun security blob out of the individual security modules and into the LSM infrastructure. The security modules tell the infrastructure how much space they require at initialization. There are no longer any modules that require the dev_tun_free hook. The hook definition has been removed.

---
 include/linux/lsm_hook_defs.h     |  3 +--
 include/linux/lsm_hooks.h         |  1 +
 security/security.c               | 17 +++++++++++++++--
 security/selinux/hooks.c          | 22 ++++++----------------
 security/selinux/include/objsec.h |  6 ++++++
 5 files changed, 29 insertions(+), 20 deletions(-)
include/linux/lsm_hook_defs.h +1 -2
index cc81f7f7c024..f1e0d6138845 100644
@@ -352,8 +352,7 @@ LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_inc, void)
 LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_dec, void)
 LSM_HOOK(void, LSM_RET_VOID, req_classify_flow, const struct request_sock *req,
 	 struct flowi_common *flic)
-LSM_HOOK(int, 0, tun_dev_alloc_security, void **security)
-LSM_HOOK(void, LSM_RET_VOID, tun_dev_free_security, void *security)
+LSM_HOOK(int, 0, tun_dev_alloc_security, void *security)
 LSM_HOOK(int, 0, tun_dev_create, void)
 LSM_HOOK(int, 0, tun_dev_attach_queue, void *security)
 LSM_HOOK(int, 0, tun_dev_attach, struct sock *sk, void *security)
include/linux/lsm_hooks.h +1 -0
index 7233bc0737be..0ff14ff128c8 100644
@@ -80,6 +80,7 @@ struct lsm_blob_sizes {
 	int	lbs_msg_msg;
 	int	lbs_task;
 	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
+	int	lbs_tun_dev;
 };
 
 /**
security/security.c +15 -2
index e5af4274b8aa..f1eb93b65ae9 100644
@@ -232,6 +232,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
 	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
 	lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
+	lsm_set_blob_size(&needed->lbs_tun_dev, &blob_sizes.lbs_tun_dev);
 	lsm_set_blob_size(&needed->lbs_xattr_count,
 			  &blob_sizes.lbs_xattr_count);
 }
@@ -410,6 +411,7 @@ static void __init ordered_lsm_init(void)
 	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
 	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
 	init_debug("task blob size       = %d\n", blob_sizes.lbs_task);
+	init_debug("tun device blob size = %d\n", blob_sizes.lbs_tun_dev);
 	init_debug("xattr slots          = %d\n", blob_sizes.lbs_xattr_count);
 
 	/*
@@ -4849,7 +4851,18 @@ EXPORT_SYMBOL(security_secmark_refcount_dec);
  */
 int security_tun_dev_alloc_security(void **security)
 {
-	return call_int_hook(tun_dev_alloc_security, security);
+	int rc;
+
+	rc = lsm_blob_alloc(security, blob_sizes.lbs_tun_dev, GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(tun_dev_alloc_security, *security);
+	if (rc) {
+		kfree(*security);
+		*security = NULL;
+	}
+	return rc;
 }
 EXPORT_SYMBOL(security_tun_dev_alloc_security);
 
@@ -4861,7 +4874,7 @@ EXPORT_SYMBOL(security_tun_dev_alloc_security);
  */
 void security_tun_dev_free_security(void *security)
 {
-	call_void_hook(tun_dev_free_security, security);
+	kfree(security);
 }
 EXPORT_SYMBOL(security_tun_dev_free_security);
 
security/selinux/hooks.c +6 -16
index 986825ba1cc5..34ed787a4bfa 100644
@@ -5573,24 +5573,14 @@ static void selinux_req_classify_flow(const struct request_sock *req,
 	flic->flowic_secid = req->secid;
 }
 
-static int selinux_tun_dev_alloc_security(void **security)
+static int selinux_tun_dev_alloc_security(void *security)
 {
-	struct tun_security_struct *tunsec;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 
-	tunsec = kzalloc(sizeof(*tunsec), GFP_KERNEL);
-	if (!tunsec)
-		return -ENOMEM;
 	tunsec->sid = current_sid();
-
-	*security = tunsec;
 	return 0;
 }
 
-static void selinux_tun_dev_free_security(void *security)
-{
-	kfree(security);
-}
-
 static int selinux_tun_dev_create(void)
 {
 	u32 sid = current_sid();
@@ -5608,7 +5598,7 @@ static int selinux_tun_dev_create(void)
 
 static int selinux_tun_dev_attach_queue(void *security)
 {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 
 	return avc_has_perm(current_sid(), tunsec->sid, SECCLASS_TUN_SOCKET,
 			    TUN_SOCKET__ATTACH_QUEUE, NULL);
@@ -5616,7 +5606,7 @@ static int selinux_tun_dev_attach_queue(void *security)
 
 static int selinux_tun_dev_attach(struct sock *sk, void *security)
 {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 	struct sk_security_struct *sksec = selinux_sock(sk);
 
 	/* we don't currently perform any NetLabel based labeling here and it
@@ -5634,7 +5624,7 @@ static int selinux_tun_dev_attach(struct sock *sk, void *security)
 
 static int selinux_tun_dev_open(void *security)
 {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 	u32 sid = current_sid();
 	int err;
 
@@ -6973,6 +6963,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
 	.lbs_sock = sizeof(struct sk_security_struct),
 	.lbs_superblock = sizeof(struct superblock_security_struct),
 	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
+	.lbs_tun_dev = sizeof(struct tun_security_struct),
 };
 
 #ifdef CONFIG_PERF_EVENTS
@@ -7283,7 +7274,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(secmark_refcount_inc, selinux_secmark_refcount_inc),
 	LSM_HOOK_INIT(secmark_refcount_dec, selinux_secmark_refcount_dec),
 	LSM_HOOK_INIT(req_classify_flow, selinux_req_classify_flow),
-	LSM_HOOK_INIT(tun_dev_free_security, selinux_tun_dev_free_security),
 	LSM_HOOK_INIT(tun_dev_create, selinux_tun_dev_create),
 	LSM_HOOK_INIT(tun_dev_attach_queue, selinux_tun_dev_attach_queue),
 	LSM_HOOK_INIT(tun_dev_attach, selinux_tun_dev_attach),
security/selinux/include/objsec.h +6 -0
index 83b9443d6919..461c6985977d 100644
@@ -207,4 +207,10 @@ static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
 	return sock->sk_security + selinux_blob_sizes.lbs_sock;
 }
 
+static inline struct tun_security_struct *
+selinux_tun_dev(void *security)
+{
+	return security + selinux_blob_sizes.lbs_tun_dev;
+}
+
 #endif /* _SELINUX_OBJSEC_H_ */
Signature · 1 line
2.45.2
maintainer Reviewed-by on v2 4/6
#7 lore raw

Re: [PATCH v2 4/6] LSM: Infrastructure management of the dev_tun blob

Quoted 7 lines · Casey Schaufler

Move management of the dev_tun security blob out of the individual security modules and into the LSM infrastructure. The security modules tell the infrastructure how much space they require at initialization. There are no longer any modules that require the dev_tun_free hook. The hook definition has been removed.

looks good

Quoted 172 lines
---
  include/linux/lsm_hook_defs.h     |  3 +--
  include/linux/lsm_hooks.h         |  1 +
  security/security.c               | 17 +++++++++++++++--
  security/selinux/hooks.c          | 22 ++++++----------------
  security/selinux/include/objsec.h |  6 ++++++
  5 files changed, 29 insertions(+), 20 deletions(-)
include/linux/lsm_hook_defs.h +1 -2
index cc81f7f7c024..f1e0d6138845 100644
@@ -352,8 +352,7 @@ LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_inc, void)
  LSM_HOOK(void, LSM_RET_VOID, secmark_refcount_dec, void)
  LSM_HOOK(void, LSM_RET_VOID, req_classify_flow, const struct request_sock *req,
  	 struct flowi_common *flic)
-LSM_HOOK(int, 0, tun_dev_alloc_security, void **security)
-LSM_HOOK(void, LSM_RET_VOID, tun_dev_free_security, void *security)
+LSM_HOOK(int, 0, tun_dev_alloc_security, void *security)
  LSM_HOOK(int, 0, tun_dev_create, void)
  LSM_HOOK(int, 0, tun_dev_attach_queue, void *security)
  LSM_HOOK(int, 0, tun_dev_attach, struct sock *sk, void *security)
include/linux/lsm_hooks.h +1 -0
index 7233bc0737be..0ff14ff128c8 100644
@@ -80,6 +80,7 @@ struct lsm_blob_sizes {
  	int	lbs_msg_msg;
  	int	lbs_task;
  	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
+	int	lbs_tun_dev;
  };
 
  /**
security/security.c +15 -2
index e5af4274b8aa..f1eb93b65ae9 100644
@@ -232,6 +232,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
  	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
  	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
  	lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
+	lsm_set_blob_size(&needed->lbs_tun_dev, &blob_sizes.lbs_tun_dev);
  	lsm_set_blob_size(&needed->lbs_xattr_count,
  			  &blob_sizes.lbs_xattr_count);
  }
@@ -410,6 +411,7 @@ static void __init ordered_lsm_init(void)
  	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
  	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
  	init_debug("task blob size       = %d\n", blob_sizes.lbs_task);
+	init_debug("tun device blob size = %d\n", blob_sizes.lbs_tun_dev);
  	init_debug("xattr slots          = %d\n", blob_sizes.lbs_xattr_count);
 
  	/*
@@ -4849,7 +4851,18 @@ EXPORT_SYMBOL(security_secmark_refcount_dec);
   */
  int security_tun_dev_alloc_security(void **security)
  {
-	return call_int_hook(tun_dev_alloc_security, security);
+	int rc;
+
+	rc = lsm_blob_alloc(security, blob_sizes.lbs_tun_dev, GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(tun_dev_alloc_security, *security);
+	if (rc) {
+		kfree(*security);
+		*security = NULL;
+	}
+	return rc;
  }
  EXPORT_SYMBOL(security_tun_dev_alloc_security);
 
@@ -4861,7 +4874,7 @@ EXPORT_SYMBOL(security_tun_dev_alloc_security);
   */
  void security_tun_dev_free_security(void *security)
  {
-	call_void_hook(tun_dev_free_security, security);
+	kfree(security);
  }
  EXPORT_SYMBOL(security_tun_dev_free_security);
 
security/selinux/hooks.c +6 -16
index 986825ba1cc5..34ed787a4bfa 100644
@@ -5573,24 +5573,14 @@ static void selinux_req_classify_flow(const struct request_sock *req,
  	flic->flowic_secid = req->secid;
  }
 
-static int selinux_tun_dev_alloc_security(void **security)
+static int selinux_tun_dev_alloc_security(void *security)
  {
-	struct tun_security_struct *tunsec;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 
-	tunsec = kzalloc(sizeof(*tunsec), GFP_KERNEL);
-	if (!tunsec)
-		return -ENOMEM;
  	tunsec->sid = current_sid();
-
-	*security = tunsec;
  	return 0;
  }
 
-static void selinux_tun_dev_free_security(void *security)
-{
-	kfree(security);
-}
-
  static int selinux_tun_dev_create(void)
  {
  	u32 sid = current_sid();
@@ -5608,7 +5598,7 @@ static int selinux_tun_dev_create(void)
 
  static int selinux_tun_dev_attach_queue(void *security)
  {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
 
  	return avc_has_perm(current_sid(), tunsec->sid, SECCLASS_TUN_SOCKET,
  			    TUN_SOCKET__ATTACH_QUEUE, NULL);
@@ -5616,7 +5606,7 @@ static int selinux_tun_dev_attach_queue(void *security)
 
  static int selinux_tun_dev_attach(struct sock *sk, void *security)
  {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
  	struct sk_security_struct *sksec = selinux_sock(sk);
 
  	/* we don't currently perform any NetLabel based labeling here and it
@@ -5634,7 +5624,7 @@ static int selinux_tun_dev_attach(struct sock *sk, void *security)
 
  static int selinux_tun_dev_open(void *security)
  {
-	struct tun_security_struct *tunsec = security;
+	struct tun_security_struct *tunsec = selinux_tun_dev(security);
  	u32 sid = current_sid();
  	int err;
 
@@ -6973,6 +6963,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
  	.lbs_sock = sizeof(struct sk_security_struct),
  	.lbs_superblock = sizeof(struct superblock_security_struct),
  	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
+	.lbs_tun_dev = sizeof(struct tun_security_struct),
  };
 
  #ifdef CONFIG_PERF_EVENTS
@@ -7283,7 +7274,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
  	LSM_HOOK_INIT(secmark_refcount_inc, selinux_secmark_refcount_inc),
  	LSM_HOOK_INIT(secmark_refcount_dec, selinux_secmark_refcount_dec),
  	LSM_HOOK_INIT(req_classify_flow, selinux_req_classify_flow),
-	LSM_HOOK_INIT(tun_dev_free_security, selinux_tun_dev_free_security),
  	LSM_HOOK_INIT(tun_dev_create, selinux_tun_dev_create),
  	LSM_HOOK_INIT(tun_dev_attach_queue, selinux_tun_dev_attach_queue),
  	LSM_HOOK_INIT(tun_dev_attach, selinux_tun_dev_attach),
security/selinux/include/objsec.h +6 -0
index 83b9443d6919..461c6985977d 100644
@@ -207,4 +207,10 @@ static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
  	return sock->sk_security + selinux_blob_sizes.lbs_sock;
  }
 
+static inline struct tun_security_struct *
+selinux_tun_dev(void *security)
+{
+	return security + selinux_blob_sizes.lbs_tun_dev;
+}
+
  #endif /* _SELINUX_OBJSEC_H_ */
author maintainer
#8 lore raw

PATCH v2 5/6 LSM: Infrastructure management of the infiniband blob

In reply to Casey Schaufler

Move management of the infiniband security blob out of the individual security modules and into the LSM infrastructure. The security modules tell the infrastructure how much space they require at initialization. There are no longer any modules that require the ib_free() hook. The hook definition has been removed.

---
 include/linux/lsm_hook_defs.h     |  3 +--
 include/linux/lsm_hooks.h         |  1 +
 security/security.c               | 17 +++++++++++++++--
 security/selinux/hooks.c          | 16 +++-------------
 security/selinux/include/objsec.h |  6 ++++++
 5 files changed, 26 insertions(+), 17 deletions(-)
include/linux/lsm_hook_defs.h +1 -2
index f1e0d6138845..7c979137c0f2 100644
@@ -372,8 +372,7 @@ LSM_HOOK(int, 0, mptcp_add_subflow, struct sock *sk, struct sock *ssk)
 LSM_HOOK(int, 0, ib_pkey_access, void *sec, u64 subnet_prefix, u16 pkey)
 LSM_HOOK(int, 0, ib_endport_manage_subnet, void *sec, const char *dev_name,
 	 u8 port_num)
-LSM_HOOK(int, 0, ib_alloc_security, void **sec)
-LSM_HOOK(void, LSM_RET_VOID, ib_free_security, void *sec)
+LSM_HOOK(int, 0, ib_alloc_security, void *sec)
 #endif /* CONFIG_SECURITY_INFINIBAND */
 
 #ifdef CONFIG_SECURITY_NETWORK_XFRM
include/linux/lsm_hooks.h +1 -0
index 0ff14ff128c8..b6fc6ac88723 100644
@@ -72,6 +72,7 @@ struct security_hook_list {
 struct lsm_blob_sizes {
 	int	lbs_cred;
 	int	lbs_file;
+	int	lbs_ib;
 	int	lbs_inode;
 	int	lbs_sock;
 	int	lbs_superblock;
security/security.c +15 -2
index f1eb93b65ae9..e8f34cbb1990 100644
@@ -219,6 +219,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 
 	lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
 	lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
+	lsm_set_blob_size(&needed->lbs_ib, &blob_sizes.lbs_ib);
 	/*
 	 * The inode blob gets an rcu_head in addition to
 	 * what the modules might need.
@@ -402,6 +403,7 @@ static void __init ordered_lsm_init(void)
 
 	init_debug("cred blob size       = %d\n", blob_sizes.lbs_cred);
 	init_debug("file blob size       = %d\n", blob_sizes.lbs_file);
+	init_debug("ib blob size         = %d\n", blob_sizes.lbs_ib);
 	init_debug("inode blob size      = %d\n", blob_sizes.lbs_inode);
 	init_debug("ipc blob size        = %d\n", blob_sizes.lbs_ipc);
 #ifdef CONFIG_KEYS
@@ -5070,7 +5072,18 @@ EXPORT_SYMBOL(security_ib_endport_manage_subnet);
  */
 int security_ib_alloc_security(void **sec)
 {
-	return call_int_hook(ib_alloc_security, sec);
+	int rc;
+
+	rc = lsm_blob_alloc(sec, blob_sizes.lbs_ib, GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(ib_alloc_security, *sec);
+	if (rc) {
+		kfree(*sec);
+		*sec = NULL;
+	}
+	return rc;
 }
 EXPORT_SYMBOL(security_ib_alloc_security);
 
@@ -5082,7 +5095,7 @@ EXPORT_SYMBOL(security_ib_alloc_security);
  */
 void security_ib_free_security(void *sec)
 {
-	call_void_hook(ib_free_security, sec);
+	kfree(sec);
 }
 EXPORT_SYMBOL(security_ib_free_security);
 #endif	/* CONFIG_SECURITY_INFINIBAND */
security/selinux/hooks.c +3 -13
index 34ed787a4bfa..11f4bdabda97 100644
@@ -6776,23 +6776,13 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,
 			    INFINIBAND_ENDPORT__MANAGE_SUBNET, &ad);
 }
 
-static int selinux_ib_alloc_security(void **ib_sec)
+static int selinux_ib_alloc_security(void *ib_sec)
 {
-	struct ib_security_struct *sec;
+	struct ib_security_struct *sec = selinux_ib(ib_sec);
 
-	sec = kzalloc(sizeof(*sec), GFP_KERNEL);
-	if (!sec)
-		return -ENOMEM;
 	sec->sid = current_sid();
-
-	*ib_sec = sec;
 	return 0;
 }
-
-static void selinux_ib_free_security(void *ib_sec)
-{
-	kfree(ib_sec);
-}
 #endif
 
 #ifdef CONFIG_BPF_SYSCALL
@@ -6964,6 +6954,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
 	.lbs_superblock = sizeof(struct superblock_security_struct),
 	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
 	.lbs_tun_dev = sizeof(struct tun_security_struct),
+	.lbs_ib = sizeof(struct ib_security_struct),
 };
 
 #ifdef CONFIG_PERF_EVENTS
@@ -7282,7 +7273,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(ib_pkey_access, selinux_ib_pkey_access),
 	LSM_HOOK_INIT(ib_endport_manage_subnet,
 		      selinux_ib_endport_manage_subnet),
-	LSM_HOOK_INIT(ib_free_security, selinux_ib_free_security),
 #endif
 #ifdef CONFIG_SECURITY_NETWORK_XFRM
 	LSM_HOOK_INIT(xfrm_policy_free_security, selinux_xfrm_policy_free),
security/selinux/include/objsec.h +6 -0
index 461c6985977d..b1878f9395b5 100644
@@ -213,4 +213,10 @@ selinux_tun_dev(void *security)
 	return security + selinux_blob_sizes.lbs_tun_dev;
 }
 
+static inline struct ib_security_struct *
+selinux_ib(void *ib_sec)
+{
+	return ib_sec + selinux_blob_sizes.lbs_ib;
+}
+
 #endif /* _SELINUX_OBJSEC_H_ */
Signature · 1 line
2.45.2
maintainer Reviewed-by on v2 5/6
#9 lore raw

Re: [PATCH v2 5/6] LSM: Infrastructure management of the infiniband blob

Quoted 7 lines · Casey Schaufler

Move management of the infiniband security blob out of the individual security modules and into the LSM infrastructure. The security modules tell the infrastructure how much space they require at initialization. There are no longer any modules that require the ib_free() hook. The hook definition has been removed.

looks good

Quoted 144 lines
---
  include/linux/lsm_hook_defs.h     |  3 +--
  include/linux/lsm_hooks.h         |  1 +
  security/security.c               | 17 +++++++++++++++--
  security/selinux/hooks.c          | 16 +++-------------
  security/selinux/include/objsec.h |  6 ++++++
  5 files changed, 26 insertions(+), 17 deletions(-)
include/linux/lsm_hook_defs.h +1 -2
index f1e0d6138845..7c979137c0f2 100644
@@ -372,8 +372,7 @@ LSM_HOOK(int, 0, mptcp_add_subflow, struct sock *sk, struct sock *ssk)
  LSM_HOOK(int, 0, ib_pkey_access, void *sec, u64 subnet_prefix, u16 pkey)
  LSM_HOOK(int, 0, ib_endport_manage_subnet, void *sec, const char *dev_name,
  	 u8 port_num)
-LSM_HOOK(int, 0, ib_alloc_security, void **sec)
-LSM_HOOK(void, LSM_RET_VOID, ib_free_security, void *sec)
+LSM_HOOK(int, 0, ib_alloc_security, void *sec)
  #endif /* CONFIG_SECURITY_INFINIBAND */
 
  #ifdef CONFIG_SECURITY_NETWORK_XFRM
include/linux/lsm_hooks.h +1 -0
index 0ff14ff128c8..b6fc6ac88723 100644
@@ -72,6 +72,7 @@ struct security_hook_list {
  struct lsm_blob_sizes {
  	int	lbs_cred;
  	int	lbs_file;
+	int	lbs_ib;
  	int	lbs_inode;
  	int	lbs_sock;
  	int	lbs_superblock;
security/security.c +15 -2
index f1eb93b65ae9..e8f34cbb1990 100644
@@ -219,6 +219,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 
  	lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
  	lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
+	lsm_set_blob_size(&needed->lbs_ib, &blob_sizes.lbs_ib);
  	/*
  	 * The inode blob gets an rcu_head in addition to
  	 * what the modules might need.
@@ -402,6 +403,7 @@ static void __init ordered_lsm_init(void)
 
  	init_debug("cred blob size       = %d\n", blob_sizes.lbs_cred);
  	init_debug("file blob size       = %d\n", blob_sizes.lbs_file);
+	init_debug("ib blob size         = %d\n", blob_sizes.lbs_ib);
  	init_debug("inode blob size      = %d\n", blob_sizes.lbs_inode);
  	init_debug("ipc blob size        = %d\n", blob_sizes.lbs_ipc);
  #ifdef CONFIG_KEYS
@@ -5070,7 +5072,18 @@ EXPORT_SYMBOL(security_ib_endport_manage_subnet);
   */
  int security_ib_alloc_security(void **sec)
  {
-	return call_int_hook(ib_alloc_security, sec);
+	int rc;
+
+	rc = lsm_blob_alloc(sec, blob_sizes.lbs_ib, GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(ib_alloc_security, *sec);
+	if (rc) {
+		kfree(*sec);
+		*sec = NULL;
+	}
+	return rc;
  }
  EXPORT_SYMBOL(security_ib_alloc_security);
 
@@ -5082,7 +5095,7 @@ EXPORT_SYMBOL(security_ib_alloc_security);
   */
  void security_ib_free_security(void *sec)
  {
-	call_void_hook(ib_free_security, sec);
+	kfree(sec);
  }
  EXPORT_SYMBOL(security_ib_free_security);
  #endif	/* CONFIG_SECURITY_INFINIBAND */
security/selinux/hooks.c +3 -13
index 34ed787a4bfa..11f4bdabda97 100644
@@ -6776,23 +6776,13 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,
  			    INFINIBAND_ENDPORT__MANAGE_SUBNET, &ad);
  }
 
-static int selinux_ib_alloc_security(void **ib_sec)
+static int selinux_ib_alloc_security(void *ib_sec)
  {
-	struct ib_security_struct *sec;
+	struct ib_security_struct *sec = selinux_ib(ib_sec);
 
-	sec = kzalloc(sizeof(*sec), GFP_KERNEL);
-	if (!sec)
-		return -ENOMEM;
  	sec->sid = current_sid();
-
-	*ib_sec = sec;
  	return 0;
  }
-
-static void selinux_ib_free_security(void *ib_sec)
-{
-	kfree(ib_sec);
-}
  #endif
 
  #ifdef CONFIG_BPF_SYSCALL
@@ -6964,6 +6954,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
  	.lbs_superblock = sizeof(struct superblock_security_struct),
  	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
  	.lbs_tun_dev = sizeof(struct tun_security_struct),
+	.lbs_ib = sizeof(struct ib_security_struct),
  };
 
  #ifdef CONFIG_PERF_EVENTS
@@ -7282,7 +7273,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
  	LSM_HOOK_INIT(ib_pkey_access, selinux_ib_pkey_access),
  	LSM_HOOK_INIT(ib_endport_manage_subnet,
  		      selinux_ib_endport_manage_subnet),
-	LSM_HOOK_INIT(ib_free_security, selinux_ib_free_security),
  #endif
  #ifdef CONFIG_SECURITY_NETWORK_XFRM
  	LSM_HOOK_INIT(xfrm_policy_free_security, selinux_xfrm_policy_free),
security/selinux/include/objsec.h +6 -0
index 461c6985977d..b1878f9395b5 100644
@@ -213,4 +213,10 @@ selinux_tun_dev(void *security)
  	return security + selinux_blob_sizes.lbs_tun_dev;
  }
 
+static inline struct ib_security_struct *
+selinux_ib(void *ib_sec)
+{
+	return ib_sec + selinux_blob_sizes.lbs_ib;
+}
+
  #endif /* _SELINUX_OBJSEC_H_ */
author maintainer
#10 lore raw

PATCH v2 6/6 LSM: Infrastructure management of the perf_event security blob

In reply to Casey Schaufler

Move management of the perf_event->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. There are no longer any modules that require the perf_event_free() hook. The hook definition has been removed.

---
 include/linux/lsm_hook_defs.h     |  1 -
 include/linux/lsm_hooks.h         |  1 +
 security/security.c               | 20 ++++++++++++++++++--
 security/selinux/hooks.c          | 18 ++++--------------
 security/selinux/include/objsec.h |  6 ++++++
 5 files changed, 29 insertions(+), 17 deletions(-)
include/linux/lsm_hook_defs.h +0 -1
index 7c979137c0f2..658e4ba282e6 100644
@@ -438,7 +438,6 @@ LSM_HOOK(int, 0, locked_down, enum lockdown_reason what)
 #ifdef CONFIG_PERF_EVENTS
 LSM_HOOK(int, 0, perf_event_open, struct perf_event_attr *attr, int type)
 LSM_HOOK(int, 0, perf_event_alloc, struct perf_event *event)
-LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event)
 LSM_HOOK(int, 0, perf_event_read, struct perf_event *event)
 LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
 #endif /* CONFIG_PERF_EVENTS */
include/linux/lsm_hooks.h +1 -0
index b6fc6ac88723..f1ca8082075a 100644
@@ -79,6 +79,7 @@ struct lsm_blob_sizes {
 	int	lbs_ipc;
 	int	lbs_key;
 	int	lbs_msg_msg;
+	int	lbs_perf_event;
 	int	lbs_task;
 	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
 	int	lbs_tun_dev;
security/security.c +18 -2
index e8f34cbb1990..444b0ea28c04 100644
@@ -28,6 +28,7 @@
 #include <linux/xattr.h>
 #include <linux/msg.h>
 #include <linux/overflow.h>
+#include <linux/perf_event.h>
 #include <net/flow.h>
 #include <net/sock.h>
 
@@ -230,6 +231,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
 	lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
 	lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key);
 	lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
+	lsm_set_blob_size(&needed->lbs_perf_event, &blob_sizes.lbs_perf_event);
 	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
 	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
 	lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
@@ -412,6 +414,7 @@ static void __init ordered_lsm_init(void)
 	init_debug("msg_msg blob size    = %d\n", blob_sizes.lbs_msg_msg);
 	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
 	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
+	init_debug("perf event blob size = %d\n", blob_sizes.lbs_perf_event);
 	init_debug("task blob size       = %d\n", blob_sizes.lbs_task);
 	init_debug("tun device blob size = %d\n", blob_sizes.lbs_tun_dev);
 	init_debug("xattr slots          = %d\n", blob_sizes.lbs_xattr_count);
@@ -5659,7 +5662,19 @@ int security_perf_event_open(struct perf_event_attr *attr, int type)
  */
 int security_perf_event_alloc(struct perf_event *event)
 {
-	return call_int_hook(perf_event_alloc, event);
+	int rc;
+
+	rc = lsm_blob_alloc(&event->security, blob_sizes.lbs_perf_event,
+			    GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(perf_event_alloc, event);
+	if (rc) {
+		kfree(event->security);
+		event->security = NULL;
+	}
+	return rc;
 }
 
 /**
@@ -5670,7 +5685,8 @@ int security_perf_event_alloc(struct perf_event *event)
  */
 void security_perf_event_free(struct perf_event *event)
 {
-	call_void_hook(perf_event_free, event);
+	kfree(event->security);
+	event->security = NULL;
 }
 
 /**
security/selinux/hooks.c +4 -14
index 11f4bdabda97..f42f6af55a73 100644
@@ -6950,6 +6950,9 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
 	.lbs_ipc = sizeof(struct ipc_security_struct),
 	.lbs_key = sizeof(struct key_security_struct),
 	.lbs_msg_msg = sizeof(struct msg_security_struct),
+#ifdef CONFIG_PERF_EVENTS
+	.lbs_perf_event = sizeof(struct perf_event_security_struct),
+#endif
 	.lbs_sock = sizeof(struct sk_security_struct),
 	.lbs_superblock = sizeof(struct superblock_security_struct),
 	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
@@ -6981,24 +6984,12 @@ static int selinux_perf_event_alloc(struct perf_event *event)
 {
 	struct perf_event_security_struct *perfsec;
 
-	perfsec = kzalloc(sizeof(*perfsec), GFP_KERNEL);
-	if (!perfsec)
-		return -ENOMEM;
-
+	perfsec = selinux_perf_event(event->security);
 	perfsec->sid = current_sid();
-	event->security = perfsec;
 
 	return 0;
 }
 
-static void selinux_perf_event_free(struct perf_event *event)
-{
-	struct perf_event_security_struct *perfsec = event->security;
-
-	event->security = NULL;
-	kfree(perfsec);
-}
-
 static int selinux_perf_event_read(struct perf_event *event)
 {
 	struct perf_event_security_struct *perfsec = event->security;
@@ -7310,7 +7301,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 
 #ifdef CONFIG_PERF_EVENTS
 	LSM_HOOK_INIT(perf_event_open, selinux_perf_event_open),
-	LSM_HOOK_INIT(perf_event_free, selinux_perf_event_free),
 	LSM_HOOK_INIT(perf_event_read, selinux_perf_event_read),
 	LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write),
 #endif
security/selinux/include/objsec.h +6 -0
index b1878f9395b5..d632a9180b41 100644
@@ -219,4 +219,10 @@ selinux_ib(void *ib_sec)
 	return ib_sec + selinux_blob_sizes.lbs_ib;
 }
 
+static inline struct perf_event_security_struct *
+selinux_perf_event(void *perf_event)
+{
+	return perf_event + selinux_blob_sizes.lbs_perf_event;
+}
+
 #endif /* _SELINUX_OBJSEC_H_ */
Signature · 1 line
2.45.2
maintainer Reviewed-by on v2 6/6
#11 lore raw

Re: [PATCH v2 6/6] LSM: Infrastructure management of the perf_event security blob

Quoted 8 lines · Casey Schaufler

Move management of the perf_event->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. There are no longer any modules that require the perf_event_free() hook. The hook definition has been removed.

looks good

Quoted 154 lines
---
  include/linux/lsm_hook_defs.h     |  1 -
  include/linux/lsm_hooks.h         |  1 +
  security/security.c               | 20 ++++++++++++++++++--
  security/selinux/hooks.c          | 18 ++++--------------
  security/selinux/include/objsec.h |  6 ++++++
  5 files changed, 29 insertions(+), 17 deletions(-)
include/linux/lsm_hook_defs.h +0 -1
index 7c979137c0f2..658e4ba282e6 100644
@@ -438,7 +438,6 @@ LSM_HOOK(int, 0, locked_down, enum lockdown_reason what)
  #ifdef CONFIG_PERF_EVENTS
  LSM_HOOK(int, 0, perf_event_open, struct perf_event_attr *attr, int type)
  LSM_HOOK(int, 0, perf_event_alloc, struct perf_event *event)
-LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event)
  LSM_HOOK(int, 0, perf_event_read, struct perf_event *event)
  LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
  #endif /* CONFIG_PERF_EVENTS */
include/linux/lsm_hooks.h +1 -0
index b6fc6ac88723..f1ca8082075a 100644
@@ -79,6 +79,7 @@ struct lsm_blob_sizes {
  	int	lbs_ipc;
  	int	lbs_key;
  	int	lbs_msg_msg;
+	int	lbs_perf_event;
  	int	lbs_task;
  	int	lbs_xattr_count; /* number of xattr slots in new_xattrs array */
  	int	lbs_tun_dev;
security/security.c +18 -2
index e8f34cbb1990..444b0ea28c04 100644
@@ -28,6 +28,7 @@
  #include <linux/xattr.h>
  #include <linux/msg.h>
  #include <linux/overflow.h>
+#include <linux/perf_event.h>
  #include <net/flow.h>
  #include <net/sock.h>
 
@@ -230,6 +231,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
  	lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
  	lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key);
  	lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
+	lsm_set_blob_size(&needed->lbs_perf_event, &blob_sizes.lbs_perf_event);
  	lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
  	lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
  	lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
@@ -412,6 +414,7 @@ static void __init ordered_lsm_init(void)
  	init_debug("msg_msg blob size    = %d\n", blob_sizes.lbs_msg_msg);
  	init_debug("sock blob size       = %d\n", blob_sizes.lbs_sock);
  	init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
+	init_debug("perf event blob size = %d\n", blob_sizes.lbs_perf_event);
  	init_debug("task blob size       = %d\n", blob_sizes.lbs_task);
  	init_debug("tun device blob size = %d\n", blob_sizes.lbs_tun_dev);
  	init_debug("xattr slots          = %d\n", blob_sizes.lbs_xattr_count);
@@ -5659,7 +5662,19 @@ int security_perf_event_open(struct perf_event_attr *attr, int type)
   */
  int security_perf_event_alloc(struct perf_event *event)
  {
-	return call_int_hook(perf_event_alloc, event);
+	int rc;
+
+	rc = lsm_blob_alloc(&event->security, blob_sizes.lbs_perf_event,
+			    GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = call_int_hook(perf_event_alloc, event);
+	if (rc) {
+		kfree(event->security);
+		event->security = NULL;
+	}
+	return rc;
  }
 
  /**
@@ -5670,7 +5685,8 @@ int security_perf_event_alloc(struct perf_event *event)
   */
  void security_perf_event_free(struct perf_event *event)
  {
-	call_void_hook(perf_event_free, event);
+	kfree(event->security);
+	event->security = NULL;
  }
 
  /**
security/selinux/hooks.c +4 -14
index 11f4bdabda97..f42f6af55a73 100644
@@ -6950,6 +6950,9 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
  	.lbs_ipc = sizeof(struct ipc_security_struct),
  	.lbs_key = sizeof(struct key_security_struct),
  	.lbs_msg_msg = sizeof(struct msg_security_struct),
+#ifdef CONFIG_PERF_EVENTS
+	.lbs_perf_event = sizeof(struct perf_event_security_struct),
+#endif
  	.lbs_sock = sizeof(struct sk_security_struct),
  	.lbs_superblock = sizeof(struct superblock_security_struct),
  	.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
@@ -6981,24 +6984,12 @@ static int selinux_perf_event_alloc(struct perf_event *event)
  {
  	struct perf_event_security_struct *perfsec;
 
-	perfsec = kzalloc(sizeof(*perfsec), GFP_KERNEL);
-	if (!perfsec)
-		return -ENOMEM;
-
+	perfsec = selinux_perf_event(event->security);
  	perfsec->sid = current_sid();
-	event->security = perfsec;
 
  	return 0;
  }
 
-static void selinux_perf_event_free(struct perf_event *event)
-{
-	struct perf_event_security_struct *perfsec = event->security;
-
-	event->security = NULL;
-	kfree(perfsec);
-}
-
  static int selinux_perf_event_read(struct perf_event *event)
  {
  	struct perf_event_security_struct *perfsec = event->security;
@@ -7310,7 +7301,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 
  #ifdef CONFIG_PERF_EVENTS
  	LSM_HOOK_INIT(perf_event_open, selinux_perf_event_open),
-	LSM_HOOK_INIT(perf_event_free, selinux_perf_event_free),
  	LSM_HOOK_INIT(perf_event_read, selinux_perf_event_read),
  	LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write),
  #endif
security/selinux/include/objsec.h +6 -0
index b1878f9395b5..d632a9180b41 100644
@@ -219,4 +219,10 @@ selinux_ib(void *ib_sec)
  	return ib_sec + selinux_blob_sizes.lbs_ib;
  }
 
+static inline struct perf_event_security_struct *
+selinux_perf_event(void *perf_event)
+{
+	return perf_event + selinux_blob_sizes.lbs_perf_event;
+}
+
  #endif /* _SELINUX_OBJSEC_H_ */
maintainer
#12 lore raw

Re: [PATCH v2 0/6] LSM: Infrastructure blob allocation

In reply to Casey Schaufler
Quoted 39 lines · Casey Schaufler

When more than one Linux Security Module (LSM) can use the security blob for a partincular object the management of the memory associated with that blob needs to be done by the infrastructure rather than the individual modules. Until now, this has been done on an as needed basis, with the blob management remaining in the modules until such time as a new configuration of modules requires sharing the blob. This piecemeal approach makes adding new modules that use blobs more difficult, as moving the blob management to the infrastructure isn't as simple as it might seem. This patch set moves management of the security blobs that is done in the modules into the infrastructure. Making security blob management more consistant improves mantainablity and makes the possibilty of general improvement of LSM blob managment easier.

No effort has been put into pursuing the possible performance optimizations these changes introduce. For example, sk_security blobs might be moved to use kmem_zone_alloc(). The option of changing the blob sizes to being compile time determined rather than calculated at run time has been considered for future exploration.

In the cases where infrastructure blob freeing no longer requires any special action on the part of any security module the hook definition has been removed as it is no long necessary.

Security blobs for the xfrm subsystem are problematic as the only security module that implements them (SELinux) has a variable size blob that has a published external API. Management of these blobs by the infrastructure will require significant consideration and negotiation with the maintainers of the existing code. This has been deferred until such time as another user of xfrm appears.

Casey Schaufler (6):
LSM: Infrastructure management of the sock security
LSM: Infrastructure management of the key security blob
LSM: Add helper for blob allocations
LSM: Infrastructure management of the dev_tun blob
LSM: Infrastructure management of the infiniband blob
LSM: Infrastructure management of the perf_event security blob

Quoted 13 lines
 include/linux/lsm_hook_defs.h     |   8 +-
 include/linux/lsm_hooks.h         |   5 +
 security/apparmor/include/net.h   |   3 +-
 security/apparmor/lsm.c           |  17 +--
 security/apparmor/net.c           |   2 +-
 security/security.c               | 184 +++++++++++++++++++++---------
 security/selinux/hooks.c          | 157 +++++++++----------------
 security/selinux/include/objsec.h |  30 +++++
 security/selinux/netlabel.c       |  23 ++--
 security/smack/smack.h            |  12 ++
 security/smack/smack_lsm.c        | 101 ++++++++--------
 security/smack/smack_netfilter.c  |   4 +-
 12 files changed, 298 insertions(+), 248 deletions(-)

Thanks Casey, these look good. I'm going to merge them in lsm/dev-staging now with the expectation that they'll be merged after the upcoming merge window closes.

Signature · 1 line
paul-moore.com
maintainer
#13 lore raw

Re: [PATCH v2 0/6] LSM: Infrastructure blob allocation

Quoted 54 lines · Paul Moore
Quoted 39 lines · Casey Schaufler

When more than one Linux Security Module (LSM) can use the security blob for a partincular object the management of the memory associated with that blob needs to be done by the infrastructure rather than the individual modules. Until now, this has been done on an as needed basis, with the blob management remaining in the modules until such time as a new configuration of modules requires sharing the blob. This piecemeal approach makes adding new modules that use blobs more difficult, as moving the blob management to the infrastructure isn't as simple as it might seem. This patch set moves management of the security blobs that is done in the modules into the infrastructure. Making security blob management more consistant improves mantainablity and makes the possibilty of general improvement of LSM blob managment easier.

No effort has been put into pursuing the possible performance optimizations these changes introduce. For example, sk_security blobs might be moved to use kmem_zone_alloc(). The option of changing the blob sizes to being compile time determined rather than calculated at run time has been considered for future exploration.

In the cases where infrastructure blob freeing no longer requires any special action on the part of any security module the hook definition has been removed as it is no long necessary.

Security blobs for the xfrm subsystem are problematic as the only security module that implements them (SELinux) has a variable size blob that has a published external API. Management of these blobs by the infrastructure will require significant consideration and negotiation with the maintainers of the existing code. This has been deferred until such time as another user of xfrm appears.

Casey Schaufler (6):
LSM: Infrastructure management of the sock security
LSM: Infrastructure management of the key security blob
LSM: Add helper for blob allocations
LSM: Infrastructure management of the dev_tun blob
LSM: Infrastructure management of the infiniband blob
LSM: Infrastructure management of the perf_event security blob

Quoted 13 lines
 include/linux/lsm_hook_defs.h     |   8 +-
 include/linux/lsm_hooks.h         |   5 +
 security/apparmor/include/net.h   |   3 +-
 security/apparmor/lsm.c           |  17 +--
 security/apparmor/net.c           |   2 +-
 security/security.c               | 184 +++++++++++++++++++++---------
 security/selinux/hooks.c          | 157 +++++++++----------------
 security/selinux/include/objsec.h |  30 +++++
 security/selinux/netlabel.c       |  23 ++--
 security/smack/smack.h            |  12 ++
 security/smack/smack_lsm.c        | 101 ++++++++--------
 security/smack/smack_netfilter.c  |   4 +-
 12 files changed, 298 insertions(+), 248 deletions(-)
Quoted 3 lines

Thanks Casey, these look good. I'm going to merge them in lsm/dev-staging now with the expectation that they'll be merged after the upcoming merge window closes.

These are now in lsm/dev, thanks!

Signature · 1 line
paul-moore.com