diff options
author | Paul Moore <paul.moore@hp.com> | 2008-10-10 10:16:30 -0400 |
---|---|---|
committer | Paul Moore <paul.moore@hp.com> | 2008-10-10 10:16:30 -0400 |
commit | 99d854d231ce141850b988bdc7e2e7c78f49b03a (patch) | |
tree | d9da2a23471f38f6b25ec2bcfe982622ee51adba /security | |
parent | d8395c876bb8a560c8a032887e191b95499a25d6 (diff) |
selinux: Fix a problem in security_netlbl_sid_to_secattr()
Currently when SELinux fails to allocate memory in
security_netlbl_sid_to_secattr() the NetLabel LSM domain field is set to
NULL which triggers the default NetLabel LSM domain mapping which may not
always be the desired mapping. This patch fixes this by returning an error
when the kernel is unable to allocate memory. This could result in more
failures on a system with heavy memory pressure but it is the "correct"
thing to do.
Signed-off-by: Paul Moore <paul.moore@hp.com>
Acked-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security')
-rw-r--r-- | security/selinux/ss/services.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 8551952ef329..c8f688a10041 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c | |||
@@ -2785,7 +2785,7 @@ netlbl_secattr_to_sid_return_cleanup: | |||
2785 | */ | 2785 | */ |
2786 | int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr) | 2786 | int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr) |
2787 | { | 2787 | { |
2788 | int rc = -ENOENT; | 2788 | int rc; |
2789 | struct context *ctx; | 2789 | struct context *ctx; |
2790 | 2790 | ||
2791 | if (!ss_initialized) | 2791 | if (!ss_initialized) |
@@ -2793,10 +2793,16 @@ int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr) | |||
2793 | 2793 | ||
2794 | read_lock(&policy_rwlock); | 2794 | read_lock(&policy_rwlock); |
2795 | ctx = sidtab_search(&sidtab, sid); | 2795 | ctx = sidtab_search(&sidtab, sid); |
2796 | if (ctx == NULL) | 2796 | if (ctx == NULL) { |
2797 | rc = -ENOENT; | ||
2797 | goto netlbl_sid_to_secattr_failure; | 2798 | goto netlbl_sid_to_secattr_failure; |
2799 | } | ||
2798 | secattr->domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1], | 2800 | secattr->domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1], |
2799 | GFP_ATOMIC); | 2801 | GFP_ATOMIC); |
2802 | if (secattr->domain == NULL) { | ||
2803 | rc = -ENOMEM; | ||
2804 | goto netlbl_sid_to_secattr_failure; | ||
2805 | } | ||
2800 | secattr->flags |= NETLBL_SECATTR_DOMAIN_CPY; | 2806 | secattr->flags |= NETLBL_SECATTR_DOMAIN_CPY; |
2801 | mls_export_netlbl_lvl(ctx, secattr); | 2807 | mls_export_netlbl_lvl(ctx, secattr); |
2802 | rc = mls_export_netlbl_cat(ctx, secattr); | 2808 | rc = mls_export_netlbl_cat(ctx, secattr); |