Received: from eggs.gnu.org ([2001:4830:134:3::10]:55371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baZEm-0002hO-FN for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:08:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baZEg-0004KM-Dp for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:08:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baZEg-0004KD-8Z for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:08:42 -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 B4BE881235 for ; Fri, 19 Aug 2016 02:08:41 +0000 (UTC) References: <20160818134405.26424-1-marcandre.lureau@redhat.com> From: Jason Wang Message-ID: Date: Fri, 19 Aug 2016 10:08:37 +0800 MIME-Version: 1.0 In-Reply-To: <20160818134405.26424-1-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] slirp: fix segv when init failed 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: pbonzini@redhat.com On 2016=E5=B9=B408=E6=9C=8818=E6=97=A5 21:44, Marc-Andr=C3=A9 Lureau wrot= e: > Since commit f6c2e66ae8c8a, slirp uses an exit notifier to call > slirp_smb_cleanup. However, if init() failed, the notifier isn't added, > and removing it will fail: > > =3D=3D18447=3D=3D Invalid write of size 8 > =3D=3D18447=3D=3D at 0x7EF2B5: notifier_remove (notify.c:32) > =3D=3D18447=3D=3D by 0x48E80C: qemu_remove_exit_notifier (vl.c:2661) > =3D=3D18447=3D=3D by 0x6A2187: net_slirp_cleanup (slirp.c:134) > =3D=3D18447=3D=3D by 0x69419D: qemu_cleanup_net_client (net.c:338) > =3D=3D18447=3D=3D by 0x69445B: qemu_del_net_client (net.c:401) > =3D=3D18447=3D=3D by 0x6A2B81: net_slirp_init (slirp.c:366) > =3D=3D18447=3D=3D by 0x6A4241: net_init_slirp (slirp.c:865) > =3D=3D18447=3D=3D by 0x695C6D: net_client_init1 (net.c:1051) > =3D=3D18447=3D=3D by 0x695F6E: net_client_init (net.c:1108) > =3D=3D18447=3D=3D by 0x696DBA: net_init_netdev (net.c:1498) > =3D=3D18447=3D=3D by 0x7F1F99: qemu_opts_foreach (qemu-option.c:1116= ) > =3D=3D18447=3D=3D by 0x696E60: net_init_clients (net.c:1516) > =3D=3D18447=3D=3D Address 0x0 is not stack'd, malloc'd or (recently) f= ree'd > > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > net/slirp.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/net/slirp.c b/net/slirp.c > index facc30e..b60893f 100644 > --- a/net/slirp.c > +++ b/net/slirp.c > @@ -131,7 +131,9 @@ static void net_slirp_cleanup(NetClientState *nc) > SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); > =20 > slirp_cleanup(s->slirp); > - qemu_remove_exit_notifier(&s->exit_notifier); > + if (s->exit_notifier.notify) { > + qemu_remove_exit_notifier(&s->exit_notifier); > + } > slirp_smb_cleanup(s); > QTAILQ_REMOVE(&slirp_stacks, s, entry); > } Applied to -net for 2.7. Thanks