xfrm: Fix wraparound in xfrm_policy_addr_delta()
authorVisa Hankala <visa@hankala.org>
Wed, 30 Dec 2020 16:15:53 +0000 (16:15 +0000)
committerSteffen Klassert <steffen.klassert@secunet.com>
Mon, 4 Jan 2021 09:35:09 +0000 (10:35 +0100)
commitda64ae2d35d3673233f0403b035d4c6acbf71965
tree075b05b9a9c7fb640fc74c82d134539a342fef08
parentf6e9ceb7a7fc321a31a9dde93a99b7b4b016a3b3
xfrm: Fix wraparound in xfrm_policy_addr_delta()

Use three-way comparison for address components to avoid integer
wraparound in the result of xfrm_policy_addr_delta(). This ensures
that the search trees are built and traversed correctly.

Treat IPv4 and IPv6 similarly by returning 0 when prefixlen == 0.
Prefix /0 has only one equivalence class.

Fixes: 9cf545ebd591d ("xfrm: policy: store inexact policies in a tree ordered by destination address")
Signed-off-by: Visa Hankala <visa@hankala.org>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c
tools/testing/selftests/net/xfrm_policy.sh