diff options
| -rw-r--r-- | include/linux/security.h | 6 | ||||
| -rw-r--r-- | security/selinux/ss/services.c | 11 | ||||
| -rw-r--r-- | security/smack/smack_lsm.c | 3 |
3 files changed, 16 insertions, 4 deletions
diff --git a/include/linux/security.h b/include/linux/security.h index d70adc394f62..b8246a8df7d2 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
| @@ -1285,9 +1285,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
| 1285 | * Return 0 if permission is granted. | 1285 | * Return 0 if permission is granted. |
| 1286 | * | 1286 | * |
| 1287 | * @secid_to_secctx: | 1287 | * @secid_to_secctx: |
| 1288 | * Convert secid to security context. | 1288 | * Convert secid to security context. If secdata is NULL the length of |
| 1289 | * the result will be returned in seclen, but no secdata will be returned. | ||
| 1290 | * This does mean that the length could change between calls to check the | ||
| 1291 | * length and the next call which actually allocates and returns the secdata. | ||
| 1289 | * @secid contains the security ID. | 1292 | * @secid contains the security ID. |
| 1290 | * @secdata contains the pointer that stores the converted security context. | 1293 | * @secdata contains the pointer that stores the converted security context. |
| 1294 | * @seclen pointer which contains the length of the data | ||
| 1291 | * @secctx_to_secid: | 1295 | * @secctx_to_secid: |
| 1292 | * Convert security context to secid. | 1296 | * Convert security context to secid. |
| 1293 | * @secid contains the pointer to the generated security ID. | 1297 | * @secid contains the pointer to the generated security ID. |
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 494ff527c174..60964d79e5eb 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; |
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 174aec44bfac..bc39f4067af6 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
| @@ -3004,7 +3004,8 @@ static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) | |||
| 3004 | { | 3004 | { |
| 3005 | char *sp = smack_from_secid(secid); | 3005 | char *sp = smack_from_secid(secid); |
| 3006 | 3006 | ||
| 3007 | *secdata = sp; | 3007 | if (secdata) |
| 3008 | *secdata = sp; | ||
| 3008 | *seclen = strlen(sp); | 3009 | *seclen = strlen(sp); |
| 3009 | return 0; | 3010 | return 0; |
| 3010 | } | 3011 | } |
