[PATCH][RFC] Null short-circuit for selinux_cred_free()

From: Jesper Juhl
Date: Mon Mar 21 2011 - 17:24:17 EST


Let selinux_cred_free accept NULL pointers.
If we don't do this, then we can crash if someone manages to pass NULL to
cred_free. Seems to me it's better to just do nothing in that case rather
than crash.

Signed-off-by: Jesper Juhl <jj@xxxxxxxxxxxxx>
---
hooks.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6475e1f..d2216cf 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3232,13 +3232,16 @@ static int selinux_cred_alloc_blank(struct cred *cred, gfp_t gfp)
*/
static void selinux_cred_free(struct cred *cred)
{
- struct task_security_struct *tsec = cred->security;
+ struct task_security_struct *tsec;

+ if (!cred)
+ return;
/*
* cred->security == NULL if security_cred_alloc_blank() or
* security_prepare_creds() returned an error.
*/
- BUG_ON(cred->security && (unsigned long) cred->security < PAGE_SIZE);
+ BUG_ON(cred->security && (unsigned long)cred->security < PAGE_SIZE);
+ tsec = cred->security;
cred->security = (void *) 0x7UL;
kfree(tsec);
}


--
Jesper Juhl <jj@xxxxxxxxxxxxx> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/