CRED: Fix BUG() upon security_cred_alloc_blank() failure
commit4c96bf3813d214d511fc8d14287868ec9f06ab9b
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Mon, 7 Feb 2011 13:36:10 +0000 (7 13:36 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 24 Feb 2011 22:54:28 +0000 (24 14:54 -0800)
tree770c5fc0998dcae177caf7df16fdb056d0f67d0b
parent05b3244cf2cfabcb523583cd3c1161d870e70898
CRED: Fix BUG() upon security_cred_alloc_blank() failure

commit 2edeaa34a6e3f2c43b667f6c4f7b27944b811695 upstream.

In cred_alloc_blank() since 2.6.32, abort_creds(new) is called with
new->security == NULL and new->magic == 0 when security_cred_alloc_blank()
returns an error.  As a result, BUG() will be triggered if SELinux is enabled
or CONFIG_DEBUG_CREDENTIALS=y.

If CONFIG_DEBUG_CREDENTIALS=y, BUG() is called from __invalid_creds() because
cred->magic == 0.  Failing that, BUG() is called from selinux_cred_free()
because selinux_cred_free() is not expecting cred->security == NULL.  This does
not affect smack_cred_free(), tomoyo_cred_free() or apparmor_cred_free().

Fix these bugs by

(1) Set new->magic before calling security_cred_alloc_blank().

(2) Handle null cred->security in creds_are_invalid() and selinux_cred_free().

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
kernel/cred.c
security/selinux/hooks.c