Skip to contentSkip to conversation

SLIM: secfs patch

PATCH In review Kylene Jo Hall 3 participants 7 messages Sep 12, 2006 – Sep 27, 2006 Security (LSM)

lore
Share & tools
lore
#0 lore raw

PATCH 4/7 SLIM: secfs patch

This patch provides the securityfs used by SLIM.

---

 security/slim/slm_secfs.c |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+)
security/slim/slm_secfs.c +73 -0
@@ -0,0 +1,73 @@
+/*
+ * SLIM securityfs support: debugging control files
+ *
+ * Copyright (C) 2005, 2006 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *	   Kylene Hall <[email protected]>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2 of the License.
+ */
+
+#include <asm/uaccess.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/security.h>
+#include <linux/debugfs.h>
+#include "slim.h"
+
+static struct dentry *slim_sec_dir, *slim_level;
+
+static ssize_t slm_read_level(struct file *file, char __user *buf,
+			      size_t buflen, loff_t *ppos)
+{
+	struct slm_tsec_data *cur_tsec = current->security;
+	ssize_t len;
+	char data[28]; 
+	if (is_kernel_thread(current))
+		len = snprintf(data, sizeof(data), "KERNEL\n");
+	else if (!cur_tsec)
+		len = snprintf(data, sizeof(data), "UNKNOWN\n");
+	else {
+		if (cur_tsec->iac_wx != cur_tsec->iac_r)
+			len = snprintf(data, sizeof(data), "GUARD wx:%s r:%s\n",
+				      slm_iac_str[cur_tsec->iac_wx],
+				      slm_iac_str[cur_tsec->iac_r]);
+		else
+			len = snprintf(data, sizeof(data), "%s\n",
+				      slm_iac_str[cur_tsec->iac_wx]);
+	}
+	return simple_read_from_buffer(buf, buflen, ppos, data, len);
+}
+
+static struct file_operations slm_level_ops = {
+	.read = slm_read_level,
+};
+
+int __init slm_init_secfs(void)
+{
+	if (!slim_enabled)
+		return 0;
+
+	slim_sec_dir = securityfs_create_dir("slim", NULL);
+	if (!slim_sec_dir || IS_ERR(slim_sec_dir))
+		return -EFAULT;
+	slim_level = securityfs_create_file("level", S_IRUGO,
+					    slim_sec_dir, NULL, &slm_level_ops);
+	if (!slim_level || IS_ERR(slim_level)) {
+		securityfs_remove(slim_sec_dir);
+		return -EFAULT;
+	}
+	return 0;
+}
+
+__initcall(slm_init_secfs);
+
+void __exit slm_cleanup_secfs(void)
+{
+	securityfs_remove(slim_level);
+	securityfs_remove(slim_sec_dir);
+}
+
#1 lore raw
Quoted 44 lines · Kylene Jo Hall

This patch provides the securityfs used by SLIM.

---

 security/slim/slm_secfs.c |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+)
security/slim/slm_secfs.c +33 -0
@@ -0,0 +1,73 @@
+/*
+ * SLIM securityfs support: debugging control files
+ *
+ * Copyright (C) 2005, 2006 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *	   Kylene Hall <[email protected]>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2 of the License.
+ */
+
+#include <asm/uaccess.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/security.h>
+#include <linux/debugfs.h>
+#include "slim.h"
+
+static struct dentry *slim_sec_dir, *slim_level;
+
+static ssize_t slm_read_level(struct file *file, char __user *buf,
+			      size_t buflen, loff_t *ppos)
+{
+	struct slm_tsec_data *cur_tsec = current->security;
+	ssize_t len;
+	char data[28]; 
+	if (is_kernel_thread(current))
+		len = snprintf(data, sizeof(data), "KERNEL\n");
+	else if (!cur_tsec)
+		len = snprintf(data, sizeof(data), "UNKNOWN\n");
+	else {

security/slim/slm_secfs.c line 43

Quoted 10 lines
security/slim/slm_secfs.c +10 -0
+		if (cur_tsec->iac_wx != cur_tsec->iac_r)
+			len = snprintf(data, sizeof(data), "GUARD wx:%s r:%s\n",
+				      slm_iac_str[cur_tsec->iac_wx],
+				      slm_iac_str[cur_tsec->iac_r]);
+		else
+			len = snprintf(data, sizeof(data), "%s\n",
+				      slm_iac_str[cur_tsec->iac_wx]);
+	}
+	return simple_read_from_buffer(buf, buflen, ppos, data, len);
+}

