Smack: Assign smack_known_web label for kernel thread's socket in the sk_alloc_securi... 23/80723/2
authorjooseong lee <jooseong.lee@samsung.com>
Wed, 20 Jul 2016 01:07:11 +0000 (10:07 +0900)
committerjooseong lee <jooseong.lee@samsung.com>
Wed, 20 Jul 2016 01:48:06 +0000 (10:48 +0900)
Creating struct sock by sk_alloc function in various kernel subsystems
like bluetooth dosen't call smack_socket_post_create(). In such case,
received sock label is the floor('_') label and makes access deny.

Refers to:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7412301b76bd53ee53b860f611fc3b5b1c2245b5

Change-Id: I614c5f0e6d59be5ca6b49f0581edfef79fc334cf
Signed-off-by: jooseong lee <jooseong.lee@samsung.com>
security/smack/smack_lsm.c

index 4213de5..44731d3 100644 (file)
@@ -2312,8 +2312,16 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
        if (ssp == NULL)
                return -ENOMEM;
 
-       ssp->smk_in = skp;
-       ssp->smk_out = skp;
+       /*
+        * Sockets created by kernel threads receive web label.
+        */
+       if (unlikely(current->flags & PF_KTHREAD)) {
+               ssp->smk_in = &smack_known_web;
+               ssp->smk_out = &smack_known_web;
+       } else {
+               ssp->smk_in = skp;
+               ssp->smk_out = skp;
+       }
        ssp->smk_packet = NULL;
 
        sk->sk_security = ssp;