Skip to content

Commit b210de4

Browse files
ayalevinkuba-moo
authored andcommitted
net: ipv6: Validate GSO SKB before finish IPv6 processing
There are cases where GSO segment's length exceeds the egress MTU: - Forwarding of a TCP GRO skb, when DF flag is not set. - Forwarding of an skb that arrived on a virtualisation interface (virtio-net/vhost/tap) with TSO/GSO size set by other network stack. - Local GSO skb transmitted on an NETIF_F_TSO tunnel stacked over an interface with a smaller MTU. - Arriving GRO skb (or GSO skb in a virtualised environment) that is bridged to a NETIF_F_TSO tunnel stacked over an interface with an insufficient MTU. If so: - Consume the SKB and its segments. - Issue an ICMP packet with 'Packet Too Big' message containing the MTU, allowing the source host to reduce its Path MTU appropriately. Note: These cases are handled in the same manner in IPv4 output finish. This patch aligns the behavior of IPv6 and the one of IPv4. Fixes: 9e50849 ("netfilter: ipv6: move POSTROUTING invocation before fragmentation") Signed-off-by: Aya Levin <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a2bc221 commit b210de4

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

net/ipv6/ip6_output.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,43 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
125125
return -EINVAL;
126126
}
127127

128+
static int
129+
ip6_finish_output_gso_slowpath_drop(struct net *net, struct sock *sk,
130+
struct sk_buff *skb, unsigned int mtu)
131+
{
132+
struct sk_buff *segs, *nskb;
133+
netdev_features_t features;
134+
int ret = 0;
135+
136+
/* Please see corresponding comment in ip_finish_output_gso
137+
* describing the cases where GSO segment length exceeds the
138+
* egress MTU.
139+
*/
140+
features = netif_skb_features(skb);
141+
segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
142+
if (IS_ERR_OR_NULL(segs)) {
143+
kfree_skb(skb);
144+
return -ENOMEM;
145+
}
146+
147+
consume_skb(skb);
148+
149+
skb_list_walk_safe(segs, segs, nskb) {
150+
int err;
151+
152+
skb_mark_not_on_list(segs);
153+
err = ip6_fragment(net, sk, segs, ip6_finish_output2);
154+
if (err && ret == 0)
155+
ret = err;
156+
}
157+
158+
return ret;
159+
}
160+
128161
static int __ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb)
129162
{
163+
unsigned int mtu;
164+
130165
#if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM)
131166
/* Policy lookup after SNAT yielded a new policy */
132167
if (skb_dst(skb)->xfrm) {
@@ -135,7 +170,11 @@ static int __ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff
135170
}
136171
#endif
137172

138-
if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) ||
173+
mtu = ip6_skb_dst_mtu(skb);
174+
if (skb_is_gso(skb) && !skb_gso_validate_network_len(skb, mtu))
175+
return ip6_finish_output_gso_slowpath_drop(net, sk, skb, mtu);
176+
177+
if ((skb->len > mtu && !skb_is_gso(skb)) ||
139178
dst_allfrag(skb_dst(skb)) ||
140179
(IP6CB(skb)->frag_max_size && skb->len > IP6CB(skb)->frag_max_size))
141180
return ip6_fragment(net, sk, skb, ip6_finish_output2);

0 commit comments

Comments
 (0)