LSM/SELinux: {get,set}context hooks to access LSM security context information.
----- Original Message ----
Quoted 10 lines
From: David P. Quigley <[email protected]>
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; David P. Quigley <[email protected]>
Sent: Tuesday, March 4, 2008 1:53:43 PM
Subject: [PATCH 1/1] LSM/SELinux: {get,set}context hooks to access LSM security context information.This patch introduces two new hooks. One to get all relavent information from an LSM about an inode an the second given that context to set it on the inode. The setcontext call takes a flag to indicate if it should set the incore representation, the ondisk representation or both.
Please coordinate with David Powell and Ahmed Darwish on these. File system cacheing and audit both require similar functionality and have proposed it in slightly different manners and with slightly different names.
Quoted 199 lines
Signed-off-by David P. Quigley---
include/linux/security.h| 18 ++++++++++++++++++security/dummy.c| 12 ++++++++++++security/security.c| 12 ++++++++++++security/selinux/hooks.c| 45 ++++++++++++++++++++++++++++++++++++++++++++-4 files changed, 86 insertions(+), 1 deletions(-)include/linux/security.h +9
-0@@ -112,6 +112,10 @@ struct request_sock;#define LSM_UNSAFE_PTRACE 2#define LSM_UNSAFE_PTRACE_CAP 4 +/* Flags for setcontext */ +#define LSM_SETCORE 1 +#define LSM_SETDISK 2 +#ifdef CONFIG_SECURITY /** @@ -1395,6 +1399,9 @@ struct security_operations {int (*secctx_to_secid)(char *secdata,u32 seclen,u32 *secid);void (*release_secctx)(char *secdata,u32 seclen); +int (*setcontext)(struct dentry *dentry,void *ctx,u32 ctxlen,int flags); +int (*getcontext)(struct dentry *dentry,void **ctx,u32 *ctxlen); +#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct socket * sock,struct socket * other,struct sock * newsk);@@ -1634,6 +1641,8 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen); +int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags); +int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen);#else /* CONFIG_SECURITY */ /*
include/linux/security.h +9
-0@@ -2316,6 +2325,15 @@ static inline int security_secctx_to_secid(char *secdata,static inline void security_release_secctx (char *secdata,u32 seclen) { } + +static inline int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return -EOPNOTSUPP ; +} +static inline int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return -EOPNOTSUPP ; +}#endif /* CONFIG_SECURITY */ #ifdef
CONFIG_SECURITY_NETWORKsecurity/dummy.c +10
-0@@ -960,6 +960,16 @@ static void dummy_release_secctx(char *secdata, u32 seclen) { } +static int dummy_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return -EOPNOTSUPP ; +} + +static int dummy_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return -EOPNOTSUPP ; +} +#ifdef CONFIG_KEYS static inline int dummy_key_alloc(struct key *key, struct task_struct *ctx,unsigned long flags)
security/dummy.c +2
-0@@ -1118,6 +1128,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, secid_to_secctx);set_to_dummy_if_null (ops, secctx_to_secid);set_to_dummy_if_null (ops, release_secctx); +set_to_dummy_if_null (ops, setcontext); +set_to_dummy_if_null (ops, getcontext);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);set_to_dummy_if_null (ops, unix_may_send);security/security.c +12
-0@@ -845,6 +845,18 @@ void security_release_secctx(char *secdata, u32 seclen) }EXPORT_SYMBOL (security_release_secctx); +int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return security_ops->setcontext (dentry, ctx, ctxlen, flags); +} +EXPORT_SYMBOL (security_setcontext); + +int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return security_ops->getcontext (dentry, ctx, ctxlen); +} +EXPORT_SYMBOL (security_getcontext); +#ifdef CONFIG_SECURITY_NETWORK int security_unix_stream_connect(struct socket *sock, struct socket *other,
security/selinux/hooks.c +42
-0@@ -75,6 +75,7 @@ #include #include #include +#include#include "avc.h" #include "objsec.h" @@ -5163,6 +5164,47 @@ static void selinux_release_secctx(char *secdata, u32 seclen)kfree (secdata ); } +/* +* This hook requires that the inode i_mutex be locked +*/ +static int selinux_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +struct inode *inode = dentry->d_inode; +int rc =0 ; + +if (flags &LSM_SETCORE ) { + rc =selinux_inode_setsecurity (inode,XATTR_SELINUX_SUFFIX , + ctx, ctxlen,0 ); +if (rc) +return rc; + } +if (flags &LSM_SETDISK ) { + rc = -EOPNOTSUPP ; +if (inode->i_op->setxattr) { + rc = inode->i_op->setxattr (dentry,XATTR_NAME_SELINUX , ctx, ctxlen,0 ); +if (!rc) { +fsnotify_xattr (dentry); +security_inode_post_setxattr (dentry,XATTR_NAME_SELINUX , ctx, + ctxlen,0 ); + } + }else { + rc =security_inode_setsecurity (inode,XATTR_SELINUX_SUFFIX , ctx, + ctxlen,0 ); +if (!rc) +fsnotify_xattr (dentry); + } + } + +return rc; +} +static int selinux_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +struct inode *inode = dentry->d_inode; + + *ctxlen =selinux_inode_getsecurity (inode,XATTR_SELINUX_SUFFIX , + ctx, true); +return *ctxlen; +}#ifdef
CONFIG_KEYSstatic int selinux_key_alloc(struct key *k, struct
task_struct*tsk,security/selinux/hooks.c +2
-1@@ -5351,7 +5393,8 @@ static struct security_operations selinux_ops = { .secid_to_secctx = selinux_secid_to_secctx, .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx, - + .setcontext = selinux_setcontext, + .getcontext = selinux_getcontext, .unix_stream_connect = selinux_socket_unix_stream_connect, .unix_may_send = selinux_socket_unix_may_send,Signature · 8 lines
1.5.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Casey Schaufler
[email protected]
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
I don't see anything in Ahmed's patch set that has this kind of functionality. Also a quick glance over the patch names in the FSCache set doesn't seem to yield a hook like this either. David Howell's patches are mainly to deal with process contexts not file contexts which this patch addresses.
Dave
Quoted 211 lines · Casey Schaufler
----- Original Message ----
Quoted 10 lines
From: David P. Quigley <[email protected]>
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; David P. Quigley <[email protected]>
Sent: Tuesday, March 4, 2008 1:53:43 PM
Subject: [PATCH 1/1] LSM/SELinux: {get,set}context hooks to access LSM security context information.This patch introduces two new hooks. One to get all relavent information from an LSM about an inode an the second given that context to set it on the inode. The setcontext call takes a flag to indicate if it should set the incore representation, the ondisk representation or both.
Please coordinate with David Powell and Ahmed Darwish on these. File system cacheing and audit both require similar functionality and have proposed it in slightly different manners and with slightly different names.
Quoted 193 lines
Signed-off-by David P. Quigley---
include/linux/security.h| 18 ++++++++++++++++++security/dummy.c| 12 ++++++++++++security/security.c| 12 ++++++++++++security/selinux/hooks.c| 45 ++++++++++++++++++++++++++++++++++++++++++++-4 files changed, 86 insertions(+), 1 deletions(-)include/linux/security.h +9
-0@@ -112,6 +112,10 @@ struct request_sock;#define LSM_UNSAFE_PTRACE 2#define LSM_UNSAFE_PTRACE_CAP 4 +/* Flags for setcontext */ +#define LSM_SETCORE 1 +#define LSM_SETDISK 2 +#ifdef CONFIG_SECURITY /** @@ -1395,6 +1399,9 @@ struct security_operations {int (*secctx_to_secid)(char *secdata,u32 seclen,u32 *secid);void (*release_secctx)(char *secdata,u32 seclen); +int (*setcontext)(struct dentry *dentry,void *ctx,u32 ctxlen,int flags); +int (*getcontext)(struct dentry *dentry,void **ctx,u32 *ctxlen); +#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct socket * sock,struct socket * other,struct sock * newsk);@@ -1634,6 +1641,8 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen); +int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags); +int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen);#else /* CONFIG_SECURITY */ /*
include/linux/security.h +9
-0@@ -2316,6 +2325,15 @@ static inline int security_secctx_to_secid(char *secdata,static inline void security_release_secctx (char *secdata,u32 seclen) { } + +static inline int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return -EOPNOTSUPP ; +} +static inline int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return -EOPNOTSUPP ; +}#endif /* CONFIG_SECURITY */ #ifdef
CONFIG_SECURITY_NETWORKsecurity/dummy.c +10
-0@@ -960,6 +960,16 @@ static void dummy_release_secctx(char *secdata, u32 seclen) { } +static int dummy_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return -EOPNOTSUPP ; +} + +static int dummy_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return -EOPNOTSUPP ; +} +#ifdef CONFIG_KEYS static inline int dummy_key_alloc(struct key *key, struct task_struct *ctx,unsigned long flags)
security/dummy.c +2
-0@@ -1118,6 +1128,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, secid_to_secctx);set_to_dummy_if_null (ops, secctx_to_secid);set_to_dummy_if_null (ops, release_secctx); +set_to_dummy_if_null (ops, setcontext); +set_to_dummy_if_null (ops, getcontext);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);set_to_dummy_if_null (ops, unix_may_send);security/security.c +12
-0@@ -845,6 +845,18 @@ void security_release_secctx(char *secdata, u32 seclen) }EXPORT_SYMBOL (security_release_secctx); +int security_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +return security_ops->setcontext (dentry, ctx, ctxlen, flags); +} +EXPORT_SYMBOL (security_setcontext); + +int security_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +return security_ops->getcontext (dentry, ctx, ctxlen); +} +EXPORT_SYMBOL (security_getcontext); +#ifdef CONFIG_SECURITY_NETWORK int security_unix_stream_connect(struct socket *sock, struct socket *other,
security/selinux/hooks.c +42
-0@@ -75,6 +75,7 @@ #include #include #include +#include#include "avc.h" #include "objsec.h" @@ -5163,6 +5164,47 @@ static void selinux_release_secctx(char *secdata, u32 seclen)kfree (secdata ); } +/* +* This hook requires that the inode i_mutex be locked +*/ +static int selinux_setcontext (struct dentry *dentry,void *ctx,u32 ctxlen,int flags) +{ +struct inode *inode = dentry->d_inode; +int rc =0 ; + +if (flags &LSM_SETCORE ) { + rc =selinux_inode_setsecurity (inode,XATTR_SELINUX_SUFFIX , + ctx, ctxlen,0 ); +if (rc) +return rc; + } +if (flags &LSM_SETDISK ) { + rc = -EOPNOTSUPP ; +if (inode->i_op->setxattr) { + rc = inode->i_op->setxattr (dentry,XATTR_NAME_SELINUX , ctx, ctxlen,0 ); +if (!rc) { +fsnotify_xattr (dentry); +security_inode_post_setxattr (dentry,XATTR_NAME_SELINUX , ctx, + ctxlen,0 ); + } + }else { + rc =security_inode_setsecurity (inode,XATTR_SELINUX_SUFFIX , ctx, + ctxlen,0 ); +if (!rc) +fsnotify_xattr (dentry); + } + } + +return rc; +} +static int selinux_getcontext (struct dentry *dentry,void **ctx,u32 *ctxlen) +{ +struct inode *inode = dentry->d_inode; + + *ctxlen =selinux_inode_getsecurity (inode,XATTR_SELINUX_SUFFIX , + ctx, true); +return *ctxlen; +}#ifdef
CONFIG_KEYSstatic int selinux_key_alloc(struct key *k, struct
task_struct*tsk,security/selinux/hooks.c +2
-1@@ -5351,7 +5393,8 @@ static struct security_operations selinux_ops = { .secid_to_secctx = selinux_secid_to_secctx, .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx, - + .setcontext = selinux_setcontext, + .getcontext = selinux_getcontext, .unix_stream_connect = selinux_socket_unix_stream_connect, .unix_may_send = selinux_socket_unix_may_send,Signature · 1 line
1.5.4.1
Quoted 15 lines
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to [email protected]
More majordomo info at
http://vger.kernel.org/majordomo-info.htmlCasey Schaufler
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · * Dave Quigley ([email protected]) wrote:
I don't see anything in Ahmed's patch set that has this kind of functionality.
I suspect Casey's referring to the inode_getsec. I think you just need to be more clear about the requirements.
thanks,
-chris
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
The hook is inode_getsecid though. This hook is used to get a context which is the string representation of the security information which is different functionality.
Dave
Quoted 9 lines · Chris Wright
Quoted 2 lines · * Dave Quigley ([email protected]) wrote:
I don't see anything in Ahmed's patch set that has this kind of functionality.
I suspect Casey's referring to the
inode_getsec. I think you just need to be more clear about the requirements.thanks,
-chris
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Dave Quigley
The hook is
inode_getsecidthough. This hook is used to get a context which is the string representation of the security information which is different functionality.
The reason why this is needed instead of using inode_getsecurity is because Casey objected to a hook that allowed you to get the security suffix for inode_getsecurity. Because of this we added a hook that will allow a LSM to conglomerate all the security information it wants into one string and return it. The corresponding hook is used to take this information and then set it in the inode and on disk.
Dave
Quoted 11 lines
Dave
Quoted 7 lines · Chris Wright
Quoted 2 lines · * Dave Quigley ([email protected]) wrote:
I don't see anything in Ahmed's patch set that has this kind of functionality.
I suspect Casey's referring to the
inode_getsec. I think you just need to be more clear about the requirements.
Quoted 8 lines
Quoted 2 lines
thanks,
-chris--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.