Commit 8e531af9 authored by Eric Paris's avatar Eric Paris Committed by James Morris

SELinux: memory leak in security_context_to_sid_core

Fix a bug and a philosophical decision about who handles errors.

security_context_to_sid_core() was leaking a context in the common case.
This was causing problems on fedora systems which recently have started
making extensive use of this function.

In discussion it was decided that if string_to_context_struct() had an
error it was its own responsibility to clean up any mess it created
along the way.
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
Acked-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent ec0c15af
...@@ -811,11 +811,12 @@ static int string_to_context_struct(struct policydb *pol, ...@@ -811,11 +811,12 @@ static int string_to_context_struct(struct policydb *pol,
/* Check the validity of the new context. */ /* Check the validity of the new context. */
if (!policydb_context_isvalid(pol, ctx)) { if (!policydb_context_isvalid(pol, ctx)) {
rc = -EINVAL; rc = -EINVAL;
context_destroy(ctx);
goto out; goto out;
} }
rc = 0; rc = 0;
out: out:
if (rc)
context_destroy(ctx);
return rc; return rc;
} }
...@@ -868,7 +869,6 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len, ...@@ -868,7 +869,6 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
} else if (rc) } else if (rc)
goto out; goto out;
rc = sidtab_context_to_sid(&sidtab, &context, sid); rc = sidtab_context_to_sid(&sidtab, &context, sid);
if (rc)
context_destroy(&context); context_destroy(&context);
out: out:
read_unlock(&policy_rwlock); read_unlock(&policy_rwlock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment