]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
xfrm: Fix stack-out-of-bounds read on socket policy lookup.
authorSteffen Klassert <steffen.klassert@secunet.com>
Wed, 29 Nov 2017 05:53:55 +0000 (06:53 +0100)
committerSteffen Klassert <steffen.klassert@secunet.com>
Fri, 1 Dec 2017 07:18:36 +0000 (08:18 +0100)
When we do tunnel or beet mode, we pass saddr and daddr from the
template to xfrm_state_find(), this is ok. On transport mode,
we pass the addresses from the flowi, assuming that the IP
addresses (and address family) don't change during transformation.
This assumption is wrong in the IPv4 mapped IPv6 case, packet
is IPv4 and template is IPv6.

Fix this by catching address family missmatches of the policy
and the flow already before we do the lookup.

Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c

index 9542975eb2f90dcb2bae894edeb9b418d04f252e..038ec68f6901f0643366f0f3c035a4054aed04b7 100644 (file)
@@ -1168,9 +1168,15 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
  again:
        pol = rcu_dereference(sk->sk_policy[dir]);
        if (pol != NULL) {
-               bool match = xfrm_selector_match(&pol->selector, fl, family);
+               bool match;
                int err = 0;
 
+               if (pol->family != family) {
+                       pol = NULL;
+                       goto out;
+               }
+
+               match = xfrm_selector_match(&pol->selector, fl, family);
                if (match) {
                        if ((sk->sk_mark & pol->mark.m) != pol->mark.v) {
                                pol = NULL;