android_kernel_motorola_sm6225/net/ipv6
Venkat Yekkirala 5b368e61c2 IPsec: correct semantics for SELinux policy matching
Currently when an IPSec policy rule doesn't specify a security
context, it is assumed to be "unlabeled" by SELinux, and so
the IPSec policy rule fails to match to a flow that it would
otherwise match to, unless one has explicitly added an SELinux
policy rule allowing the flow to "polmatch" to the "unlabeled"
IPSec policy rules. In the absence of such an explicitly added
SELinux policy rule, the IPSec policy rule fails to match and
so the packet(s) flow in clear text without the otherwise applicable
xfrm(s) applied.

The above SELinux behavior violates the SELinux security notion of
"deny by default" which should actually translate to "encrypt by
default" in the above case.

This was first reported by Evgeniy Polyakov and the way James Morris
was seeing the problem was when connecting via IPsec to a
confined service on an SELinux box (vsftpd), which did not have the
appropriate SELinux policy permissions to send packets via IPsec.

With this patch applied, SELinux "polmatching" of flows Vs. IPSec
policy rules will only come into play when there's a explicit context
specified for the IPSec policy rule (which also means there's corresponding
SELinux policy allowing appropriate domains/flows to polmatch to this context).

Secondly, when a security module is loaded (in this case, SELinux), the
security_xfrm_policy_lookup() hook can return errors other than access denied,
such as -EINVAL.  We were not handling that correctly, and in fact
inverting the return logic and propagating a false "ok" back up to
xfrm_lookup(), which then allowed packets to pass as if they were not
associated with an xfrm policy.

The solution for this is to first ensure that errno values are
correctly propagated all the way back up through the various call chains
from security_xfrm_policy_lookup(), and handled correctly.

Then, flow_cache_lookup() is modified, so that if the policy resolver
fails (typically a permission denied via the security module), the flow
cache entry is killed rather than having a null policy assigned (which
indicates that the packet can pass freely).  This also forces any future
lookups for the same flow to consult the security module (e.g. SELinux)
for current security policy (rather than, say, caching the error on the
flow cache entry).

This patch: Fix the selinux side of things.

This makes sure SELinux polmatching of flow contexts to IPSec policy
rules comes into play only when an explicit context is associated
with the IPSec policy rule.

Also, this no longer defaults the context of a socket policy to
the context of the socket since the "no explicit context" case
is now handled properly.