Why do you need this when you implement getprocattr and return the same data that way?

Quoted 30 lines
security/slim/slm_secfs.c +30 -0
+
+static struct file_operations slm_level_ops = {
+	.read = slm_read_level,
+};
+
+int __init slm_init_secfs(void)
+{
+	if (!slim_enabled)
+		return 0;
+
+	slim_sec_dir = securityfs_create_dir("slim", NULL);
+	if (!slim_sec_dir || IS_ERR(slim_sec_dir))
+		return -EFAULT;
+	slim_level = securityfs_create_file("level", S_IRUGO,
+					    slim_sec_dir, NULL, &slm_level_ops);
+	if (!slim_level || IS_ERR(slim_level)) {
+		securityfs_remove(slim_sec_dir);
+		return -EFAULT;
+	}
+	return 0;
+}
+
+__initcall(slm_init_secfs);
+
+void __exit slm_cleanup_secfs(void)
+{
+	securityfs_remove(slim_level);
+	securityfs_remove(slim_sec_dir);
+}
+
Signature · 2 lines
Stephen Smalley
National Security Agency
#2 lore raw
Quoted 50 lines · Stephen Smalley
Quoted 49 lines · Kylene Jo Hall

This patch provides the securityfs used by SLIM.

---

 security/slim/slm_secfs.c |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+)
security/slim/slm_secfs.c +38 -0
@@ -0,0 +1,73 @@
+/*
+ * SLIM securityfs support: debugging control files
+ *
+ * Copyright (C) 2005, 2006 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *	   Kylene Hall <[email protected]>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2 of the License.
+ */
+
+#include <asm/uaccess.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/security.h>
+#include <linux/debugfs.h>
+#include "slim.h"
+
+static struct dentry *slim_sec_dir, *slim_level;
+
+static ssize_t slm_read_level(struct file *file, char __user *buf,
+			      size_t buflen, loff_t *ppos)
+{
+	struct slm_tsec_data *cur_tsec = current->security;
+	ssize_t len;
+	char data[28]; 
+	if (is_kernel_thread(current))
+		len = snprintf(data, sizeof(data), "KERNEL\n");
+	else if (!cur_tsec)
+		len = snprintf(data, sizeof(data), "UNKNOWN\n");
+	else {
+		if (cur_tsec->iac_wx != cur_tsec->iac_r)
+			len = snprintf(data, sizeof(data), "GUARD wx:%s r:%s\n",
+				      slm_iac_str[cur_tsec->iac_wx],
+				      slm_iac_str[cur_tsec->iac_r]);
+		else
Quoted 9 lines

security/slim/slm_secfs.c line 43

Quoted 5 lines
security/slim/slm_secfs.c +5 -0
+			len = snprintf(data, sizeof(data), "%s\n",
+				      slm_iac_str[cur_tsec->iac_wx]);
+	}
+	return simple_read_from_buffer(buf, buflen, ppos, data, len);
+}

Why do you need this when you implement getprocattr and return the same data that way?

True you can get the same info that way but we find it very useful to be able to cat this file and get the level of the current process.

Quoted 22 lines
Quoted 22 lines
security/slim/slm_secfs.c +22 -0
+
+static struct file_operations slm_level_ops = {
+	.read = slm_read_level,
+};
+
+int __init slm_init_secfs(void)
+{
+	if (!slim_enabled)
+		return 0;
+
+	slim_sec_dir = securityfs_create_dir("slim", NULL);
+	if (!slim_sec_dir || IS_ERR(slim_sec_dir))
+		return -EFAULT;
+	slim_level = securityfs_create_file("level", S_IRUGO,
+					    slim_sec_dir, NULL, &slm_level_ops);
+	if (!slim_level || IS_ERR(slim_level)) {
+		securityfs_remove(slim_sec_dir);
+		return -EFAULT;
+	}
+	return 0;
+}
+
Quoted 9 lines

security/slim/slm_secfs.c line 73

Quoted 8 lines
security/slim/slm_secfs.c +8 -0
+__initcall(slm_init_secfs);
+
+void __exit slm_cleanup_secfs(void)
+{
+	securityfs_remove(slim_level);
+	securityfs_remove(slim_sec_dir);
+}
+

Thanks,
Kylie

#3 lore raw
Quoted 1 line · Kylene Jo Hall
Quoted 1 line
Quoted 1 line

This patch provides the securityfs used by SLIM.

