Skip to content

Commit 2b1dc62

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: pass struct net to xfrm_decode_session wrappers
Preparation patch, extra arg is not used. No functional changes intended. This is needed to replace the xfrm session decode functions with the flow dissector. skb_flow_dissect() cannot be used as-is, because it attempts to deduce the 'struct net' to use for bpf program fetch from skb->sk or skb->dev, but xfrm code path can see skbs that have neither sk or dev filled in. So either flow dissector needs to try harder, e.g. by also trying skb->dst->dev, or we have to pass the struct net explicitly. Passing the struct net doesn't look too bad to me, most places already have it available or can derive it from the output device. Reported-by: kernel test robot <oliver.sang@intel.com> Link: https://lore.kernel.org/netdev/202309271628.27fd2187-oliver.sang@intel.com/ Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent e377240 commit 2b1dc62

10 files changed

Lines changed: 22 additions & 22 deletions

File tree

include/net/xfrm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,20 +1207,20 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
12071207
return __xfrm_policy_check2(sk, dir, skb, AF_INET6, 1);
12081208
}
12091209

1210-
int __xfrm_decode_session(struct sk_buff *skb, struct flowi *fl,
1210+
int __xfrm_decode_session(struct net *net, struct sk_buff *skb, struct flowi *fl,
12111211
unsigned int family, int reverse);
12121212

1213-
static inline int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl,
1213+
static inline int xfrm_decode_session(struct net *net, struct sk_buff *skb, struct flowi *fl,
12141214
unsigned int family)
12151215
{
1216-
return __xfrm_decode_session(skb, fl, family, 0);
1216+
return __xfrm_decode_session(net, skb, fl, family, 0);
12171217
}
12181218

1219-
static inline int xfrm_decode_session_reverse(struct sk_buff *skb,
1219+
static inline int xfrm_decode_session_reverse(struct net *net, struct sk_buff *skb,
12201220
struct flowi *fl,
12211221
unsigned int family)
12221222
{
1223-
return __xfrm_decode_session(skb, fl, family, 1);
1223+
return __xfrm_decode_session(net, skb, fl, family, 1);
12241224
}
12251225

12261226
int __xfrm_route_forward(struct sk_buff *skb, unsigned short family);
@@ -1296,7 +1296,7 @@ static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *sk
12961296
{
12971297
return 1;
12981298
}
1299-
static inline int xfrm_decode_session_reverse(struct sk_buff *skb,
1299+
static inline int xfrm_decode_session_reverse(struct net *net, struct sk_buff *skb,
13001300
struct flowi *fl,
13011301
unsigned int family)
13021302
{

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
517517
} else
518518
return rt;
519519

520-
err = xfrm_decode_session_reverse(skb_in, flowi4_to_flowi(&fl4_dec), AF_INET);
520+
err = xfrm_decode_session_reverse(net, skb_in, flowi4_to_flowi(&fl4_dec), AF_INET);
521521
if (err)
522522
goto relookup_failed;
523523

net/ipv4/ip_vti.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
288288
switch (skb->protocol) {
289289
case htons(ETH_P_IP):
290290
memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
291-
xfrm_decode_session(skb, &fl, AF_INET);
291+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET);
292292
break;
293293
case htons(ETH_P_IPV6):
294294
memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
295-
xfrm_decode_session(skb, &fl, AF_INET6);
295+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6);
296296
break;
297297
default:
298298
goto tx_err;

net/ipv4/netfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un
6262

6363
#ifdef CONFIG_XFRM
6464
if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
65-
xfrm_decode_session(skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
65+
xfrm_decode_session(net, skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
6666
struct dst_entry *dst = skb_dst(skb);
6767
skb_dst_set(skb, NULL);
6868
dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), sk, 0);

net/ipv6/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
385385
return dst;
386386
}
387387

388-
err = xfrm_decode_session_reverse(skb, flowi6_to_flowi(&fl2), AF_INET6);
388+
err = xfrm_decode_session_reverse(net, skb, flowi6_to_flowi(&fl2), AF_INET6);
389389
if (err)
390390
goto relookup_failed;
391391

net/ipv6/ip6_vti.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,11 @@ vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
569569
goto tx_err;
570570

571571
memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
572-
xfrm_decode_session(skb, &fl, AF_INET6);
572+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6);
573573
break;
574574
case htons(ETH_P_IP):
575575
memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
576-
xfrm_decode_session(skb, &fl, AF_INET);
576+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET);
577577
break;
578578
default:
579579
goto tx_err;

