Thread (29 messages) 29 messages, 1 author, 2021-09-24
STALE1748d REVIEWED: 6 (5M)
Revisions (54)
  1. v1 [diff vs current]
  2. v1 [diff vs current]
  3. v1 [diff vs current]
  4. v1 [diff vs current]
  5. v1 [diff vs current]
  6. v2 [diff vs current]
  7. v3 [diff vs current]
  8. v3 [diff vs current]
  9. v4 [diff vs current]
  10. v5 [diff vs current]
  11. v5 [diff vs current]
  12. v7 [diff vs current]
  13. v10 [diff vs current]
  14. v10 [diff vs current]
  15. v10 [diff vs current]
  16. v11 [diff vs current]
  17. v11 [diff vs current]
  18. v11 [diff vs current]
  19. v11 [diff vs current]
  20. v11 [diff vs current]
  21. v12 [diff vs current]
  22. v12 [diff vs current]
  23. v12 [diff vs current]
  24. v12 [diff vs current]
  25. v13 [diff vs current]
  26. v14 [diff vs current]
  27. v15 [diff vs current]
  28. v15 [diff vs current]
  29. v15 [diff vs current]
  30. v15 [diff vs current]
  31. v17 [diff vs current]
  32. v18 [diff vs current]
  33. v19 [diff vs current]
  34. v20 [diff vs current]
  35. v21 [diff vs current]
  36. v22 [diff vs current]
  37. v22 [diff vs current]
  38. v22 [diff vs current]
  39. v24 [diff vs current]
  40. v25 [diff vs current]
  41. v26 [diff vs current]
  42. v27 [diff vs current]
  43. v28 [diff vs current]
  44. v29 current
  45. v30 [diff vs current]
  46. v31 [diff vs current]
  47. v32 [diff vs current]
  48. v33 [diff vs current]
  49. v34 [diff vs current]
  50. v34 [diff vs current]
  51. v35 [diff vs current]
  52. v36 [diff vs current]
  53. v37 [diff vs current]
  54. v38 [diff vs current]

[PATCH v29 03/28] LSM: provide lsm name and id slot mappings

From: Casey Schaufler <casey@schaufler-ca.com>
Date: 2021-09-24 17:58:12
Also in: lkml, selinux
Subsystem: security subsystem, the rest · Maintainers: Paul Moore, James Morris, "Serge E. Hallyn", Linus Torvalds

Provide interfaces to map LSM slot numbers and LSM names.
Update the LSM registration code to save this information.

Acked-by: Paul Moore <paul@paul-moore.com>
Reviewed-by: Kees Cook <redacted>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
 include/linux/security.h |  4 ++++
 security/security.c      | 45 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
diff --git a/include/linux/security.h b/include/linux/security.h
index 1b05094468b7..b10b10afd04f 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -193,6 +193,10 @@ static inline bool lsmblob_equal(struct lsmblob *bloba, struct lsmblob *blobb)
 	return !memcmp(bloba, blobb, sizeof(*bloba));
 }
 
+/* Map lsm names to blob slot numbers */
+extern int lsm_name_to_slot(char *name);
+extern const char *lsm_slot_to_name(int slot);
+
 /* These functions are in security/commoncap.c */
 extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
 		       int cap, unsigned int opts);
diff --git a/security/security.c b/security/security.c
index b4af710fbb90..8ca554e1dbeb 100644
--- a/security/security.c
+++ b/security/security.c
@@ -477,6 +477,50 @@ static int lsm_append(const char *new, char **result)
  * Current index to use while initializing the lsmblob secid list.
  */
 static int lsm_slot __lsm_ro_after_init;
+static struct lsm_id *lsm_slotlist[LSMBLOB_ENTRIES] __lsm_ro_after_init;
+
+/**
+ * lsm_name_to_slot - Report the slot number for a security module
+ * @name: name of the security module
+ *
+ * Look up the slot number for the named security module.
+ * Returns the slot number or LSMBLOB_INVALID if @name is not
+ * a registered security module name.
+ */
+int lsm_name_to_slot(char *name)
+{
+	int i;
+
+	for (i = 0; i < lsm_slot; i++)
+		if (strcmp(lsm_slotlist[i]->lsm, name) == 0)
+			return i;
+
+	return LSMBLOB_INVALID;
+}
+
+/**
+ * lsm_slot_to_name - Get the name of the security module in a slot
+ * @slot: index into the interface LSM slot list.
+ *
+ * Provide the name of the security module associated with
+ * a interface LSM slot.
+ *
+ * If @slot is LSMBLOB_INVALID return the value
+ * for slot 0 if it has been set, otherwise NULL.
+ *
+ * Returns a pointer to the name string or NULL.
+ */
+const char *lsm_slot_to_name(int slot)
+{
+	if (slot == LSMBLOB_INVALID)
+		slot = 0;
+	else if (slot >= LSMBLOB_ENTRIES || slot < 0)
+		return NULL;
+
+	if (lsm_slotlist[slot] == NULL)
+		return NULL;
+	return lsm_slotlist[slot]->lsm;
+}
 
 /**
  * security_add_hooks - Add a modules hooks to the hook lists.
@@ -498,6 +542,7 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,
 	if (lsmid->slot == LSMBLOB_NEEDED) {
 		if (lsm_slot >= LSMBLOB_ENTRIES)
 			panic("%s Too many LSMs registered.\n", __func__);
+		lsm_slotlist[lsm_slot] = lsmid;
 		lsmid->slot = lsm_slot++;
 		init_debug("%s assigned lsmblob slot %d\n", lsmid->lsm,
 			   lsmid->slot);
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help