From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCI8l-0005kI-ND for qemu-devel@nongnu.org; Sun, 12 Jun 2016 23:02:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCI8g-0001CN-N8 for qemu-devel@nongnu.org; Sun, 12 Jun 2016 23:02:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCI8g-0001CJ-HR for qemu-devel@nongnu.org; Sun, 12 Jun 2016 23:02:10 -0400 References: <1465382224-6791-1-git-send-email-ppandit@redhat.com> From: Jason Wang Message-ID: <575E2226.5010004@redhat.com> Date: Mon, 13 Jun 2016 11:01:58 +0800 MIME-Version: 1.0 In-Reply-To: <1465382224-6791-1-git-send-email-ppandit@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: P J P Cc: Peter Maydell , Li Qiang , Prasad J Pandit , Qemu Developers , Leon Alrae , Aurelien Jarno On 2016=E5=B9=B406=E6=9C=8808=E6=97=A5 18:37, P J P wrote: > From: Prasad J Pandit > > When processing MIPSnet I/O port write operation, it uses a > transmit buffer tx_buffer[MAX_ETH_FRAME_SIZE=3D1514]. Two indices > 's->tx_written' and 's->tx_count' are used to control data written > to this buffer. If the two were to be equal before writing, it'd > lead to an OOB write access beyond tx_buffer. Add check to avoid it. > > Reported-by: Li Qiang > Signed-off-by: Prasad J Pandit > --- > hw/net/mipsnet.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > Update as per: > -> https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg02089.ht= ml > > diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c > index 740cd98..450e42d 100644 > --- a/hw/net/mipsnet.c > +++ b/hw/net/mipsnet.c > @@ -180,10 +180,12 @@ static void mipsnet_ioport_write(void *opaque, hw= addr addr, > break; > case MIPSNET_TX_DATA_BUFFER: > s->tx_buffer[s->tx_written++] =3D val; I believe we may still have a buffer overflow here, no? > - if (s->tx_written =3D=3D s->tx_count) { > + if ((s->tx_written >=3D MAX_ETH_FRAME_SIZE) > + || (s->tx_written =3D=3D s->tx_count)) { > /* Send buffer. */ > - trace_mipsnet_send(s->tx_count); > - qemu_send_packet(qemu_get_queue(s->nic), s->tx_buffer, s->= tx_count); > + trace_mipsnet_send(s->tx_written); > + qemu_send_packet(qemu_get_queue(s->nic), > + s->tx_buffer, s->tx_written); > s->tx_count =3D s->tx_written =3D 0; > s->intctl |=3D MIPSNET_INTCTL_TXDONE; > s->busy =3D 1;