net/ipv6/netfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int ip6_route_me_harder(struct net *net, struct sock *sk_partial, struct sk_buff
6161

6262
#ifdef CONFIG_XFRM
6363
if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
64-
xfrm_decode_session(skb, flowi6_to_flowi(&fl6), AF_INET6) == 0) {
64+
xfrm_decode_session(net, skb, flowi6_to_flowi(&fl6), AF_INET6) == 0) {
6565
skb_dst_set(skb, NULL);
6666
dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), sk, 0);
6767
if (IS_ERR(dst))

net/netfilter/nf_nat_proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static int nf_xfrm_me_harder(struct net *net, struct sk_buff *skb, unsigned int
668668
struct flowi fl;
669669
int err;
670670

671-
err = xfrm_decode_session(skb, &fl, family);
671+
err = xfrm_decode_session(net, skb, &fl, family);
672672
if (err < 0)
673673
return err;
674674

net/xfrm/xfrm_interface_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
538538
switch (skb->protocol) {
539539
case htons(ETH_P_IPV6):
540540
memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
541-
xfrm_decode_session(skb, &fl, AF_INET6);
541+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6);
542542
if (!dst) {
543543
fl.u.ip6.flowi6_oif = dev->ifindex;
544544
fl.u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC;
@@ -553,7 +553,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
553553
break;
554554
case htons(ETH_P_IP):
555555
memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
556-
xfrm_decode_session(skb, &fl, AF_INET);
556+
xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET);
557557
if (!dst) {
558558
struct rtable *rt;
559559

net/xfrm/xfrm_policy.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,7 +2853,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
28532853
/* Fixup the mark to support VTI. */
28542854
skb_mark = skb->mark;
28552855
skb->mark = pol->mark.v;
2856-
xfrm_decode_session(skb, &fl, dst->ops->family);
2856+
xfrm_decode_session(net, skb, &fl, dst->ops->family);
28572857
skb->mark = skb_mark;
28582858
spin_unlock(&pq->hold_queue.lock);
28592859

@@ -2889,7 +2889,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
28892889
/* Fixup the mark to support VTI. */
28902890
skb_mark = skb->mark;
28912891
skb->mark = pol->mark.v;
2892-
xfrm_decode_session(skb, &fl, skb_dst(skb)->ops->family);
2892+
xfrm_decode_session(net, skb, &fl, skb_dst(skb)->ops->family);
28932893
skb->mark = skb_mark;
28942894

28952895
dst_hold(xfrm_dst_path(skb_dst(skb)));
@@ -3554,7 +3554,7 @@ decode_session6(struct sk_buff *skb, struct flowi *fl, bool reverse)
35543554
}
35553555
#endif
35563556

3557-
int __xfrm_decode_session(struct sk_buff *skb, struct flowi *fl,
3557+
int __xfrm_decode_session(struct net *net, struct sk_buff *skb, struct flowi *fl,
35583558
unsigned int family, int reverse)
35593559
{
35603560
switch (family) {
@@ -3618,7 +3618,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
36183618
reverse = dir & ~XFRM_POLICY_MASK;
36193619
dir &= XFRM_POLICY_MASK;
36203620

3621-
if (__xfrm_decode_session(skb, &fl, family, reverse) < 0) {
3621+
if (__xfrm_decode_session(net, skb, &fl, family, reverse) < 0) {
36223622
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
36233623
return 0;
36243624
}
@@ -3774,7 +3774,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
37743774
struct dst_entry *dst;
37753775
int res = 1;
37763776

3777-
if (xfrm_decode_session(skb, &fl, family) < 0) {
3777+
if (xfrm_decode_session(net, skb, &fl, family) < 0) {
37783778
XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR);
37793779
return 0;
37803780
}

0 commit comments

Comments
 (0)