Additional TCP SYN-ACK fixes for labeled IPsec
cover Additional TCP SYN-ACK fixes for labeled IPsec
In addition to the patches posted earlier, there are two additional labeled IPsec patches needed to fix up the SYN-ACK issue.
---
Paul Moore (2):
selinux: look for IPsec labels on both inbound and outbound packets
selinux: process labeled IPsec TCP SYN-ACK packets properly in selinux_ip_postroute()
security/selinux/hooks.c | 44 ++++++++++++++++++++++++++++------ security/selinux/include/xfrm.h | 8 ++++-- security/selinux/xfrm.c | 51 +++++++++++++++++++++++++++++++-------- 3 files changed, 82 insertions(+), 21 deletions(-)
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/2 selinux: look for IPsec labels on both inbound and outbound packets
Previously selinux_skb_peerlbl_sid() would only check for labeled IPsec security labels on inbound packets, this patch enables it to check both inbound and outbound traffic for labeled IPsec security labels.
--- security/selinux/hooks.c | 2 +- security/selinux/include/xfrm.h | 8 ++++-- security/selinux/xfrm.c | 51 +++++++++++++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 14 deletions(-)
security/selinux/hooks.c +1 -1
@@ -3829,7 +3829,7 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid)u32 nlbl_sid;u32 nlbl_type; - err =selinux_skb_xfrm_sid (skb, &xfrm_sid); + err =selinux_xfrm_skb_sid (skb, &xfrm_sid);if (unlikely (err))return -EACCES ; err =selinux_netlbl_skbuff_getsid (skb, family, &nlbl_type, &nlbl_sid);
security/selinux/include/xfrm.h +5 -3
@@ -39,6 +39,7 @@ int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,int selinux_xfrm_postroute_last (u32 sk_sid,struct sk_buff *skb,struct common_audit_data *ad,u8 proto);int selinux_xfrm_decode_session (struct sk_buff *skb,u32 *sid,int ckall); +int selinux_xfrm_skb_sid (struct sk_buff *skb,u32 *sid);static inline void selinux_xfrm_notify_policyload (void ) {
@@ -79,11 +80,12 @@ static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid,static inline void selinux_xfrm_notify_policyload (void ) { } -#endif -static inline int selinux_skb_xfrm_sid (struct sk_buff *skb,u32 *sid) +static inline int selinux_xfrm_skb_sid (struct sk_buff *skb,u32 *sid) { -return selinux_xfrm_decode_session (skb, sid,0 ); + *sid =SECSID_NULL ; +return 0 ; } +#endif #endif /* _SELINUX_XFRM_H_ */
security/selinux/xfrm.c +41 -10
66 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/2 selinux: process labeled IPsec TCP SYN-ACK packets properly in selinux_ip_postroute()
In reply to Paul MooreDue 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.
--- security/selinux/hooks.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
security/selinux/hooks.c +35 -7
@@ -4846,22 +4846,31 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,* as fast and as clean as possible. */ if (!selinux_policycap_netpeer)return selinux_ip_postroute_compat (skb, ifindex, family); + + secmark_active =selinux_secmark_enabled (); + peerlbl_active =selinux_peerlbl_enabled (); +if (!secmark_active && !peerlbl_active) +return NF_ACCEPT ; + + sk = skb->sk; +#ifdef CONFIG_XFRM /* If skb->dst->xfrm is non-NULL then the packet is undergoing an IPsec * packet transformation so allow the packet to pass without any checks * since we'll have another chance to perform access control checks * when the packet is on it's final way out. * NOTE: there appear to be some IPv6 multicast cases where skb->dst -* is NULL, in this case go ahead and apply access control. */ -if (skb_dst (skb) !=NULL &&skb_dst (skb)->xfrm !=NULL ) +* is NULL, in this case go ahead and apply access control. +* NOTE: if this is a local socket (skb->sk != NULL) that is in the +* TCP listening state we cannot wait until the XFRM processing +* is done as we will miss out on the SA label if we do; +* unfortunately, this means more work, but it is only once per +* connection. */ +if (skb_dst (skb) !=NULL &&skb_dst (skb)->xfrm !=NULL && + !(sk !=NULL && sk->sk_state ==TCP_LISTEN ))return NF_ACCEPT ;#endif - secmark_active =selinux_secmark_enabled (); - peerlbl_active =selinux_peerlbl_enabled (); -if (!secmark_active && !peerlbl_active) -return NF_ACCEPT ; - sk = skb->sk;if (sk ==NULL ) {/* Without an associated socket the packet is either coming * from the kernel or it is being forwarded; check the packet
@@ -4889,6 +4898,25 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,struct sk_security_struct *sksec = sk->sk_security;if (selinux_skb_peerlbl_sid (skb, family, &skb_sid))return NF_DROP ; +/* At this point, if the returned skb peerlbl is SECSID_NULL +* and the packet has been through at least one XFRM +* transformation then we must be dealing with the "final" +* form of labeled IPsec packet; since we've already applied +* all of our access controls on this packet we can safely +* pass the packet. */ +if (skb_sid ==SECSID_NULL ) { +switch (family) { +case PF_INET : +if (IPCB (skb)->flags &IPSKB_XFRM_TRANSFORMED ) +return NF_ACCEPT ; +break ; +case PF_INET6 : +if (IP6CB (skb)->flags &IP6SKB_XFRM_TRANSFORMED ) +return NF_ACCEPT ; +default : +return NF_DROP_ERR (-ECONNREFUSED ); + } + }if (selinux_conn_sid (sksec->sid, skb_sid, &peer_sid))return NF_DROP ; secmark_perm =PACKET__SEND ;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.