Signed-off-by: Venkat Yekkirala <vyekkirala@TrustedCS.com>
Signed-off-by: James Morris <jmorris@namei.org>
2006-10-11 23:59:37 -07:00
..
netfilter [NETFILTER]: make some netfilter globals __read_mostly 2006-09-22 15:19:58 -07:00
addrconf.c [IPV4]: inet_rcv_saddr() annotations 2006-09-28 18:02:28 -07:00
af_inet6.c [IPV4]: inet_addr_type() annotations 2006-09-28 18:01:07 -07:00
ah6.c [IPV6] MIP6: Several obvious clean-ups. 2006-09-22 15:17:58 -07:00
anycast.c [IPV6] ADDRCONF: Convert addrconf_lock to RCU. 2006-09-22 15:20:26 -07:00
datagram.c [IPV6] MIP6: Add socket option and ancillary data interface of routing header type 2. 2006-09-22 15:06:49 -07:00
esp6.c [IPSEC] esp: Defer output IV initialization to first use. 2006-09-22 15:17:35 -07:00
exthdrs.c [IPV6] MIP6: Fix to update IP6CB when cloned skbuff is received at HAO. 2006-09-22 15:18:46 -07:00
exthdrs_core.c [SELINUX]: Fix ipv6_skip_exthdr() invocation causing OOPS. 2005-04-24 20:16:19 -07:00
fib6_rules.c Remove all inclusions of <linux/config.h> 2006-10-04 03:38:54 -04:00
icmp.c [IPV6] MIP6: Revert address to send ICMPv6 error. 2006-09-22 15:06:55 -07:00
inet6_connection_sock.c [IPV6]: Cache source address as well in ipv6_pinfo{}. 2006-09-22 14:55:45 -07:00
inet6_hashtables.c [IPV4]: INET_MATCH() annotations 2006-09-28 18:02:25 -07:00
ip6_fib.c [NET]: Use SLAB_PANIC 2006-09-22 15:18:19 -07:00
ip6_flowlabel.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
ip6_input.c [IPV6]: Allow to replace skbuff by TLV parser. 2006-09-22 15:06:51 -07:00
ip6_output.c [IPV6] NDISC: Add proxy_ndp sysctl. 2006-09-22 15:20:25 -07:00
ip6_tunnel.c [NET]: Conversions from kmalloc+memset to k(z|c)alloc. 2006-07-21 14:51:30 -07:00
ipcomp6.c [XFRM]: BEET mode 2006-10-04 00:31:09 -07:00
ipv6_sockglue.c [IPV6]: Disable SG for GSO unless we have checksum 2006-09-28 18:02:45 -07:00
ipv6_syms.c [IPV6] ADDRCONF: Convert addrconf_lock to RCU. 2006-09-22 15:20:26 -07:00
Kconfig [XFRM]: BEET mode 2006-10-04 00:31:09 -07:00
Makefile [XFRM]: BEET mode 2006-10-04 00:31:09 -07:00
mcast.c [NET/IPV4/IPV6]: Change some sysctl variables to __read_mostly 2006-09-22 14:55:03 -07:00
mip6.c Remove all inclusions of <linux/config.h> 2006-10-04 03:38:54 -04:00
ndisc.c [IPV6] NDISC: Fix is_router flag setting. 2006-09-22 15:20:27 -07:00
netfilter.c [NET]: Replace CHECKSUM_HW by CHECKSUM_PARTIAL/CHECKSUM_COMPLETE 2006-09-22 14:53:53 -07:00
proc.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
protocol.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
raw.c [IPV6] MIP6: Add sending mobility header functions through raw socket. 2006-09-22 15:07:02 -07:00
reassembly.c [NET/IPV4/IPV6]: Change some sysctl variables to __read_mostly 2006-09-22 14:55:03 -07:00
route.c [IPV6] ROUTE: Fix dst reference counting in ip6_pol_route_lookup(). 2006-09-22 15:18:26 -07:00
sit.c [IPV4]: Get rid of redundant IPCB->opts initialisation 2006-07-21 14:29:53 -07:00
sysctl_net_ipv6.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
tcp_ipv6.c [IPV6]: bh_lock_sock_nested on tcp_v6_rcv 2006-09-28 17:53:54 -07:00
tunnel6.c [INET]: Move no-tunnel ICMP error to tunnel4/tunnel6 2006-04-09 22:25:25 -07:00
udp.c [UDP]: Fix MSG_PROBE crash 2006-10-04 00:31:00 -07:00
xfrm6_input.c [XFRM]: xrfm_replay_check() annotations 2006-09-28 18:02:40 -07:00
xfrm6_mode_beet.c [XFRM]: BEET mode 2006-10-04 00:31:09 -07:00
xfrm6_mode_ro.c [IPSEC]: output mode to take an xfrm state as input param 2006-09-22 15:18:48 -07:00
xfrm6_mode_transport.c [IPSEC]: output mode to take an xfrm state as input param 2006-09-22 15:18:48 -07:00
xfrm6_mode_tunnel.c [IPSEC]: output mode to take an xfrm state as input param 2006-09-22 15:18:48 -07:00
xfrm6_output.c [IPSEC]: output mode to take an xfrm state as input param 2006-09-22 15:18:48 -07:00
xfrm6_policy.c IPsec: correct semantics for SELinux policy matching 2006-10-11 23:59:37 -07:00
xfrm6_state.c [XFRM]: ports in struct xfrm_selector annotated 2006-09-28 18:02:33 -07:00
xfrm6_tunnel.c [XFRM]: xrfm_replay_check() annotations 2006-09-28 18:02:40 -07:00