nitpick. (I never reviewed this when it was posted, but this followup caught my eye..)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
security/slim/slm_secfs.c +6 -0
@@ -0,0 +1,73 @@
+/*
+ * SLIM securityfs support: debugging control files
+ *
+ * Copyright (C) 2005, 2006 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *	   Kylene Hall <[email protected]>
Quoted 8 lines
Quoted 8 lines

security/slim/slm_secfs.c line 14

Quoted 8 lines
security/slim/slm_secfs.c +8 -0
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2 of the License.
+ */
+
+#include <asm/uaccess.h>
+#include <linux/config.h>

You don't need to include config.h any more, kbuild does it for you. (Might want to check the other files for the same thing).

Dave

#4 lore raw

PATCH 1/1 integrity: cleanup use of config.h

This patch addresses this comment about the use of config.h in the integrity .c files.

Quoted 4 lines · Dave Jones

You don't need to include config.h any more, kbuild does it for you. (Might want to check the other files for the same thing).

Dave

---

security/integrity.c       |    1 -
security/integrity_dummy.c |    1 -
2 files changed, 2 deletions(-)
security/integrity_dummy.c +0 -1
@@ -11,7 +11,6 @@
  *      the Free Software Foundation, version 2 of the License.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
security/integrity.c +0 -1
@@ -11,7 +11,6 @@
  *      the Free Software Foundation, version 2 of the License.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
#5 lore raw

PATCH 1/1 slim: cleanup use of config.h

In reply to Dave Jones

The following patch addresses this comment to clean up the use of config.h in the slim .c files.

Quoted 8 lines · Dave Jones
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+#include <asm/uaccess.h>
+#include <linux/config.h>

You don't need to include config.h any more, kbuild does it for you. (Might want to check the other files for the same thing).

Dave

---

security/slim/slm_main.c  |    1 -
security/slim/slm_secfs.c |    1 -
2 files changed, 2 deletions(-)
security/slim/slm_main.c +0 -1
@@ -11,7 +11,6 @@
  */
 
 #include <linux/mman.h>
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/security.h>
 #include <linux/integrity.h>
security/slim/slm_secfs.c +0 -1
@@ -11,7 +11,6 @@
  */
 
 #include <asm/uaccess.h>
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/security.h>
#6 lore raw
In reply to Kylene Jo Hall
Quoted 60 lines · Kylene Jo Hall
Quoted 50 lines · Stephen Smalley
Quoted 49 lines · Kylene Jo Hall

This patch provides the securityfs used by SLIM.

---

 security/slim/slm_secfs.c |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+)
security/slim/slm_secfs.c +38 -0
@@ -0,0 +1,73 @@
+/*
+ * SLIM securityfs support: debugging control files
+ *
+ * Copyright (C) 2005, 2006 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *	   Kylene Hall <[email protected]>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, version 2 of the License.
+ */
+
+#include <asm/uaccess.h>
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/security.h>
+#include <linux/debugfs.h>
+#include "slim.h"
+
+static struct dentry *slim_sec_dir, *slim_level;
+
+static ssize_t slm_read_level(struct file *file, char __user *buf,
+			      size_t buflen, loff_t *ppos)
+{
+	struct slm_tsec_data *cur_tsec = current->security;
+	ssize_t len;
+	char data[28]; 
+	if (is_kernel_thread(current))
+		len = snprintf(data, sizeof(data), "KERNEL\n");
+	else if (!cur_tsec)
+		len = snprintf(data, sizeof(data), "UNKNOWN\n");
+	else {
+		if (cur_tsec->iac_wx != cur_tsec->iac_r)
+			len = snprintf(data, sizeof(data), "GUARD wx:%s r:%s\n",
+				      slm_iac_str[cur_tsec->iac_wx],
+				      slm_iac_str[cur_tsec->iac_r]);
+		else
Quoted 9 lines

security/slim/slm_secfs.c line 43

Quoted 5 lines
security/slim/slm_secfs.c +5 -0
+			len = snprintf(data, sizeof(data), "%s\n",
+				      slm_iac_str[cur_tsec->iac_wx]);
+	}
+	return simple_read_from_buffer(buf, buflen, ppos, data, len);
+}

Why do you need this when you implement getprocattr and return the same data that way?

Quoted 2 lines

True you can get the same info that way but we find it very useful to be able to cat this file and get the level of the current process.

It is duplicated code and interface for no obvious purpose - why cannot you cat /proc/self/attr/current instead?

Signature · 2 lines
Stephen Smalley
National Security Agency