Commit 129a9989 authored by Piotr Sawicki's avatar Piotr Sawicki Committed by Casey Schaufler

Smack: Fix handling of IPv4 traffic received by PF_INET6 sockets

A socket which has sk_family set to PF_INET6 is able to receive not
only IPv6 but also IPv4 traffic (IPv4-mapped IPv6 addresses).

Prior to this patch, the smk_skb_to_addr_ipv6() could have been
called for socket buffers containing IPv4 packets, in result such
traffic was allowed.
Signed-off-by: default avatarPiotr Sawicki <p.sawicki2@partner.samsung.com>
Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
parent 4f0496d8
...@@ -3923,15 +3923,19 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -3923,15 +3923,19 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
struct smack_known *skp = NULL; struct smack_known *skp = NULL;
int rc = 0; int rc = 0;
struct smk_audit_info ad; struct smk_audit_info ad;
u16 family = sk->sk_family;
#ifdef CONFIG_AUDIT #ifdef CONFIG_AUDIT
struct lsm_network_audit net; struct lsm_network_audit net;
#endif #endif
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
struct sockaddr_in6 sadd; struct sockaddr_in6 sadd;
int proto; int proto;
if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
family = PF_INET;
#endif /* CONFIG_IPV6 */ #endif /* CONFIG_IPV6 */
switch (sk->sk_family) { switch (family) {
case PF_INET: case PF_INET:
#ifdef CONFIG_SECURITY_SMACK_NETFILTER #ifdef CONFIG_SECURITY_SMACK_NETFILTER
/* /*
...@@ -3949,7 +3953,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -3949,7 +3953,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
*/ */
netlbl_secattr_init(&secattr); netlbl_secattr_init(&secattr);
rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr); rc = netlbl_skbuff_getattr(skb, family, &secattr);
if (rc == 0) if (rc == 0)
skp = smack_from_secattr(&secattr, ssp); skp = smack_from_secattr(&secattr, ssp);
else else
...@@ -3962,7 +3966,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -3962,7 +3966,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
#endif #endif
#ifdef CONFIG_AUDIT #ifdef CONFIG_AUDIT
smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net); smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
ad.a.u.net->family = sk->sk_family; ad.a.u.net->family = family;
ad.a.u.net->netif = skb->skb_iif; ad.a.u.net->netif = skb->skb_iif;
ipv4_skb_to_auditdata(skb, &ad.a, NULL); ipv4_skb_to_auditdata(skb, &ad.a, NULL);
#endif #endif
...@@ -3976,7 +3980,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -3976,7 +3980,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
rc = smk_bu_note("IPv4 delivery", skp, ssp->smk_in, rc = smk_bu_note("IPv4 delivery", skp, ssp->smk_in,
MAY_WRITE, rc); MAY_WRITE, rc);
if (rc != 0) if (rc != 0)
netlbl_skbuff_err(skb, sk->sk_family, rc, 0); netlbl_skbuff_err(skb, family, rc, 0);
break; break;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case PF_INET6: case PF_INET6:
...@@ -3992,7 +3996,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -3992,7 +3996,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
skp = smack_net_ambient; skp = smack_net_ambient;
#ifdef CONFIG_AUDIT #ifdef CONFIG_AUDIT
smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net); smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
ad.a.u.net->family = sk->sk_family; ad.a.u.net->family = family;
ad.a.u.net->netif = skb->skb_iif; ad.a.u.net->netif = skb->skb_iif;
ipv6_skb_to_auditdata(skb, &ad.a, NULL); ipv6_skb_to_auditdata(skb, &ad.a, NULL);
#endif /* CONFIG_AUDIT */ #endif /* CONFIG_AUDIT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment