diff options
| author | Paul Moore <pmoore@redhat.com> | 2013-12-04 16:10:45 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-20 10:45:09 -0500 |
| commit | 216c4a776a12148e8386070da71b9f10ab854e93 (patch) | |
| tree | ff599bc8a66e0518135ff8ad95fbc9550caf4cae /security | |
| parent | c588502a732451d199ea27fa5eae9045230e786b (diff) | |
selinux: handle TCP SYN-ACK packets correctly in selinux_ip_output()
commit 47180068276a04ed31d24fe04c673138208b07a9 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>
Diffstat (limited to 'security')
| -rw-r--r-- | security/selinux/hooks.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5c6f2cd2d095..27860faab12e 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | #include <net/ip.h> /* for local_port_range[] */ | 53 | #include <net/ip.h> /* for local_port_range[] */ |
| 54 | #include <net/sock.h> | 54 | #include <net/sock.h> |
| 55 | #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ | 55 | #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ |
| 56 | #include <net/inet_connection_sock.h> | ||
| 56 | #include <net/net_namespace.h> | 57 | #include <net/net_namespace.h> |
| 57 | #include <net/netlabel.h> | 58 | #include <net/netlabel.h> |
| 58 | #include <linux/uaccess.h> | 59 | #include <linux/uaccess.h> |
| @@ -4621,6 +4622,7 @@ static unsigned int selinux_ipv6_forward(unsigned int hooknum, | |||
| 4621 | static unsigned int selinux_ip_output(struct sk_buff *skb, | 4622 | static unsigned int selinux_ip_output(struct sk_buff *skb, |
| 4622 | u16 family) | 4623 | u16 family) |
| 4623 | { | 4624 | { |
| 4625 | struct sock *sk; | ||
| 4624 | u32 sid; | 4626 | u32 sid; |
| 4625 | 4627 | ||
| 4626 | if (!netlbl_enabled()) | 4628 | if (!netlbl_enabled()) |
| @@ -4629,8 +4631,27 @@ static unsigned int selinux_ip_output(struct sk_buff *skb, | |||
| 4629 | /* we do this in the LOCAL_OUT path and not the POST_ROUTING path | 4631 | /* we do this in the LOCAL_OUT path and not the POST_ROUTING path |
| 4630 | * because we want to make sure we apply the necessary labeling | 4632 | * because we want to make sure we apply the necessary labeling |
| 4631 | * before IPsec is applied so we can leverage AH protection */ | 4633 | * before IPsec is applied so we can leverage AH protection */ |
| 4632 | if (skb->sk) { | 4634 | sk = skb->sk; |
| 4633 | struct sk_security_struct *sksec = skb->sk->sk_security; | 4635 | if (sk) { |
| 4636 | struct sk_security_struct *sksec; | ||
| 4637 | |||
| 4638 | if (sk->sk_state == TCP_LISTEN) | ||
| 4639 | /* if the socket is the listening state then this | ||
| 4640 | * packet is a SYN-ACK packet which means it needs to | ||
| 4641 | * be labeled based on the connection/request_sock and | ||
| 4642 | * not the parent socket. unfortunately, we can't | ||
| 4643 | * lookup the request_sock yet as it isn't queued on | ||
| 4644 | * the parent socket until after the SYN-ACK is sent. | ||
| 4645 | * the "solution" is to simply pass the packet as-is | ||
| 4646 | * as any IP option based labeling should be copied | ||
| 4647 | * from the initial connection request (in the IP | ||
| 4648 | * layer). it is far from ideal, but until we get a | ||
| 4649 | * security label in the packet itself this is the | ||
| 4650 | * best we can do. */ | ||
| 4651 | return NF_ACCEPT; | ||
| 4652 | |||
| 4653 | /* standard practice, label using the parent socket */ | ||
| 4654 | sksec = sk->sk_security; | ||
| 4634 | sid = sksec->sid; | 4655 | sid = sksec->sid; |
| 4635 | } else | 4656 | } else |
| 4636 | sid = SECINITSID_KERNEL; | 4657 | sid = SECINITSID_KERNEL; |
