From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW1dU-0007bI-Rr for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:18:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XW1dQ-0001G3-0b for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:18:28 -0400 Date: Mon, 22 Sep 2014 14:21:26 +0300 From: "Michael S. Tsirkin" Message-ID: <20140922112126.GE14882@redhat.com> References: <1410799208-3250-1-git-send-email-afaerber@suse.de> <1410799208-3250-3-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1410799208-3250-3-git-send-email-afaerber@suse.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 2/4] ivshmem: validate incoming_posn value from server List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: Bruce Rogers , Sebastian Krahmer , qemu-stable@nongnu.org, qemu-devel@nongnu.org, David Marchand , Stefan Hajnoczi , Cam Macdonell On Mon, Sep 15, 2014 at 06:40:06PM +0200, Andreas F=E4rber wrote: > From: Stefan Hajnoczi >=20 > Check incoming_posn to avoid out-of-bounds array accesses if the ivshme= m > server on the host sends invalid values. >=20 > Cc: Cam Macdonell > Reported-by: Sebastian Krahmer > Signed-off-by: Stefan Hajnoczi > [AF: Tighten upper bound check for posn in close_guest_eventfds()] > Cc: qemu-stable@nongnu.org > Signed-off-by: Andreas F=E4rber Reviewed-by: Michael S. Tsirkin > --- > hw/misc/ivshmem.c | 8 ++++++++ > 1 file changed, 8 insertions(+) >=20 > diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c > index caeee1e..24f74f6 100644 > --- a/hw/misc/ivshmem.c > +++ b/hw/misc/ivshmem.c > @@ -389,6 +389,9 @@ static void close_guest_eventfds(IVShmemState *s, i= nt posn) > if (!ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) { > return; > } > + if (posn < 0 || posn >=3D s->nb_peers) { > + return; > + } > =20 > guest_curr_max =3D s->peers[posn].nb_eventfds; > =20 > @@ -455,6 +458,11 @@ static void ivshmem_read(void *opaque, const uint8= _t *buf, int size) > } > } > =20 > + if (incoming_posn < -1) { > + IVSHMEM_DPRINTF("invalid incoming_posn %ld\n", incoming_posn); > + return; > + } > + > /* pick off s->server_chr->msgfd and store it, posn should accompa= ny msg */ > tmp_fd =3D qemu_chr_fe_get_msgfd(s->server_chr); > IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, tmp_fd); > --=20 > 1.8.4.5