Skip to contentSkip to conversation

Smack: Don't register smackfs if we're not loaded

PATCH Casey Schaufler 1 participant 1 message Mar 4, 2008

lore
Share & tools
lore

Casey Schaufler

author Acked-by
#0 lore raw

----- Original Message ----

Quoted 8 lines

From: Ahmed S. Darwish <[email protected]>
To: Casey Schaufler <[email protected]>
Cc: LKML <[email protected]>; Linus <[email protected]>
Sent: Tuesday, March 4, 2008 5:10:55 AM
Subject: [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded

Hi all,

Quoted 8 lines

Smackfs initialization without an enabled Smack leads to an early Oops that renders the system unusable.

Introduce a global smack_enabled variable that will be used to make sure that no smack components will be registered (ala smackfs) if we are not already enabled.

Signed-off-by Ahmed S. Darwish
Quoted 90 lines

---

The Oops is triggered by the security= patch that will be sent soon.

I can't imagine an SELinux guru finding /smackfs instead of his usual /selinuxfs when he hits a tab completion after 's' ;). As a bonus, this patch will handle that case too.

smack.h | 9 +++++++++
smack_lsm.c | 8 ++++++++
smackfs.c | 3 +++

3 files changed, 20 insertions(+)
security/smack/smack.h +9 -0
index a21a0e9..17c55ad 100644
@@ -18,6 +18,15 @@
 #include 
 
 /*
+ * We must not bother the rest of the kernel by exporting our
+ * own stuff if we are not already enabled. We may not be loaded
+ * if another or no LSM was chosen on boot.
+ * Smackfs is currently the only exported component, but this
+ * may change in the future.
+ */
+extern int smack_enabled;
+
+/*
 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
 * bigger than can be used, and 24 is the next lower multiple
 * of 8, and there are too many issues if there isn't space set
security/smack/smack_lsm.c +8 -0
index 770eb06..6fe7869 100644
@@ -36,6 +36,8 @@
 #define SOCKFS_MAGIC 0x534F434B
 #define TMPFS_MAGIC 0x01021994
 
+int smack_enabled;
+
 /**
 * smk_fetch - Fetch the smack label from a file.
 * @ip: a pointer to the inode
@@ -2589,6 +2591,12 @@ static __init int smack_init(void)
 if (register_security(&smack_ops))
 panic("smack: Unable to register with kernel.\n");
 
+ /*
+ * Notify other Smack components that it's now safe to
+ * to register themselves.
+ */
+ smack_enabled = 1;
+
 return 0;
 }
 
security/smack/smackfs.c +3 -0
index 358c92c..e1687c0 100644
@@ -992,6 +992,9 @@ static int __init init_smk_fs(void)
 {
 int err;
 
+ if (!smack_enabled)
+ return 0;
+
 err = register_filesystem(&smk_fs_type);
 if (!err) {
 smackfs_mount = kern_mount(&smk_fs_type);
Signature · 14 lines
-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at 
http://www.tux.org/lkml/

Casey Schaufler
[email protected]