aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/ss/services.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 494ff527c17..60964d79e5e 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -991,7 +991,8 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
991{ 991{
992 char *scontextp; 992 char *scontextp;
993 993
994 *scontext = NULL; 994 if (scontext)
995 *scontext = NULL;
995 *scontext_len = 0; 996 *scontext_len = 0;
996 997
997 if (context->len) { 998 if (context->len) {
@@ -1008,6 +1009,9 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
1008 *scontext_len += strlen(policydb.p_type_val_to_name[context->type - 1]) + 1; 1009 *scontext_len += strlen(policydb.p_type_val_to_name[context->type - 1]) + 1;
1009 *scontext_len += mls_compute_context_len(context); 1010 *scontext_len += mls_compute_context_len(context);
1010 1011
1012 if (!scontext)
1013 return 0;
1014
1011 /* Allocate space for the context; caller must free this space. */ 1015 /* Allocate space for the context; caller must free this space. */
1012 scontextp = kmalloc(*scontext_len, GFP_ATOMIC); 1016 scontextp = kmalloc(*scontext_len, GFP_ATOMIC);
1013 if (!scontextp) 1017 if (!scontextp)
@@ -1047,7 +1051,8 @@ static int security_sid_to_context_core(u32 sid, char **scontext,
1047 struct context *context; 1051 struct context *context;
1048 int rc = 0; 1052 int rc = 0;
1049 1053
1050 *scontext = NULL; 1054 if (scontext)
1055 *scontext = NULL;
1051 *scontext_len = 0; 1056 *scontext_len = 0;
1052 1057
1053 if (!ss_initialized) { 1058 if (!ss_initialized) {
@@ -1055,6 +1060,8 @@ static int security_sid_to_context_core(u32 sid, char **scontext,
1055 char *scontextp; 1060 char *scontextp;
1056 1061
1057 *scontext_len = strlen(initial_sid_to_string[sid]) + 1; 1062 *scontext_len = strlen(initial_sid_to_string[sid]) + 1;
1063 if (!scontext)
1064 goto out;
1058 scontextp = kmalloc(*scontext_len, GFP_ATOMIC); 1065 scontextp = kmalloc(*scontext_len, GFP_ATOMIC);
1059 if (!scontextp) { 1066 if (!scontextp) {
1060 rc = -ENOMEM; 1067 rc = -ENOMEM;