Skip to content

Commit

Permalink
SELinux: memory leak in security_context_to_sid_core
Browse files Browse the repository at this point in the history
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: Eric Paris <eparis@redhat.com>
Acked-by:  Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
eparis authored and James Morris committed Sep 3, 2008
1 parent ec0c15a commit 8e531af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,12 @@ static int string_to_context_struct(struct policydb *pol,
/* Check the validity of the new context. */
if (!policydb_context_isvalid(pol, ctx)) {
rc = -EINVAL;
context_destroy(ctx);
goto out;
}
rc = 0;
out:
if (rc)
context_destroy(ctx);
return rc;
}

Expand Down Expand Up @@ -868,8 +869,7 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
} else if (rc)
goto out;
rc = sidtab_context_to_sid(&sidtab, &context, sid);
if (rc)
context_destroy(&context);
context_destroy(&context);
out:
read_unlock(&policy_rwlock);
kfree(scontext2);
Expand Down

0 comments on commit 8e531af

Please sign in to comment.