A sealable memory allocator patch was proposed at
http://lkml.kernel.org/r/20170519103811.2183-1-igor.stoppa at huawei.com ,
and is waiting for a follow-on patch showing how any of the kernel
can be changed to use this new subsystem. So, here it is for LSM hooks.
The LSM hooks ("struct security_hook_heads security_hook_heads" and
"struct security_hook_list ...[]") will benefit from this allocator via
protection using set_memory_ro()/set_memory_rw(), and it will remove
CONFIG_SECURITY_WRITABLE_HOOKS config option.
This means that these structures will be allocated at run time using
smalloc(), and therefore the address of these structures will be
determined at run time rather than compile time.
But currently, LSM_HOOK_INIT() macro depends on the address of
security_hook_heads being known at compile time. But we already
initialize security_hook_heads as an array of "struct list_head".
Therefore, let's use index number (or relative offset from the head
of security_hook_heads) instead of absolute address of
security_hook_heads so that LSM_HOOK_INIT() macro does not need to
know absolute address of security_hook_heads. Then, security_add_hooks()
will be able to allocate and copy "struct security_hook_list ...[]" using
smalloc().
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Kees Cook <redacted>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Cc: Igor Stoppa <redacted>
Cc: Greg KH <gregkh@linuxfoundation.org>
---
include/linux/lsm_hooks.h | 6 +++---
security/security.c | 10 ++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
@@ -33,7 +33,7 @@/* Maximum number of letters for an LSM name string */#define SECURITY_NAME_MAX 10-structsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;+staticstructsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;char*lsm_names;/* Boot-time LSM user choice */static__initdatacharchosen_lsm[SECURITY_NAME_MAX+1]=
@@ -152,10 +152,16 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,char*lsm){inti;+structlist_head*list=(structlist_head*)&security_hook_heads;for(i=0;i<count;i++){+constunsignedintidx=hooks[i].idx;++if(WARN_ON(idx>=sizeof(security_hook_heads)/+sizeof(structlist_head)))+continue;hooks[i].lsm=lsm;-list_add_tail_rcu(&hooks[i].list,hooks[i].head);+list_add_tail_rcu(&hooks[i].list,&list[idx]);}if(lsm_append(lsm,&lsm_names)<0)panic("%s - Cannot get early memory.\n",__func__);
--
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@ http://vger.kernel.org/majordomo-info.html
From: Christoph Hellwig <hch@infradead.org> Date: 2017-05-22 14:03:44
On Sun, May 21, 2017 at 08:14:05PM +0900, Tetsuo Handa wrote:
quoted hunk
A sealable memory allocator patch was proposed at
http://lkml.kernel.org/r/20170519103811.2183-1-igor.stoppa at huawei.com ,
and is waiting for a follow-on patch showing how any of the kernel
can be changed to use this new subsystem. So, here it is for LSM hooks.
The LSM hooks ("struct security_hook_heads security_hook_heads" and
"struct security_hook_list ...[]") will benefit from this allocator via
protection using set_memory_ro()/set_memory_rw(), and it will remove
CONFIG_SECURITY_WRITABLE_HOOKS config option.
This means that these structures will be allocated at run time using
smalloc(), and therefore the address of these structures will be
determined at run time rather than compile time.
But currently, LSM_HOOK_INIT() macro depends on the address of
security_hook_heads being known at compile time. But we already
initialize security_hook_heads as an array of "struct list_head".
Therefore, let's use index number (or relative offset from the head
of security_hook_heads) instead of absolute address of
security_hook_heads so that LSM_HOOK_INIT() macro does not need to
know absolute address of security_hook_heads. Then, security_add_hooks()
will be able to allocate and copy "struct security_hook_list ...[]" using
smalloc().
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Kees Cook <redacted>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Cc: Igor Stoppa <redacted>
Cc: Greg KH <gregkh@linuxfoundation.org>
---
include/linux/lsm_hooks.h | 6 +++---
security/security.c | 10 ++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
@@ -33,7 +33,7 @@/* Maximum number of letters for an LSM name string */#define SECURITY_NAME_MAX 10-structsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;+staticstructsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;char*lsm_names;/* Boot-time LSM user choice */static__initdatacharchosen_lsm[SECURITY_NAME_MAX+1]=
Eww, struct casts. This whole security_hook_heads scheme stink,
even with the slight improvements from Tetsuo. It has everything we
shouldn't do - function pointers in structures that are not hard
read-only, structure casts, etc.
What's the reason why can't just have good old const function tables?
Yeah, stackable LSM make that a little harder, but they should not be
enable by default anyway. But even with those we can still chain
them together with a list with external linkage.
--
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
On Sun, May 21, 2017 at 08:14:05PM +0900, Tetsuo Handa wrote:
quoted
A sealable memory allocator patch was proposed at
http://lkml.kernel.org/r/20170519103811.2183-1-igor.stoppa at huawei.com ,
and is waiting for a follow-on patch showing how any of the kernel
can be changed to use this new subsystem. So, here it is for LSM hooks.
The LSM hooks ("struct security_hook_heads security_hook_heads" and
"struct security_hook_list ...[]") will benefit from this allocator via
protection using set_memory_ro()/set_memory_rw(), and it will remove
CONFIG_SECURITY_WRITABLE_HOOKS config option.
This means that these structures will be allocated at run time using
smalloc(), and therefore the address of these structures will be
determined at run time rather than compile time.
But currently, LSM_HOOK_INIT() macro depends on the address of
security_hook_heads being known at compile time. But we already
initialize security_hook_heads as an array of "struct list_head".
Therefore, let's use index number (or relative offset from the head
of security_hook_heads) instead of absolute address of
security_hook_heads so that LSM_HOOK_INIT() macro does not need to
know absolute address of security_hook_heads. Then, security_add_hooks()
will be able to allocate and copy "struct security_hook_list ...[]" using
smalloc().
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Kees Cook <redacted>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Cc: Igor Stoppa <redacted>
Cc: Greg KH <gregkh@linuxfoundation.org>
---
include/linux/lsm_hooks.h | 6 +++---
security/security.c | 10 ++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)
@@ -33,7 +33,7 @@/* Maximum number of letters for an LSM name string */#define SECURITY_NAME_MAX 10-structsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;+staticstructsecurity_hook_headssecurity_hook_heads__lsm_ro_after_init;char*lsm_names;/* Boot-time LSM user choice */static__initdatacharchosen_lsm[SECURITY_NAME_MAX+1]=
Eww, struct casts. This whole security_hook_heads scheme stink,
even with the slight improvements from Tetsuo. It has everything we
shouldn't do - function pointers in structures that are not hard
read-only, structure casts, etc.
What's the reason why can't just have good old const function tables?
The set of hooks used by most security modules are sparse.
Yeah, stackable LSM make that a little harder, but they should not be
enable by default anyway.
With the number of security modules queued up behind full stacking
I can't say that I agree with your assertion.
But even with those we can still chain
them together with a list with external linkage.
I gave up that approach in 2012. Too many unnecessary calls to
null functions, and massive function vectors with a tiny number
of non-null entries. From a data structure standpoint, it was
just wrong. The list scheme is exactly right for the task at
hand.
--
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
--
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
From: Igor Stoppa <hidden> Date: 2017-05-22 19:51:27
On 22/05/17 18:09, Casey Schaufler wrote:
On 5/22/2017 7:03 AM, Christoph Hellwig wrote:
[...]
quoted
But even with those we can still chain
them together with a list with external linkage.
I gave up that approach in 2012. Too many unnecessary calls to
null functions, and massive function vectors with a tiny number
of non-null entries. From a data structure standpoint, it was
just wrong. The list scheme is exactly right for the task at
hand.
I understand this as a green light, for me to continue with the plan of
using LSM Hooks as example for making dynamically allocated data become
read-only, using also Tetsuo's patch (thanks, btw).
Is that correct?
---
thanks, igor
--
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
But even with those we can still chain
them together with a list with external linkage.
I gave up that approach in 2012. Too many unnecessary calls to
null functions, and massive function vectors with a tiny number
of non-null entries. From a data structure standpoint, it was
just wrong. The list scheme is exactly right for the task at
hand.
I understand this as a green light, for me to continue with the plan of
using LSM Hooks as example for making dynamically allocated data become
read-only, using also Tetsuo's patch (thanks, btw).
I still don't like the assumption that a structure of
N elements can be assumed to be the same as an array
of N elements. Putting on my hardening hat, however, I
like the smalloc() solution to keeping the hook lists
safe, so I am willing to swallow the objection to using
offsets to address the existing exposure.
Is that correct?
---
thanks, igor
--
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
--
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
But even with those we can still chain
them together with a list with external linkage.
I gave up that approach in 2012. Too many unnecessary calls to
null functions, and massive function vectors with a tiny number
of non-null entries. From a data structure standpoint, it was
just wrong. The list scheme is exactly right for the task at
hand.
I understand this as a green light, for me to continue with the plan of
using LSM Hooks as example for making dynamically allocated data become
read-only, using also Tetsuo's patch (thanks, btw).
I still don't like the assumption that a structure of
N elements can be assumed to be the same as an array
of N elements.
I think we can use "enum" and call via index numbers while preserving
current "union" for type checking purpose.
--
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