Skip to contentSkip to conversation

xfrm: fix "disable_policy" on ipv4 early demux

PATCH Applied Eyal Birger 3 participants 7 messages Oct 9, 2022 – Oct 14, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfrm: fix "disable_policy" on ipv4 early demux

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")

----

v2: use dev instead of skb->dev

---
 net/ipv4/ip_input.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ipv4/ip_input.c +5 -0
index 1b512390b3cf..e880ce77322a 100644
@@ -366,6 +366,11 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
 					   iph->tos, dev);
 		if (unlikely(err))
 			goto drop_error;
+	} else {
+		struct in_device *in_dev = __in_dev_get_rcu(dev);
+
+		if (in_dev && IN_DEV_ORCONF(in_dev, NOPOLICY))
+			IPCB(skb)->flags |= IPSKB_NOPOLICY;
 	}
 
 #ifdef CONFIG_IP_ROUTE_CLASSID
Signature · 1 line
2.34.1
#1 lore raw

Le 09/10/2022 à 21:16, Eyal Birger a écrit :

Quoted 9 lines

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Quoted 8 lines

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")

Is there the same problem with ipv6?

#2 lore raw

Hi Nicolas,

Quoted 14 lines · Nicolas Dichtel
Quoted 12 lines · Eyal Birger

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Quoted 7 lines
Quoted 5 lines
Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")

Is there the same problem with ipv6?

The issue is specific to IPv4 as the original fix was only relevant to IPv4.

I also tested a similar scenario using IPv6 addresses and did not see a problem.

Thanks!
Eyal.

#3 lore raw

Le 10/10/2022 à 12:29, Eyal Birger a écrit :

Quoted 24 lines

Hi Nicolas,

Quoted 20 lines · Nicolas Dichtel
Quoted 17 lines · Eyal Birger

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")
Quoted 7 lines
Quoted 1 line

Is there the same problem with ipv6?

The issue is specific to IPv4 as the original fix was only relevant to IPv4.

I also tested a similar scenario using IPv6 addresses and did not see a problem.

Thanks. Is it possible to write a selftest with this scenario?

Regards,
Nicolas

#4 lore raw
Quoted 26 lines · Nicolas Dichtel
Quoted 24 lines · Eyal Birger

Hi Nicolas,

Quoted 20 lines · Nicolas Dichtel
Quoted 17 lines · Eyal Birger

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Is there the same problem with ipv6?

The issue is specific to IPv4 as the original fix was only relevant to IPv4.

I also tested a similar scenario using IPv6 addresses and did not see a problem.

Thanks. Is it possible to write a selftest with this scenario?

I can add one targeting ipsec-next.

Do you perhaps know which is the current preferred flavor for such selftests for ipsec - C or bash?

Eyal.

#6 lore raw
In reply to Eyal Birger
Quoted 9 lines · Eyal Birger

The commit in the "Fixes" tag tried to avoid a case where policy check is ignored due to dst caching in next hops.

However, when the traffic is locally consumed, the dst may be cached in a local TCP or UDP socket as part of early demux. In this case the "disable_policy" flag is not checked as ip_route_input_noref() was only called before caching, and thus, packets after the initial packet in a flow will be dropped if not matching policies.

Quoted 7 lines

Fix by checking the "disable_policy" flag also when a valid dst is already available.

Fixes e6175a2ed1f1 ("xfrm: fix "disable_policy" flag use when arriving from different devices")

Applied, thanks Eyal!