Skip to content

Commit 46b3171

Browse files
klassertgregkh
authored andcommitted
xfrm: Fix stack-out-of-bounds read on socket policy lookup.
commit ddc47e4 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 274ee93 commit 46b3171

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

net/xfrm/xfrm_policy.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,15 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
12571257
again:
12581258
pol = rcu_dereference(sk->sk_policy[dir]);
12591259
if (pol != NULL) {
1260-
bool match = xfrm_selector_match(&pol->selector, fl, family);
1260+
bool match;
12611261
int err = 0;
12621262

1263+
if (pol->family != family) {
1264+
pol = NULL;
1265+
goto out;
1266+
}
1267+
1268+
match = xfrm_selector_match(&pol->selector, fl, family);
12631269
if (match) {
12641270
if ((sk->sk_mark & pol->mark.m) != pol->mark.v) {
12651271
pol = NULL;

0 commit comments

Comments
 (0)