lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z0NiQk76qhCMpg6M@duo.ucw.cz>
Date: Sun, 24 Nov 2024 18:28:34 +0100
From: Pavel Machek <pavel@....cz>
To: Sasha Levin <sashal@...nel.org>
Cc: linux-kernel@...r.kernel.org, stable@...r.kernel.org,
	Eyal Birger <eyal.birger@...il.com>,
	Steffen Klassert <steffen.klassert@...unet.com>,
	davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
	pabeni@...hat.com, dsahern@...nel.org, netdev@...r.kernel.org
Subject: Re: [PATCH AUTOSEL 6.6 01/15] xfrm: extract dst lookup parameters
 into a struct

Hi!

> [ Upstream commit e509996b16728e37d5a909a5c63c1bd64f23b306 ]
> 
> Preparation for adding more fields to dst lookup functions without
> changing their signatures.
> 
> Signed-off-by: Eyal Birger <eyal.birger@...il.com>
> Signed-off-by: Steffen Klassert <steffen.klassert@...unet.com>
> Signed-off-by: Sasha Levin <sashal@...nel.org>

This does not sound like a bugfix.

BR,
								Pavel

>  include/net/xfrm.h      | 26 +++++++++++++-------------
>  net/ipv4/xfrm4_policy.c | 38 ++++++++++++++++----------------------
>  net/ipv6/xfrm6_policy.c | 28 +++++++++++++---------------
>  net/xfrm/xfrm_device.c  | 11 ++++++++---
>  net/xfrm/xfrm_policy.c  | 35 +++++++++++++++++++++++------------
>  5 files changed, 73 insertions(+), 65 deletions(-)
> 
> diff --git a/include/net/xfrm.h b/include/net/xfrm.h
> index b280e7c460116..93207d87e1c7f 100644
> --- a/include/net/xfrm.h
> +++ b/include/net/xfrm.h
> @@ -342,20 +342,23 @@ struct xfrm_if_cb {
>  void xfrm_if_register_cb(const struct xfrm_if_cb *ifcb);
>  void xfrm_if_unregister_cb(void);
>  
> +struct xfrm_dst_lookup_params {
> +	struct net *net;
> +	int tos;
> +	int oif;
> +	xfrm_address_t *saddr;
> +	xfrm_address_t *daddr;
> +	u32 mark;
> +};
> +
>  struct net_device;
>  struct xfrm_type;
>  struct xfrm_dst;
>  struct xfrm_policy_afinfo {
>  	struct dst_ops		*dst_ops;
> -	struct dst_entry	*(*dst_lookup)(struct net *net,
> -					       int tos, int oif,
> -					       const xfrm_address_t *saddr,
> -					       const xfrm_address_t *daddr,
> -					       u32 mark);
> -	int			(*get_saddr)(struct net *net, int oif,
> -					     xfrm_address_t *saddr,
> -					     xfrm_address_t *daddr,
> -					     u32 mark);
> +	struct dst_entry	*(*dst_lookup)(const struct xfrm_dst_lookup_params *params);
> +	int			(*get_saddr)(xfrm_address_t *saddr,
> +					     const struct xfrm_dst_lookup_params *params);
>  	int			(*fill_dst)(struct xfrm_dst *xdst,
>  					    struct net_device *dev,
>  					    const struct flowi *fl);
> @@ -1728,10 +1731,7 @@ static inline int xfrm_user_policy(struct sock *sk, int optname,
>  }
>  #endif
>  
> -struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
> -				    const xfrm_address_t *saddr,
> -				    const xfrm_address_t *daddr,
> -				    int family, u32 mark);
> +struct dst_entry *__xfrm_dst_lookup(int family, const struct xfrm_dst_lookup_params *params);
>  
>  struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp);
>  
> diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
> index c33bca2c38415..01d4f6f4dbb8c 100644
> --- a/net/ipv4/xfrm4_policy.c
> +++ b/net/ipv4/xfrm4_policy.c
> @@ -17,47 +17,41 @@
>  #include <net/ip.h>
>  #include <net/l3mdev.h>
>  
> -static struct dst_entry *__xfrm4_dst_lookup(struct net *net, struct flowi4 *fl4,
> -					    int tos, int oif,
> -					    const xfrm_address_t *saddr,
> -					    const xfrm_address_t *daddr,
> -					    u32 mark)
> +static struct dst_entry *__xfrm4_dst_lookup(struct flowi4 *fl4,
> +					    const struct xfrm_dst_lookup_params *params)
>  {
>  	struct rtable *rt;
>  
>  	memset(fl4, 0, sizeof(*fl4));
> -	fl4->daddr = daddr->a4;
> -	fl4->flowi4_tos = tos;
> -	fl4->flowi4_l3mdev = l3mdev_master_ifindex_by_index(net, oif);
> -	fl4->flowi4_mark = mark;
> -	if (saddr)
> -		fl4->saddr = saddr->a4;
> -
> -	rt = __ip_route_output_key(net, fl4);
> +	fl4->daddr = params->daddr->a4;
> +	fl4->flowi4_tos = params->tos;
> +	fl4->flowi4_l3mdev = l3mdev_master_ifindex_by_index(params->net,
> +							    params->oif);
> +	fl4->flowi4_mark = params->mark;
> +	if (params->saddr)
> +		fl4->saddr = params->saddr->a4;
> +
> +	rt = __ip_route_output_key(params->net, fl4);
>  	if (!IS_ERR(rt))
>  		return &rt->dst;
>  
>  	return ERR_CAST(rt);
>  }
>  
> -static struct dst_entry *xfrm4_dst_lookup(struct net *net, int tos, int oif,
> -					  const xfrm_address_t *saddr,
> -					  const xfrm_address_t *daddr,
> -					  u32 mark)
> +static struct dst_entry *xfrm4_dst_lookup(const struct xfrm_dst_lookup_params *params)
>  {
>  	struct flowi4 fl4;
>  
> -	return __xfrm4_dst_lookup(net, &fl4, tos, oif, saddr, daddr, mark);
> +	return __xfrm4_dst_lookup(&fl4, params);
>  }
>  
> -static int xfrm4_get_saddr(struct net *net, int oif,
> -			   xfrm_address_t *saddr, xfrm_address_t *daddr,
> -			   u32 mark)
> +static int xfrm4_get_saddr(xfrm_address_t *saddr,
> +			   const struct xfrm_dst_lookup_params *params)
>  {
>  	struct dst_entry *dst;
>  	struct flowi4 fl4;
>  
> -	dst = __xfrm4_dst_lookup(net, &fl4, 0, oif, NULL, daddr, mark);
> +	dst = __xfrm4_dst_lookup(&fl4, params);
>  	if (IS_ERR(dst))
>  		return -EHOSTUNREACH;
>  
> diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
> index 444b0b4469a49..246a0cea77c26 100644
> --- a/net/ipv6/xfrm6_policy.c
> +++ b/net/ipv6/xfrm6_policy.c
> @@ -23,23 +23,21 @@
>  #include <net/ip6_route.h>
>  #include <net/l3mdev.h>
>  
> -static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
> -					  const xfrm_address_t *saddr,
> -					  const xfrm_address_t *daddr,
> -					  u32 mark)
> +static struct dst_entry *xfrm6_dst_lookup(const struct xfrm_dst_lookup_params *params)
>  {
>  	struct flowi6 fl6;
>  	struct dst_entry *dst;
>  	int err;
>  
>  	memset(&fl6, 0, sizeof(fl6));
> -	fl6.flowi6_l3mdev = l3mdev_master_ifindex_by_index(net, oif);
> -	fl6.flowi6_mark = mark;
> -	memcpy(&fl6.daddr, daddr, sizeof(fl6.daddr));
> -	if (saddr)
> -		memcpy(&fl6.saddr, saddr, sizeof(fl6.saddr));
> +	fl6.flowi6_l3mdev = l3mdev_master_ifindex_by_index(params->net,
> +							   params->oif);
> +	fl6.flowi6_mark = params->mark;
> +	memcpy(&fl6.daddr, params->daddr, sizeof(fl6.daddr));
> +	if (params->saddr)
> +		memcpy(&fl6.saddr, params->saddr, sizeof(fl6.saddr));
>  
> -	dst = ip6_route_output(net, NULL, &fl6);
> +	dst = ip6_route_output(params->net, NULL, &fl6);
>  
>  	err = dst->error;
>  	if (dst->error) {
> @@ -50,15 +48,14 @@ static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
>  	return dst;
>  }
>  
> -static int xfrm6_get_saddr(struct net *net, int oif,
> -			   xfrm_address_t *saddr, xfrm_address_t *daddr,
> -			   u32 mark)
> +static int xfrm6_get_saddr(xfrm_address_t *saddr,
> +			   const struct xfrm_dst_lookup_params *params)
>  {
>  	struct dst_entry *dst;
>  	struct net_device *dev;
>  	struct inet6_dev *idev;
>  
> -	dst = xfrm6_dst_lookup(net, 0, oif, NULL, daddr, mark);
> +	dst = xfrm6_dst_lookup(params);
>  	if (IS_ERR(dst))
>  		return -EHOSTUNREACH;
>  
> @@ -68,7 +65,8 @@ static int xfrm6_get_saddr(struct net *net, int oif,
>  		return -EHOSTUNREACH;
>  	}
>  	dev = idev->dev;
> -	ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
> +	ipv6_dev_get_saddr(dev_net(dev), dev, &params->daddr->in6, 0,
> +			   &saddr->in6);
>  	dst_release(dst);
>  	return 0;
>  }
> diff --git a/net/xfrm/xfrm_device.c b/net/xfrm/xfrm_device.c
> index 6346690d5c699..04dc0c8a83707 100644
> --- a/net/xfrm/xfrm_device.c
> +++ b/net/xfrm/xfrm_device.c
> @@ -263,6 +263,8 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
>  
>  	dev = dev_get_by_index(net, xuo->ifindex);
>  	if (!dev) {
> +		struct xfrm_dst_lookup_params params;
> +
>  		if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) {
>  			saddr = &x->props.saddr;
>  			daddr = &x->id.daddr;
> @@ -271,9 +273,12 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
>  			daddr = &x->props.saddr;
>  		}
>  
> -		dst = __xfrm_dst_lookup(net, 0, 0, saddr, daddr,
> -					x->props.family,
> -					xfrm_smark_get(0, x));
> +		memset(&params, 0, sizeof(params));
> +		params.net = net;
> +		params.saddr = saddr;
> +		params.daddr = daddr;
> +		params.mark = xfrm_smark_get(0, x);
> +		dst = __xfrm_dst_lookup(x->props.family, &params);
>  		if (IS_ERR(dst))
>  			return (is_packet_offload) ? -EINVAL : 0;
>  
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index b699cc2ec35ac..1395d3de1ec70 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -251,10 +251,8 @@ static const struct xfrm_if_cb *xfrm_if_get_cb(void)
>  	return rcu_dereference(xfrm_if_cb);
>  }
>  
> -struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
> -				    const xfrm_address_t *saddr,
> -				    const xfrm_address_t *daddr,
> -				    int family, u32 mark)
> +struct dst_entry *__xfrm_dst_lookup(int family,
> +				    const struct xfrm_dst_lookup_params *params)
>  {
>  	const struct xfrm_policy_afinfo *afinfo;
>  	struct dst_entry *dst;
> @@ -263,7 +261,7 @@ struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
>  	if (unlikely(afinfo == NULL))
>  		return ERR_PTR(-EAFNOSUPPORT);
>  
> -	dst = afinfo->dst_lookup(net, tos, oif, saddr, daddr, mark);
> +	dst = afinfo->dst_lookup(params);
>  
>  	rcu_read_unlock();
>  
> @@ -277,6 +275,7 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x,
>  						xfrm_address_t *prev_daddr,
>  						int family, u32 mark)
>  {
> +	struct xfrm_dst_lookup_params params;
>  	struct net *net = xs_net(x);
>  	xfrm_address_t *saddr = &x->props.saddr;
>  	xfrm_address_t *daddr = &x->id.daddr;
> @@ -291,7 +290,14 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x,
>  		daddr = x->coaddr;
>  	}
>  
> -	dst = __xfrm_dst_lookup(net, tos, oif, saddr, daddr, family, mark);
> +	params.net = net;
> +	params.saddr = saddr;
> +	params.daddr = daddr;
> +	params.tos = tos;
> +	params.oif = oif;
> +	params.mark = mark;
> +
> +	dst = __xfrm_dst_lookup(family, &params);
>  
>  	if (!IS_ERR(dst)) {
>  		if (prev_saddr != saddr)
> @@ -2424,15 +2430,15 @@ int __xfrm_sk_clone_policy(struct sock *sk, const struct sock *osk)
>  }
>  
>  static int
> -xfrm_get_saddr(struct net *net, int oif, xfrm_address_t *local,
> -	       xfrm_address_t *remote, unsigned short family, u32 mark)
> +xfrm_get_saddr(unsigned short family, xfrm_address_t *saddr,
> +	       const struct xfrm_dst_lookup_params *params)
>  {
>  	int err;
>  	const struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family);
>  
>  	if (unlikely(afinfo == NULL))
>  		return -EINVAL;
> -	err = afinfo->get_saddr(net, oif, local, remote, mark);
> +	err = afinfo->get_saddr(saddr, params);
>  	rcu_read_unlock();
>  	return err;
>  }
> @@ -2461,9 +2467,14 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
>  			remote = &tmpl->id.daddr;
>  			local = &tmpl->saddr;
>  			if (xfrm_addr_any(local, tmpl->encap_family)) {
> -				error = xfrm_get_saddr(net, fl->flowi_oif,
> -						       &tmp, remote,
> -						       tmpl->encap_family, 0);
> +				struct xfrm_dst_lookup_params params;
> +
> +				memset(&params, 0, sizeof(params));
> +				params.net = net;
> +				params.oif = fl->flowi_oif;
> +				params.daddr = remote;
> +				error = xfrm_get_saddr(tmpl->encap_family, &tmp,
> +						       &params);
>  				if (error)
>  					goto fail;
>  				local = &tmp;

-- 
People of Russia, stop Putin before his war on Ukraine escalates.

Download attachment "signature.asc" of type "application/pgp-signature" (196 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