Received: from eggs.gnu.org ([2001:4830:134:3::10]:47816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkFzA-0007ba-Na for qemu-devel@nongnu.org; Fri, 31 Oct 2014 13:27:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XkFz6-00089t-DF for qemu-devel@nongnu.org; Fri, 31 Oct 2014 13:27:40 -0400 From: Paolo Bonzini Date: Fri, 31 Oct 2014 18:26:09 +0100 Message-Id: <1414776373-9704-32-git-send-email-pbonzini@redhat.com> In-Reply-To: <1414776373-9704-1-git-send-email-pbonzini@redhat.com> References: <1414776373-9704-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 31/35] ivshmem: validate incoming_posn value from server List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cam Macdonell , qemu-stable@nongnu.org, Stefan Hajnoczi , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Stefan Hajnoczi Check incoming_posn to avoid out-of-bounds array accesses if the ivshmem server on the host sends invalid values. 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=C3=A4rber Reviewed-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini --- hw/misc/ivshmem.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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, int= 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 accompany= 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.3.1