From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL4w9-0001u8-5f for qemu-devel@nongnu.org; Mon, 18 Jan 2016 03:13:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aL4w8-0004G5-28 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 03:13:17 -0500 References: <1452764448-17953-1-git-send-email-mst@redhat.com> <569C8B29.4040300@redhat.com> From: Jason Wang Message-ID: <569C9E87.2030001@redhat.com> Date: Mon, 18 Jan 2016 16:12:55 +0800 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite Cc: Peter Crosthwaite , Alistair Francis , "Michael S. Tsirkin" , "qemu-devel@nongnu.org Developers" , Prasad Pandit , qemu-arm , =?UTF-8?B?5YiY5Luk?= On 01/18/2016 03:04 PM, Peter Crosthwaite wrote: > On Sun, Jan 17, 2016 at 10:50 PM, Jason Wang wrot= e: >> >> On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote: >>> gem_receive copies a packet received from network into an rxbuf[2048] >>> array on stack, with size limited by descriptor length set by guest. = If >>> guest is malicious and specifies a descriptor length that is too larg= e, >>> and should packet size exceed array size, this results in a buffer >>> overflow. >>> >>> Reported-by: =E5=88=98=E4=BB=A4 >>> Signed-off-by: Michael S. Tsirkin >>> --- >>> hw/net/cadence_gem.c | 8 ++++++++ >>> 1 file changed, 8 insertions(+) >> Apply to my -net with tweak on commit log (changing receive to transmi= t >> as noticed). >> > As this is actually an unimplemented feature you should change the > message to a LOG_UNIMP rather than a debug printf. > > Regards, > Peter Thanks for the reminding. But we need know the whether real device could send packet whose length is greater than 2048. Do you know the link to the manual? (Haven't fond it in cadence page.) A hint is the linux driver (drivers/net/ethernet/cadence/macb.c), use 1500 as its MTU. > >> Thanks >> >>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c >>> index 3639fc1..15a0786 100644 >>> --- a/hw/net/cadence_gem.c >>> +++ b/hw/net/cadence_gem.c >>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s) >>> break; >>> } >>> >>> + if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_p= acket)) { >>> + DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x spac= e 0x%x\n", >>> + (unsigned)packet_desc_addr, >>> + (unsigned)tx_desc_get_length(desc), >>> + sizeof(tx_packet) - (p - tx_packet)); >>> + break; >>> + } >>> + >>> /* Gather this fragment of the packet from "dma memory" to o= ur contig. >>> * buffer. >>> */