Smack: secmark connections 12/68312/2
authorCasey Schaufler <casey@schaufler-ca.com>
Tue, 26 Apr 2016 07:40:01 +0000 (16:40 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 25 Aug 2016 05:01:10 +0000 (22:01 -0700)
If the secmark is available us it on connection as
well as packet delivery.

Change-Id: I570e750dc3753908f361b894c470784ec00a468e
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
security/smack/smack_lsm.c

index d2a13f9..a7f2b5b 100644 (file)
@@ -3930,6 +3930,18 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
        }
 #endif /* CONFIG_IPV6 */
 
+#ifdef CONFIG_SECURITY_SMACK_NETFILTER
+       /*
+        * If there is a secmark use it rather than the CIPSO label.
+        * If there is no secmark fall back to CIPSO.
+        * The secmark is assumed to reflect policy better.
+        */
+       if (skb && skb->secmark != 0) {
+               skp = smack_from_secid(skb->secmark);
+               goto access_check;
+       }
+#endif /* CONFIG_SECURITY_SMACK_NETFILTER */
+
        netlbl_secattr_init(&secattr);
        rc = netlbl_skbuff_getattr(skb, family, &secattr);
        if (rc == 0)
@@ -3938,6 +3950,10 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
                skp = &smack_known_huh;
        netlbl_secattr_destroy(&secattr);
 
+#ifdef CONFIG_SECURITY_SMACK_NETFILTER
+access_check:
+#endif
+
 #ifdef CONFIG_AUDIT
        smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
        ad.a.u.net->family = family;