linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] Null short-circuit for selinux_cred_free()
@ 2011-03-21 21:23 Jesper Juhl
  2011-03-23  3:51 ` Tetsuo Handa
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2011-03-21 21:23 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: Justin Mattock, Stephen Smalley, James Morris, Eric Paris,
	linux-security-module

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@chaosbits.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@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] Null short-circuit for selinux_cred_free()
  2011-03-21 21:23 [PATCH][RFC] Null short-circuit for selinux_cred_free() Jesper Juhl
@ 2011-03-23  3:51 ` Tetsuo Handa
  2011-03-23 21:07   ` Jesper Juhl
  0 siblings, 1 reply; 3+ messages in thread
From: Tetsuo Handa @ 2011-03-23  3:51 UTC (permalink / raw)
  To: jj; +Cc: linux-security-module, linux-kernel

Jesper Juhl wrote:
> Let selinux_cred_free accept NULL pointers.
No need to do so.

> 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.
If cred == NULL, put_cred_rcu(NULL) causes the kernel to panic before calling
LSM hooks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] Null short-circuit for selinux_cred_free()
  2011-03-23  3:51 ` Tetsuo Handa
@ 2011-03-23 21:07   ` Jesper Juhl
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Juhl @ 2011-03-23 21:07 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: linux-security-module, linux-kernel

On Wed, 23 Mar 2011, Tetsuo Handa wrote:

> Jesper Juhl wrote:
> > Let selinux_cred_free accept NULL pointers.
> No need to do so.
> 
> > 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.
> If cred == NULL, put_cred_rcu(NULL) causes the kernel to panic before calling
> LSM hooks.

Good point. Thanks.

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-23 21:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-21 21:23 [PATCH][RFC] Null short-circuit for selinux_cred_free() Jesper Juhl
2011-03-23  3:51 ` Tetsuo Handa
2011-03-23 21:07   ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).