[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.00.1103212215230.23432@swampdragon.chaosbits.net>
Date: Mon, 21 Mar 2011 22:23:57 +0100 (CET)
From: Jesper Juhl <jj@...osbits.net>
To: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
cc: Justin Mattock <justinmattock@...il.com>,
Stephen Smalley <sds@...ho.nsa.gov>,
James Morris <jmorris@...ei.org>,
Eric Paris <eparis@...isplace.org>,
linux-security-module@...r.kernel.org
Subject: [PATCH][RFC] Null short-circuit for selinux_cred_free()
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@...osbits.net>
---
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@...osbits.net> 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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists