Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfrm: Fix stack-out-of-bounds read on socket policy lookup.

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>

+7 -1
+7 -1
net/xfrm/xfrm_policy.c
··· 1168 1168 again: 1169 1169 pol = rcu_dereference(sk->sk_policy[dir]); 1170 1170 if (pol != NULL) { 1171 - bool match = xfrm_selector_match(&pol->selector, fl, family); 1171 + bool match; 1172 1172 int err = 0; 1173 1173 1174 + if (pol->family != family) { 1175 + pol = NULL; 1176 + goto out; 1177 + } 1178 + 1179 + match = xfrm_selector_match(&pol->selector, fl, family); 1174 1180 if (match) { 1175 1181 if ((sk->sk_mark & pol->mark.m) != pol->mark.v) { 1176 1182 pol = NULL;