Skip to content

Commit 85f1bd9

Browse files
wdebruijdavem330
authored andcommitted
udp: consistently apply ufo or fragmentation
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 <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 96d9703 commit 85f1bd9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

net/ipv4/ip_output.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,12 @@ static int __ip_append_data(struct sock *sk,
965965
csummode = CHECKSUM_PARTIAL;
966966

967967
cork->length += length;
968-
if ((((length + (skb ? skb->len : fragheaderlen)) > mtu) ||
969-
(skb && skb_is_gso(skb))) &&
968+
if ((skb && skb_is_gso(skb)) ||
969+
(((length + (skb ? skb->len : fragheaderlen)) > mtu) &&
970+
(skb_queue_len(queue) <= 1) &&
970971
(sk->sk_protocol == IPPROTO_UDP) &&
971972
(rt->dst.dev->features & NETIF_F_UFO) && !dst_xfrm(&rt->dst) &&
972-
(sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx) {
973+
(sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx)) {
973974
err = ip_ufo_append_data(sk, queue, getfrag, from, length,
974975
hh_len, fragheaderlen, transhdrlen,
975976
maxfraglen, flags);
@@ -1288,6 +1289,7 @@ ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page,
12881289
return -EINVAL;
12891290

12901291
if ((size + skb->len > mtu) &&
1292+
(skb_queue_len(&sk->sk_write_queue) == 1) &&
12911293
(sk->sk_protocol == IPPROTO_UDP) &&
12921294
(rt->dst.dev->features & NETIF_F_UFO)) {
12931295
if (skb->ip_summed != CHECKSUM_PARTIAL)

net/ipv4/udp.c

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

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

807807
skb->ip_summed = CHECKSUM_NONE;
808808
goto send;

net/ipv6/ip6_output.c

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

13831383
cork->length += length;
1384-
if ((((length + (skb ? skb->len : headersize)) > mtu) ||
1385-
(skb && skb_is_gso(skb))) &&
1384+
if ((skb && skb_is_gso(skb)) ||
1385+
(((length + (skb ? skb->len : headersize)) > mtu) &&
1386+
(skb_queue_len(queue) <= 1) &&
13861387
(sk->sk_protocol == IPPROTO_UDP) &&
13871388
(rt->dst.dev->features & NETIF_F_UFO) && !dst_xfrm(&rt->dst) &&
1388-
(sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk)) {
1389+
(sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk))) {
13891390
err = ip6_ufo_append_data(sk, queue, getfrag, from, length,
13901391
hh_len, fragheaderlen, exthdrlen,
13911392
transhdrlen, mtu, flags, fl6);

0 commit comments

Comments
 (0)