xfrm: validate selector family and prefixlen during match
Subsystems (3)
PATCH 1/1 xfrm: validate selector family and prefixlen during match
syzbot reported a shift-out-of-bounds in xfrm_selector_match() due to AF_UNSPEC selector with large prefixlen (e.g. 128) matched against IPv4 flow (when XFRM_STATE_AF_UNSPEC is set).
Fix this by:
- Rejecting mismatched families in xfrm_selector_match.
- Returning false in addr4_match if prefixlen > 32.
- Returning false in addr_match if prefixlen > 128 (prevents overflow).
---
Cc: Sabrina Dubroca <[email protected]>
Cc: Steffen Klassert <[email protected]>
--- include/net/xfrm.h | 7 +++++++ net/xfrm/xfrm_policy.c | 3 +++ 2 files changed, 10 insertions(+)
include/net/xfrm.h +7 -0
@@ -943,6 +943,9 @@ static inline bool addr_match(const void *token1, const void *token2,unsigned int pdw;unsigned int pbi; +if (prefixlen >128 ) +return false; + pdw = prefixlen >>5 ;/* num of whole u32 in prefix */ pbi = prefixlen &0x1f ;/* num of bits in incomplete u32 in prefix */
@@ -967,6 +970,10 @@ static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */ if (sizeof (long ) ==4 && prefixlen ==0 )return true; + +if (prefixlen >32 ) +return false; +return !((a1 ^ a2) &htonl (~0UL << (32 - prefixlen))); }
net/xfrm/xfrm_policy.c +3 -0
@@ -242,6 +242,9 @@ __xfrm6_selector_match(const struct xfrm_selector *sel, const struct flowi *fl)bool xfrm_selector_match (const struct xfrm_selector *sel,const struct flowi *fl,unsigned short family) { +if (family != sel->family && sel->family !=AF_UNSPEC ) +return false; +switch (family) {case AF_INET :return __xfrm4_selector_match (sel, fl);
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
Steffen Klassert
maintainerQuoted 6 lines · Eric Dumazet
syzbot reported a shift-out-of-bounds in
xfrm_selector_match()due toAF_UNSPECselector with large prefixlen (e.g. 128) matched against IPv4 flow (whenXFRM_STATE_AF_UNSPECis set).Fix this by:
Quoted 8 lines
- Rejecting mismatched families in
xfrm_selector_match.
- Returning false inaddr4_matchif prefixlen > 32.
- Returning false inaddr_matchif prefixlen > 128 (prevents overflow).Fixes 3f0ab59e6537 ("xfrm: validate new SA's prefixlen using SA family when sel.family is unset")Reported-by [email protected]Signed-off-by Eric Dumazet <[email protected]>
Also applied, thanks a lot!