qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] net: check packet payload length


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH] net: check packet payload length
Date: Wed, 17 Feb 2016 13:57:08 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

P J P <address@hidden> writes:

> From: Prasad J Pandit <address@hidden>
>
> 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 <address@hidden>
> Signed-off-by: Prasad J Pandit <address@hidden>
> ---
>  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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]