binder: use cred instead of task for selinux checks
authorTodd Kjos <tkjos@google.com>
Wed, 10 Nov 2021 23:00:35 +0000 (15:00 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 13:03:36 +0000 (14:03 +0100)
commit0d9f4ae7cd6f5283dd0e343265268c695ef592b0
tree55a4fa71ccc0e8639c14d03986f2691a5fd48426
parentbd9cea41ac6e08f615030dea28b23e12b7a2674f
binder: use cred instead of task for selinux checks

commit 52f88693378a58094c538662ba652aff0253c4fe upstream.

Since binder was integrated with selinux, it has passed
'struct task_struct' associated with the binder_proc
to represent the source and target of transactions.
The conversion of task to SID was then done in the hook
implementations. It turns out that there are race conditions
which can result in an incorrect security context being used.

Fix by using the 'struct cred' saved during binder_open and pass
it to the selinux subsystem.

Cc: stable@vger.kernel.org # 5.14 (need backport for earlier stables)
Fixes: 79af73079d75 ("Add security hooks to binder and implement the hooks for SELinux.")
Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Todd Kjos <tkjos@google.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder.c
include/linux/lsm_hook_defs.h
include/linux/lsm_hooks.h
include/linux/security.h
security/security.c
security/selinux/hooks.c