Received: from eggs.gnu.org ([2001:4830:134:3::10]:42456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqzzf-0006zQ-7r for qemu-devel@nongnu.org; Mon, 03 Oct 2016 05:57:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqzza-0003Hx-BM for qemu-devel@nongnu.org; Mon, 03 Oct 2016 05:57:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqzza-0003HX-1T for qemu-devel@nongnu.org; Mon, 03 Oct 2016 05:57:02 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 220B5624AE for ; Mon, 3 Oct 2016 09:57:01 +0000 (UTC) References: <20161003094704.18087-1-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: <0b8bd5f1-93d5-0b9b-12da-b0db1fd94277@redhat.com> Date: Mon, 3 Oct 2016 11:56:58 +0200 MIME-Version: 1.0 In-Reply-To: <20161003094704.18087-1-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 0/2] Fix use after free with mux List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , qemu-devel@nongnu.org Cc: kraxel@redhat.com On 03/10/2016 11:47, Marc-Andr=C3=A9 Lureau wrote: > Hi, >=20 > When qemu with muxed monitor quits, it leads to invalid use after free: >=20 > valgrind qemu -chardev stdio,mux=3Don,id=3Dchar0 -mon chardev=3Dchar0,m= ode=3Dcontrol,default >=20 > =3D=3D4306=3D=3D Invalid read of size 8 > =3D=3D4306=3D=3D at 0x8061D3: json_lexer_destroy (json-lexer.c:3= 85) > =3D=3D4306=3D=3D by 0x7E39F8: json_message_parser_destroy (json-= streamer.c:134) > =3D=3D4306=3D=3D by 0x3447F6: monitor_qmp_event (monitor.c:3908) > =3D=3D4306=3D=3D by 0x480153: mux_chr_send_event (qemu-char.c:63= 0) > =3D=3D4306=3D=3D by 0x480694: mux_chr_event (qemu-char.c:734) > =3D=3D4306=3D=3D by 0x47F1E9: qemu_chr_be_event (qemu-char.c:205= ) > =3D=3D4306=3D=3D by 0x481207: fd_chr_close (qemu-char.c:1114) > =3D=3D4306=3D=3D by 0x481659: qemu_chr_close_stdio (qemu-char.c:= 1221) > =3D=3D4306=3D=3D by 0x486F07: qemu_chr_free (qemu-char.c:4146) > =3D=3D4306=3D=3D by 0x486F97: qemu_chr_delete (qemu-char.c:4154) > =3D=3D4306=3D=3D by 0x487E66: qemu_chr_cleanup (qemu-char.c:4678= ) > =3D=3D4306=3D=3D by 0x495A98: main (vl.c:4675) > =3D=3D4306=3D=3D Address 0x28439e90 is 112 bytes inside a block of= size 240 free'd > =3D=3D4306=3D=3D at 0x4C2CD5A: free (vg_replace_malloc.c:530) > =3D=3D4306=3D=3D by 0x1E4CBF2D: g_free (in /usr/lib64/libglib-2.= 0.so.0.4800.2) > =3D=3D4306=3D=3D by 0x344DE9: monitor_cleanup (monitor.c:4058) > =3D=3D4306=3D=3D by 0x495A93: main (vl.c:4674) > =3D=3D4306=3D=3D Block was alloc'd at > =3D=3D4306=3D=3D at 0x4C2BBAD: malloc (vg_replace_malloc.c:299) > =3D=3D4306=3D=3D by 0x1E4CBE18: g_malloc (in /usr/lib64/libglib-= 2.0.so.0.4800.2) > =3D=3D4306=3D=3D by 0x344BF8: monitor_init (monitor.c:4021) > =3D=3D4306=3D=3D by 0x49063C: mon_init_func (vl.c:2417) > =3D=3D4306=3D=3D by 0x7FC6DE: qemu_opts_foreach (qemu-option.c:1= 116) > =3D=3D4306=3D=3D by 0x4954E0: main (vl.c:4473) > ... >=20 > The following two patches fix this by unregistering the muxed chr handl= ers. If I read the code right, patch 1 without patch 2 can cause the mux_cnt to overflow the size of the d->chr_* arrays. Ok to invert the order? Thanks, Paolo >=20 > Marc-Andr=C3=A9 Lureau (2): > char: update read handler in all cases > char: use a fixed idx for child muxed chr >=20 > qemu-char.c | 24 ++++++++++++++++-------- > include/sysemu/char.h | 1 + > 2 files changed, 17 insertions(+), 8 deletions(-) >=20