Skip to content

Commit 6594af6

Browse files
pcmooregregkh
authored andcommitted
selinux: process labeled IPsec TCP SYN-ACK packets properly in selinux_ip_postroute()
commit c0828e5 upstream. Due to difficulty in arriving at the proper security label for TCP SYN-ACK packets in selinux_ip_postroute(), we need to check packets while/before they are undergoing XFRM transforms instead of waiting until afterwards so that we can determine the correct security label. Reported-by: Janak Desai <Janak.Desai@gtri.gatech.edu> Signed-off-by: Paul Moore <pmoore@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3577781 commit 6594af6

1 file changed

Lines changed: 36 additions & 7 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4811,22 +4811,32 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
48114811
* as fast and as clean as possible. */
48124812
if (!selinux_policycap_netpeer)
48134813
return selinux_ip_postroute_compat(skb, ifindex, family);
4814+
4815+
secmark_active = selinux_secmark_enabled();
4816+
peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled();
4817+
if (!secmark_active && !peerlbl_active)
4818+
return NF_ACCEPT;
4819+
4820+
sk = skb->sk;
4821+
48144822
#ifdef CONFIG_XFRM
48154823
/* If skb->dst->xfrm is non-NULL then the packet is undergoing an IPsec
48164824
* packet transformation so allow the packet to pass without any checks
48174825
* since we'll have another chance to perform access control checks
48184826
* when the packet is on it's final way out.
48194827
* NOTE: there appear to be some IPv6 multicast cases where skb->dst
4820-
* is NULL, in this case go ahead and apply access control. */
4821-
if (skb_dst(skb) != NULL && skb_dst(skb)->xfrm != NULL)
4828+
* is NULL, in this case go ahead and apply access control.
4829+
* is NULL, in this case go ahead and apply access control.
4830+
* NOTE: if this is a local socket (skb->sk != NULL) that is in the
4831+
* TCP listening state we cannot wait until the XFRM processing
4832+
* is done as we will miss out on the SA label if we do;
4833+
* unfortunately, this means more work, but it is only once per
4834+
* connection. */
4835+
if (skb_dst(skb) != NULL && skb_dst(skb)->xfrm != NULL &&
4836+
!(sk != NULL && sk->sk_state == TCP_LISTEN))
48224837
return NF_ACCEPT;
48234838
#endif
4824-
secmark_active = selinux_secmark_enabled();
4825-
peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled();
4826-
if (!secmark_active && !peerlbl_active)
4827-
return NF_ACCEPT;
48284839

4829-
sk = skb->sk;
48304840
if (sk == NULL) {
48314841
/* Without an associated socket the packet is either coming
48324842
* from the kernel or it is being forwarded; check the packet
@@ -4854,6 +4864,25 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
48544864
struct sk_security_struct *sksec = sk->sk_security;
48554865
if (selinux_skb_peerlbl_sid(skb, family, &skb_sid))
48564866
return NF_DROP;
4867+
/* At this point, if the returned skb peerlbl is SECSID_NULL
4868+
* and the packet has been through at least one XFRM
4869+
* transformation then we must be dealing with the "final"
4870+
* form of labeled IPsec packet; since we've already applied
4871+
* all of our access controls on this packet we can safely
4872+
* pass the packet. */
4873+
if (skb_sid == SECSID_NULL) {
4874+
switch (family) {
4875+
case PF_INET:
4876+
if (IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED)
4877+
return NF_ACCEPT;
4878+
break;
4879+
case PF_INET6:
4880+
if (IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED)
4881+
return NF_ACCEPT;
4882+
default:
4883+
return NF_DROP_ERR(-ECONNREFUSED);
4884+
}
4885+
}
48574886
if (selinux_conn_sid(sksec->sid, skb_sid, &peer_sid))
48584887
return NF_DROP;
48594888
secmark_perm = PACKET__SEND;

0 commit comments

Comments
 (0)