Skip to contentSkip to conversation

selinux: add selinux_status_get_seq() function

PATCH In review Sebastien Buisson 3 participants 3 messages Apr 12, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: add selinux_status_get_seq() function

Add selinux_status_get_seq() function to give access to sequence number of current SELinux policy loaded to the rest of the kernel.

---
 include/linux/selinux.h      |  7 +++++++
 security/selinux/ss/status.c | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+)
include/linux/selinux.h +7 -0
index 44f4596..926f9f0 100644
@@ -24,12 +24,19 @@
  * selinux_is_enabled - is SELinux enabled?
  */
 bool selinux_is_enabled(void);
+u32 selinux_status_get_seq(void);
 #else
 
 static inline bool selinux_is_enabled(void)
 {
 	return false;
 }
+
+static inline u32 selinux_status_get_seq(void)
+{
+	return 0;
+}
+
 #endif	/* CONFIG_SECURITY_SELINUX */
 
 #endif /* _LINUX_SELINUX_H */
security/selinux/ss/status.c +21 -0
index d982365..a0670d3 100644
@@ -124,3 +124,24 @@ void selinux_status_update_policyload(int seqno)
 	}
 	mutex_unlock(&selinux_status_lock);
 }
+
+/*
+ * selinux_status_get_seq
+ *
+ * It gets current sequence of policy loaded.
+ */
+u32 selinux_status_get_seq(void)
+{
+	struct selinux_kernel_status   *status;
+	u32				seq = 0;
+
+	mutex_lock(&selinux_status_lock);
+	if (selinux_status_page) {
+		status = page_address(selinux_status_page);
+		seq = status->sequence;
+	}
+	mutex_unlock(&selinux_status_lock);
+
+	return seq;
+}
+EXPORT_SYMBOL_GPL(selinux_status_get_seq);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 8 lines · Sebastien Buisson

Add selinux_status_get_seq() function to give access to sequence number of current SELinux policy loaded to the rest of the kernel.

---
 include/linux/selinux.h      |  7 +++++++
 security/selinux/ss/status.c | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+)

See my comments on your other patch, they apply here as well.

Quoted 60 lines
include/linux/selinux.h +7 -0
index 44f4596..926f9f0 100644
@@ -24,12 +24,19 @@
  * selinux_is_enabled - is SELinux enabled?
  */
 bool selinux_is_enabled(void);
+u32 selinux_status_get_seq(void);
 #else
 
 static inline bool selinux_is_enabled(void)
 {
        return false;
 }
+
+static inline u32 selinux_status_get_seq(void)
+{
+       return 0;
+}
+
 #endif /* CONFIG_SECURITY_SELINUX */
 
 #endif /* _LINUX_SELINUX_H */
security/selinux/ss/status.c +21 -1
index d982365..a0670d3 100644
@@ -124,3 +124,24 @@ void selinux_status_update_policyload(int seqno)
        }
        mutex_unlock(&selinux_status_lock);
 }
+
+/*
+ * selinux_status_get_seq
+ *
+ * It gets current sequence of policy loaded.
+ */
+u32 selinux_status_get_seq(void)
+{
+       struct selinux_kernel_status   *status;
+       u32                             seq = 0;
+
+       mutex_lock(&selinux_status_lock);
+       if (selinux_status_page) {
+               status = page_address(selinux_status_page);
+               seq = status->sequence;
+       }
+       mutex_unlock(&selinux_status_lock);
+
+       return seq;
+}
+EXPORT_SYMBOL_GPL(selinux_status_get_seq);
--

1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 6 lines
paul moore
security @ redhat
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Sebastien Buisson
Quoted 53 lines · Sebastien Buisson

Add selinux_status_get_seq() function to give access to sequence number of current SELinux policy loaded to the rest of the kernel.

---
 include/linux/selinux.h      |  7 +++++++ security/selinux/ss/status.c | 21 +++++++++++++++++++++

 2 files changed, 28 insertions(+)
include/linux/selinux.h +1 -0
index 44f4596..926f9f0 100644
@@ -24,12 +24,19 @@
   * selinux_is_enabled - is SELinux enabled?
   */
  bool selinux_is_enabled(void);
+u32 selinux_status_get_seq(void);
  #else


 static inline bool selinux_is_enabled(void)
 {
  return false;
 }

include/linux/selinux.h +6 -0
+
+static inline u32 selinux_status_get_seq(void)
+{
+	return 0;
+}
+

 #endif /* CONFIG_SECURITY_SELINUX */

 #endif /* _LINUX_SELINUX_H */

security/selinux/ss/status.c +11 -0
index d982365..a0670d3 100644
@@ -124,3 +124,24 @@ void selinux_status_update_policyload(int seqno)
  	}
  	mutex_unlock(&selinux_status_lock);
  }
+
+/*
+ * selinux_status_get_seq
+ *
+ * It gets current sequence of policy loaded.
+ */
+u32 selinux_status_get_seq(void)
+{
+	struct selinux_kernel_status   *status;
+	u32				seq = 0;
+

security/selinux/ss/status.c void selinux_status_update_policyload(int seqno) · line 147

Quoted 10 lines
security/selinux/ss/status.c +10 -0
+	mutex_lock(&selinux_status_lock);
+	if (selinux_status_page) {
+		status = page_address(selinux_status_page);
+		seq = status->sequence;
+	}
+	mutex_unlock(&selinux_status_lock);
+
+	return seq;
+}
+EXPORT_SYMBOL_GPL(selinux_status_get_seq);

status->sequence is a sequence number for the seqlock logic, not the policy sequence number. You likely want avc_policy_seqno() instead, although I can't tell without seeing the user of this function. Regardless, as with the other patch, there needs to be an in-tree user and a LSM hook interface to use this outside of the SELinux code itself.