Skip to content

Commit 569ee4b

Browse files
pcmooregregkh
authored andcommitted
selinux: handle TCP SYN-ACK packets correctly in selinux_ip_output()
commit 4718006 upstream. In selinux_ip_output() we always label packets based on the parent socket. While this approach works in almost all cases, it doesn't work in the case of TCP SYN-ACK packets when the correct label is not the label of the parent socket, but rather the label of the larval socket represented by the request_sock struct. Unfortunately, since the request_sock isn't queued on the parent socket until *after* the SYN-ACK packet is sent, we can't lookup the request_sock to determine the correct label for the packet; at this point in time the best we can do is simply pass/NF_ACCEPT the packet. It must be said that simply passing the packet without any explicit labeling action, while far from ideal, is not terrible as the SYN-ACK packet will inherit any IP option based labeling from the initial connection request so the label *should* be correct and all our access controls remain in place so we shouldn't have to worry about information leaks. Reported-by: Janak Desai <Janak.Desai@gtri.gatech.edu> Tested-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 c0bd0fc commit 569ee4b

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <net/ip.h> /* for local_port_range[] */
5454
#include <net/sock.h>
5555
#include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */
56+
#include <net/inet_connection_sock.h>
5657
#include <net/net_namespace.h>
5758
#include <net/netlabel.h>
5859
#include <linux/uaccess.h>
@@ -4690,6 +4691,7 @@ static unsigned int selinux_ipv6_forward(unsigned int hooknum,
46904691
static unsigned int selinux_ip_output(struct sk_buff *skb,
46914692
u16 family)
46924693
{
4694+
struct sock *sk;
46934695
u32 sid;
46944696

46954697
if (!netlbl_enabled())
@@ -4698,8 +4700,27 @@ static unsigned int selinux_ip_output(struct sk_buff *skb,
46984700
/* we do this in the LOCAL_OUT path and not the POST_ROUTING path
46994701
* because we want to make sure we apply the necessary labeling
47004702
* before IPsec is applied so we can leverage AH protection */
4701-
if (skb->sk) {
4702-
struct sk_security_struct *sksec = skb->sk->sk_security;
4703+
sk = skb->sk;
4704+
if (sk) {
4705+
struct sk_security_struct *sksec;
4706+
4707+
if (sk->sk_state == TCP_LISTEN)
4708+
/* if the socket is the listening state then this
4709+
* packet is a SYN-ACK packet which means it needs to
4710+
* be labeled based on the connection/request_sock and
4711+
* not the parent socket. unfortunately, we can't
4712+
* lookup the request_sock yet as it isn't queued on
4713+
* the parent socket until after the SYN-ACK is sent.
4714+
* the "solution" is to simply pass the packet as-is
4715+
* as any IP option based labeling should be copied
4716+
* from the initial connection request (in the IP
4717+
* layer). it is far from ideal, but until we get a
4718+
* security label in the packet itself this is the
4719+
* best we can do. */
4720+
return NF_ACCEPT;
4721+
4722+
/* standard practice, label using the parent socket */
4723+
sksec = sk->sk_security;
47034724
sid = sksec->sid;
47044725
} else
47054726
sid = SECINITSID_KERNEL;

0 commit comments

Comments
 (0)