kobject support for LSM core
PATCH 1/1 kobject support for LSM core
Hello,
the following patch (against 2.5.64) introduces kobject infrastructure
scaffolding to the LSM framework. It does nothing but allocating security root subsystem for the LSMs, so that they are tied to one specific point in the kobject hierarchy. They are suggested to create own subsystems under the security subsystem, however such things are completely up to the individual LSMs and not regulated by core in any way (it's not that I would so much like such an approach, but I was advised so by GregKH and it makes sense in its own way as well).
A lot of LSMs use various ad hoc methods for communication with the userspace
and using the sysfs framework could be very convient for them, and there is at least one real-world (altough yet a bit primitive) LSM which already uses the security subsystem: http://pasky.ji.cz/securitylevels/.
It works fine for me and it should be pretty trivial. Please consider
applying.
security/security.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+)
Kind regards,
Petr Baudis
security/security.c +30 -0
@@ -9,11 +9,15 @@* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. +* +* Introduced kobject infrastructure. +* 2003-02-27 Petr Baudis <[email protected]> */ #include <linux/config.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/kobject.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/security.h>
@@ -38,6 +42,7 @@return 0 ; } +/** * security_scaffolding_startup - initialzes the security scaffolding framework *
@@ -59,6 +64,30 @@return 0 ; } + +/* kobject stuff */ + +/* We define only the base subsystem here and leave everything to a LSM. It is +* heavily recommended that the LSM should create own subsystem under this one, +* so that it can be easily made stackable and it doesn't confuse userland by +* exporting its stuff directly to /sys/security/. */ +decl_subsys (security,NULL ); + +/** +* security_kobj_init - initializes the security kobject subsystem +* +* This is called after security_scaffolding_startup as a regular initcall, +* since we need sysfs mounted already. +*/ +static int __init security_kobj_init (void ) +{ +subsystem_register (&security_subsys); +return 0 ; +} + +subsys_initcall (security_kobj_init); + +/** * register_security - registers a security framework with the kernel * @ops: a pointer to the struct security_options that is to be registered
@@ -197,3 +226,4 @@EXPORT_SYMBOL_GPL (mod_unreg_security);EXPORT_SYMBOL (capable);EXPORT_SYMBOL (security_ops); +EXPORT_SYMBOL (security_subsys);
Quoted 9 lines · Petr Baudis
the following patch (against 2.5.64) introduces kobject infrastructure
scaffolding to the LSM framework. It does nothing but allocating security root subsystem for the LSMs, so that they are tied to one specific point in the kobject hierarchy. They are suggested to create own subsystems under the security subsystem, however such things are completely up to the individual LSMs and not regulated by core in any way (it's not that I would so much like such an approach, but I was advised so by GregKH and it makes sense in its own way as well).
Hm, I thought I advised not doing this at all :)
Anyway, if we were to add this, you might want to:
security/security.c line 74
Quoted 8 lines
security/security.c +8
-0+ +/* kobject stuff */ + +/* We define only the base subsystem here and leave everything to a LSM. It is +* heavily recommended that the LSM should create own subsystem under this one, +* so that it can be easily made stackable and it doesn't confuse userland by +* exporting its stuff directly to /sys/security/. */ +decl_subsys (security,NULL );
Add a prototype of this variable to security.h so that everyone can actually see it who wants to use it.
security/security.c line 88
Quoted 13 lines
security/security.c +13
-0+/** +* security_kobj_init - initializes the security kobject subsystem +* +* This is called after security_scaffolding_startup as a regular initcall, +* since we need sysfs mounted already. +*/ +static int __init security_kobj_init (void ) +{ +subsystem_register (&security_subsys); +return 0 ; +} + +subsys_initcall (security_kobj_init);
Why not initialize this when the security core is initialized? Why have a new initcall?
And when do you unregister this subsystem?
Quoted 1 line
+EXPORT_SYMBOL(security_subsys);
No EXPORT_SYMBOL_GPL() for it? :)
thanks,
greg k-h
PATCH 1/1 kobject support for LSM core (v2)
Dear diary, on Mon, Mar 10, 2003 at 07:47:38AM CET, I got a letter, where Greg KH <[email protected]> told me, that...
Quoted 11 lines · Petr Baudis
Quoted 9 lines
the following patch (against 2.5.64) introduces kobject infrastructure
scaffolding to the LSM framework. It does nothing but allocating security root subsystem for the LSMs, so that they are tied to one specific point in the kobject hierarchy. They are suggested to create own subsystems under the security subsystem, however such things are completely up to the individual LSMs and not regulated by core in any way (it's not that I would so much like such an approach, but I was advised so by GregKH and it makes sense in its own way as well).
Quoted 1 line
Hm, I thought I advised not doing this at all :)
*mumble* ;-)
Quoted 13 lines
Anyway, if we were to add this, you might want to:
Review
Quoted 8 lines
(quoted diff) +8
-0+ +/* kobject stuff */ + +/* We define only the base subsystem here and leave everything to a LSM. It is + * heavily recommended that the LSM should create own subsystem under this one, + * so that it can be easily made stackable and it doesn't confuse userland by + * exporting its stuff directly to /sys/security/. */ +decl_subsys(security,NULL);Add a prototype of this variable to
security.hso that everyone can actually see it who wants to use it.
Oops, I accidentally missed that file when diffing, sorry.
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+/** + * security_kobj_init - initializes the security kobject subsystem + * + * This is called after security_scaffolding_startup as a regular initcall, + * since we need sysfs mounted already. + */ +static int __init security_kobj_init (void) +{
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ subsystem_register (&security_subsys); + return 0; +} + +subsys_initcall(security_kobj_init);Why not initialize this when the security core is initialized? Why have a new initcall?
See the comment before the function:
+ * since we need sysfs mounted already.
At the time of security_scaffolding_setup(), sysfs is not mounted yet, thus subsystem_register() returns -EFAULT and is unsuccessful.
Quoted 1 line
And when do you unregister this subsystem?
Never ;-). Well it appears that there is no need to unregister it explicitly, at least noone else does it (subsystem_unregister() is called only for dynamically registered subsystems). If you insist on having it there, I can add it, but we are following the current way of doing things with leaving it out.
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(security_subsys);
No
EXPORT_SYMBOL_GPL()for it? :)
True, fixed.
The second version of the patch follows...
Hello,
the following patch (against 2.5.64) introduces kobject infrastructure
scaffolding to the LSM framework. It does nothing but allocating security root subsystem for the LSMs, so that they are tied to one specific point in the kobject hierarchy. They are suggested to create own subsystems under the security subsystem, however such things are completely up to the individual LSMs and not regulated by core in any way (it's not that I would so much like such an approach, but I was advised so by GregKH and it makes sense in its own way as well).
A lot of LSMs use various ad hoc methods for communication with the userspace
and using the sysfs framework could be very convient for them, and there is at least one real-world (altough yet a bit primitive) LSM which already uses the security subsystem: http://pasky.ji.cz/securitylevels/.
It works fine for me and it should be pretty trivial. Please consider
applying.
include/linux/security.h | 2 ++ security/security.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
Note that this is the second version of the patch, containing changes based
on GregKH's remarks. It fixes missing patch for include/linux/security.h and exports security_subsys GPL'd.
Kind regards,
Petr Baudis
security/security.c +30 -0
@@ -9,11 +9,15 @@* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. +* +* Introduced kobject infrastructure. +* 2003-02-27 Petr Baudis <[email protected]> */ #include <linux/config.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/kobject.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/security.h>
@@ -38,6 +42,7 @@return 0 ; } +/** * security_scaffolding_startup - initialzes the security scaffolding framework *
@@ -59,6 +64,30 @@return 0 ; } + +/* kobject stuff */ + +/* We define only the base subsystem here and leave everything to a LSM. It is +* heavily recommended that the LSM should create own subsystem under this one, +* so that it can be easily made stackable and it doesn't confuse userland by +* exporting its stuff directly to /sys/security/. */ +decl_subsys (security,NULL ); + +/** +* security_kobj_init - initializes the security kobject subsystem +* +* This is called after security_scaffolding_startup as a regular initcall, +* since we need sysfs mounted already. +*/ +static int __init security_kobj_init (void ) +{ +subsystem_register (&security_subsys); +return 0 ; +} + +subsys_initcall (security_kobj_init); + +/** * register_security - registers a security framework with the kernel * @ops: a pointer to the struct security_options that is to be registered
@@ -195,5 +224,6 @@EXPORT_SYMBOL_GPL (unregister_security);EXPORT_SYMBOL_GPL (mod_reg_security);EXPORT_SYMBOL_GPL (mod_unreg_security); +EXPORT_SYMBOL_GPL (security_subsys);EXPORT_SYMBOL (capable);EXPORT_SYMBOL (security_ops);
include/linux/security.h +2 -0
@@ -22,6 +22,7 @@#ifndef __LINUX_SECURITY_H#define __LINUX_SECURITY_H +#include <linux/kobject.h> #include <linux/fs.h> #include <linux/binfmts.h> #include <linux/signal.h>
@@ -1745,6 +1746,7 @@extern int unregister_security (struct security_operations *ops);extern int mod_reg_security (const char *name,struct security_operations *ops);extern int mod_unreg_security (const char *name,struct security_operations *ops); +extern struct subsystem security_subsys;#else /* CONFIG_SECURITY */
Re: [PATCH] kobject support for LSM core (v2)
Quoted 1 line · Petr Baudis
The second version of the patch follows...
Much nicer, and I would agree to add this patch to the kernel, if there was actually a user for it :)
Mind converting one of the exsting LSM modules to use this sysfs subsystem?
thanks,
greg k-h
Re: [PATCH] kobject support for LSM core (v2)
In reply to Petr BaudisQuoted 3 lines · * Petr Baudis ([email protected]) wrote:
At the time of
security_scaffolding_setup(), sysfs is not mounted yet, thussubsystem_register()returns-EFAULTand is unsuccessful.
yup, same problem with the early init patch.
Quoted 2 lines
A lot of LSMs use various ad hoc methods for communication with the userspace
and using the sysfs framework could be very convient for them, and there is at
This would be more compelling if you could convert something in the LSM tree to using it. Right now, this patch just adds something that is not clearly needed. What about converting DTE to use this new subsystem?
thanks,
-chris
Signature · 1 line
Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net