Received: from eggs.gnu.org ([2001:4830:134:3::10]:33771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW1fQ-0004xQ-T9 for qemu-devel@nongnu.org; Wed, 17 Feb 2016 07:57:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW1fN-0000IP-ML for qemu-devel@nongnu.org; Wed, 17 Feb 2016 07:57:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53333) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW1fN-0000IG-Gz for qemu-devel@nongnu.org; Wed, 17 Feb 2016 07:57:13 -0500 From: Markus Armbruster References: <1455710904-13368-1-git-send-email-ppandit@redhat.com> Date: Wed, 17 Feb 2016 13:57:08 +0100 In-Reply-To: <1455710904-13368-1-git-send-email-ppandit@redhat.com> (P. J. P.'s message of "Wed, 17 Feb 2016 17:38:24 +0530") Message-ID: <878u2jh4uz.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] net: check packet payload length List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: P J P Cc: Jason Wang , Liu Ling , Qemu Developers , Prasad J Pandit P J P writes: > From: Prasad J Pandit > > While computing IP checksum, 'net_checksum_calculate' reads > payload length from the packet. It could exceed the given 'data' > buffer size. Add a check to avoid it. > > Reported-by: Liu Ling > Signed-off-by: Prasad J Pandit > --- > net/checksum.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/net/checksum.c b/net/checksum.c > index 14c0855..e51698c 100644 > --- a/net/checksum.c > +++ b/net/checksum.c > @@ -76,8 +76,9 @@ void net_checksum_calculate(uint8_t *data, int length) > return; > } > > - if (plen < csum_offset+2) > - return; > + if ((plen < csum_offset + 2) || (plen + hlen >= length)) { > + return; > + } > > data[14+hlen+csum_offset] = 0; > data[14+hlen+csum_offset+1] = 0; Function takes data + length, then doesn't use length *groan*. The function stores the checksum if * this is an IPv4 TCP or UDP packet, and * the packet is long enough to include the checksum (but may still be shorter than the TCP header), and * (new with your patch) the buffer holds the complete packet Else it does nothing. Doing nothing for packets other than IPv4 TCP/UDP is obviously intentional. Is calling this function with a partial IPv4 TCP/UDP packet legitimate? If not, should we assert plen + hlen <= length? Or == length, even? If partial packet is okay, what about a partial header? If either is legit, are the callers that can do it prepared for the checksum not to be computed? Style nitpick: we generally omit obviously superfluous parenthesis.