Skip to content

Commit 938990d

Browse files
wdebruijgregkh
authored andcommitted
udp: consistently apply ufo or fragmentation
[ Upstream commit 85f1bd9a7b5a79d5baa8bf44af19658f7bf77bfa ] When iteratively building a UDP datagram with MSG_MORE and that datagram exceeds MTU, consistently choose UFO or fragmentation. Once skb_is_gso, always apply ufo. Conversely, once a datagram is split across multiple skbs, do not consider ufo. Sendpage already maintains the first invariant, only add the second. IPv6 does not have a sendpage implementation to modify. A gso skb must have a partial checksum, do not follow sk_no_check_tx in udp_send_skb. Found by syzkaller. Fixes: e89e9cf ("[IPv4/IPv6]: UFO Scatter-gather approach") Reported-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 98c1ad1 commit 938990d

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

net/ipv4/ip_output.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,12 @@ static int __ip_append_data(struct sock *sk,
922922
csummode = CHECKSUM_PARTIAL;
923923

924924
cork->length += length;
925-
if (((length > mtu) || (skb && skb_is_gso(skb))) &&
925+
if ((skb && skb_is_gso(skb)) ||
926+
((length > mtu) &&
927+
(skb_queue_len(queue) <= 1) &&
926928
(sk->sk_protocol == IPPROTO_UDP) &&
927929
(rt->dst.dev->features & NETIF_F_UFO) && !rt->dst.header_len &&
928-
(sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx) {
930+
(sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx)) {
929931
err = ip_ufo_append_data(sk, queue, getfrag, from, length,
930932
hh_len, fragheaderlen, transhdrlen,
931933
maxfraglen, flags);
@@ -1241,6 +1243,7 @@ ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page,
12411243
return -EINVAL;
12421244

12431245
if ((size + skb->len > mtu) &&
1246+
(skb_queue_len(&sk->sk_write_queue) == 1) &&
12441247
(sk->sk_protocol == IPPROTO_UDP) &&
12451248
(rt->dst.dev->features & NETIF_F_UFO)) {
12461249
if (skb->ip_summed != CHECKSUM_PARTIAL)

net/ipv4/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4)
819819
if (is_udplite) /* UDP-Lite */
820820
csum = udplite_csum(skb);
821821

822-
else if (sk->sk_no_check_tx) { /* UDP csum disabled */
822+
else if (sk->sk_no_check_tx && !skb_is_gso(skb)) { /* UDP csum off */
823823

824824
skb->ip_summed = CHECKSUM_NONE;
825825
goto send;

net/ipv6/ip6_output.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,11 +1357,12 @@ static int __ip6_append_data(struct sock *sk,
13571357
*/
13581358

13591359
cork->length += length;
1360-
if ((((length + fragheaderlen) > mtu) ||
1361-
(skb && skb_is_gso(skb))) &&
1360+
if ((skb && skb_is_gso(skb)) ||
1361+
(((length + fragheaderlen) > mtu) &&
1362+
(skb_queue_len(queue) <= 1) &&
13621363
(sk->sk_protocol == IPPROTO_UDP) &&
13631364
(rt->dst.dev->features & NETIF_F_UFO) &&
1364-
(sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk)) {
1365+
(sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk))) {
13651366
err = ip6_ufo_append_data(sk, queue, getfrag, from, length,
13661367
hh_len, fragheaderlen, exthdrlen,
13671368
transhdrlen, mtu, flags, fl6);

0 commit comments

Comments
 (0)