netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Dexuan Cui <decui@microsoft.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"edumazet@google.com" <edumazet@google.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Sasha Levin <Alexander.Levin@microsoft.com>,
	"w@1wt.eu" <w@1wt.eu>,
	Joseph Salisbury <Joseph.Salisbury@microsoft.com>,
	Michael Kelley <mikelley@microsoft.com>,
	"viro@zeniv.linux.org.uk" <viro@zeniv.linux.org.uk>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"ohering@suse.com" <ohering@suse.com>
Subject: Re: [PATCH][for v4.4 only] udp: drop corrupt packets earlier to avoid data corruption
Date: Wed, 12 Aug 2020 20:06:50 -0400	[thread overview]
Message-ID: <20200813000650.GL2975990@sasha-vm> (raw)
In-Reply-To: <KL1P15301MB0279A6C3BB3ACADE410F8144BF490@KL1P15301MB0279.APCP153.PROD.OUTLOOK.COM>

On Fri, Aug 07, 2020 at 06:03:00PM +0000, Dexuan Cui wrote:
>> From: Dexuan Cui <decui@microsoft.com>
>> Sent: Monday, July 27, 2020 6:55 PM
>> To: gregkh@linuxfoundation.org; edumazet@google.com;
>> stable@vger.kernel.org
>> Cc: w@1wt.eu; Dexuan Cui <decui@microsoft.com>; Joseph Salisbury
>> <Joseph.Salisbury@microsoft.com>; Michael Kelley <mikelley@microsoft.com>;
>> viro@zeniv.linux.org.uk; netdev@vger.kernel.org; davem@davemloft.net;
>> ohering@suse.com
>> Subject: [PATCH][for v4.4 only] udp: drop corrupt packets earlier to avoid data
>> corruption
>>
>> The v4.4 stable kernel lacks this bugfix:
>> commit 327868212381 ("make skb_copy_datagram_msg() et.al. preserve
>> ->msg_iter on error").
>> As a result, the v4.4 kernel can deliver corrupt data to the application
>> when a corrupt UDP packet is closely followed by a valid UDP packet: the
>> same invocation of the recvmsg() syscall can deliver the corrupt packet's
>> UDP payload to the application with the UDP payload length and the
>> "from IP/Port" of the valid packet.
>>
>> Details:
>>
>> For a UDP packet longer than 76 bytes (see the v5.8-rc6 kernel's
>> include/linux/skbuff.h:3951), Linux delays the UDP checksum verification
>> until the application invokes the syscall recvmsg().
>>
>> In the recvmsg() syscall handler, while Linux is copying the UDP payload
>> to the application's memory, it calculates the UDP checksum. If the
>> calculated checksum doesn't match the received checksum, Linux drops the
>> corrupt UDP packet, and then starts to process the next packet (if any),
>> and if the next packet is valid (i.e. the checksum is correct), Linux
>> will copy the valid UDP packet's payload to the application's receiver
>> buffer.
>>
>> The bug is: before Linux starts to copy the valid UDP packet, the data
>> structure used to track how many more bytes should be copied to the
>> application memory is not reset to what it was when the application just
>> entered the kernel by the syscall! Consequently, only a small portion or
>> none of the valid packet's payload is copied to the application's
>> receive buffer, and later when the application exits from the kernel,
>> actually most of the application's receive buffer contains the payload
>> of the corrupt packet while recvmsg() returns the length of the UDP
>> payload of the valid packet.
>>
>> For the mainline kernel, the bug was fixed in commit 327868212381,
>> but unluckily the bugfix is only backported to v4.9+. It turns out
>> backporting 327868212381 to v4.4 means that some supporting patches
>> must be backported first, so the overall changes seem too big, so the
>> alternative is performs the csum validation earlier and drops the
>> corrupt packets earlier.
>>
>> Signed-off-by: Eric Dumazet <edumazet@google.com>
>> Signed-off-by: Dexuan Cui <decui@microsoft.com>
>> ---
>>  net/ipv4/udp.c | 3 +--
>>  net/ipv6/udp.c | 6 ++----
>>  2 files changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
>> index bb30699..49ab587 100644
>> --- a/net/ipv4/udp.c
>> +++ b/net/ipv4/udp.c
>> @@ -1589,8 +1589,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct
>> sk_buff *skb)
>>  		}
>>  	}
>>
>> -	if (rcu_access_pointer(sk->sk_filter) &&
>> -	    udp_lib_checksum_complete(skb))
>> +	if (udp_lib_checksum_complete(skb))
>>  		goto csum_error;
>>
>>  	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
>> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
>> index 73f1112..2d6703d 100644
>> --- a/net/ipv6/udp.c
>> +++ b/net/ipv6/udp.c
>> @@ -686,10 +686,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct
>> sk_buff *skb)
>>  		}
>>  	}
>>
>> -	if (rcu_access_pointer(sk->sk_filter)) {
>> -		if (udp_lib_checksum_complete(skb))
>> -			goto csum_error;
>> -	}
>> +	if (udp_lib_checksum_complete(skb))
>> +		goto csum_error;
>>
>>  	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
>>  		UDP6_INC_STATS_BH(sock_net(sk),
>> --
>> 1.8.3.1
>
>+Sasha
>
>This patch is targeted to the linux-4.4.y branch of the stable tree.

Eric, will you ack this (or have a missed a previous ack)?

-- 
Thanks,
Sasha

  reply	other threads:[~2020-08-13  0:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  1:55 [PATCH][for v4.4 only] udp: drop corrupt packets earlier to avoid data corruption Dexuan Cui
2020-08-07 18:03 ` Dexuan Cui
2020-08-13  0:06   ` Sasha Levin [this message]
2020-08-13  0:09     ` Eric Dumazet
2020-08-14 16:26       ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200813000650.GL2975990@sasha-vm \
    --to=sashal@kernel.org \
    --cc=Alexander.Levin@microsoft.com \
    --cc=Joseph.Salisbury@microsoft.com \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=mikelley@microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=ohering@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).