All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: Ensure consistent address families when resolving templates
@ 2023-04-24 13:23 Tobias Brunner
  2023-04-25  5:34 ` Herbert Xu
  0 siblings, 1 reply; 18+ messages in thread
From: Tobias Brunner @ 2023-04-24 13:23 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: netdev, David S . Miller, Herbert Xu

xfrm_state_find() uses `encap_family` of the current template with
the passed local and remote addresses to find a matching state.
This check makes sure that there is no mismatch and out-of-bounds
read in mixed-family scenarios where optional tunnel or BEET mode
templates were skipped that would have changed the addresses to
match the current template's family.

This basically enforces the same check as validate_tmpl(), just at
runtime when one or more optional templates might have been skipped.

Signed-off-by: Tobias Brunner <tobias@strongswan.org>
---
  net/xfrm/xfrm_policy.c | 5 +++++
  1 file changed, 5 insertions(+)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 62be042f2ebc..e6dfa55f1c3a 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2440,6 +2440,7 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
  	struct net *net = xp_net(policy);
  	int nx;
  	int i, error;
+	unsigned short prev_family = family;
  	xfrm_address_t *daddr = xfrm_flowi_daddr(fl, family);
  	xfrm_address_t *saddr = xfrm_flowi_saddr(fl, family);
  	xfrm_address_t tmp;
@@ -2462,6 +2463,9 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
  					goto fail;
  				local = &tmp;
  			}
+		} else if (prev_family != tmpl->encap_family) {
+			error = -EINVAL;
+			goto fail;
  		}
  
  		x = xfrm_state_find(remote, local, fl, tmpl, policy, &error,
@@ -2471,6 +2475,7 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
  			xfrm[nx++] = x;
  			daddr = remote;
  			saddr = local;
+			prev_family = tmpl->encap_family;
  			continue;
  		}
  		if (x) {
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-05-11 10:04 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24 13:23 [PATCH ipsec] xfrm: Ensure consistent address families when resolving templates Tobias Brunner
2023-04-25  5:34 ` Herbert Xu
2023-04-25  6:47   ` Steffen Klassert
2023-04-25  8:26     ` Herbert Xu
2023-04-25  8:00   ` Tobias Brunner
2023-04-25  8:28     ` Herbert Xu
2023-05-05 10:16       ` [PATCH ipsec] xfrm: Reject optional tunnel/BEET mode templates in outbound policies Tobias Brunner
2023-05-05 10:43         ` Herbert Xu
2023-05-05 11:36           ` [PATCH ipsec] af_key: " Tobias Brunner
2023-05-08  3:10             ` Herbert Xu
2023-05-08  6:01             ` Steffen Klassert
2023-05-09  9:00               ` Tobias Brunner
2023-05-11 10:04                 ` Steffen Klassert
2023-05-08  5:59         ` [PATCH ipsec] xfrm: " Steffen Klassert
2023-05-08  9:03           ` Tobias Brunner
2023-05-09  4:27             ` Steffen Klassert
2023-05-09  8:59               ` Tobias Brunner
2023-05-11 10:03                 ` Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.