Received: from eggs.gnu.org ([2001:4830:134:3::10]:57583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkosg-0005VQ-Ao for qemu-devel@nongnu.org; Fri, 16 Sep 2016 04:52:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkosb-0001sh-BG for qemu-devel@nongnu.org; Fri, 16 Sep 2016 04:52:22 -0400 Received: from 10.mo6.mail-out.ovh.net ([87.98.157.236]:40267) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkosb-0001sJ-2b for qemu-devel@nongnu.org; Fri, 16 Sep 2016 04:52:17 -0400 Received: from player776.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 2894AFFBFA3 for ; Fri, 16 Sep 2016 10:52:16 +0200 (CEST) Date: Fri, 16 Sep 2016 10:52:07 +0200 From: Greg Kurz Message-ID: <20160916105207.3d14af87@bahia> In-Reply-To: <1a7c2900-5e47-b1a1-e18f-c4d950d90978@kaod.org> References: <147398054143.25432.18026157491978434193.stgit@bahia> <20160916091955.0706cc6a@bahia> <1a7c2900-5e47-b1a1-e18f-c4d950d90978@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] 9pfs: fix potential segfault during walk List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?Q8OpZHJpYw==?= Le Goater Cc: qemu-devel@nongnu.org, Paolo Bonzini , qemu-stable@nongnu.org, "Aneesh Kumar K.V" , Michael Roth On Fri, 16 Sep 2016 09:37:48 +0200 C=C3=A9dric Le Goater wrote: > On 09/16/2016 09:19 AM, Greg Kurz wrote: > > On Fri, 16 Sep 2016 01:05:11 +0200 > > Greg Kurz wrote: > > =20 > >> If the call to fid_to_qid() returns an error, we will call v9fs_path_f= ree() > >> on uninitialized paths. > >> =20 > >=20 > > I'll add this to the changelog: > >=20 > > It is a regression introduced by the following commit: > >=20 > > 56f101ecce0e 9pfs: handle walk of ".." in the root directory > > =20 > >> Let's fix this by initializing dpath and path before calling fid_to_qi= d(). > >> > >> Signed-off-by: Greg Kurz > >> --- > >> > >> Thanks Paolo (and Coverity) for spotting this. > >> > >> Cc'ing stable as this is a regression introduced in 2.7. It is also pr= esent > >> in Michael's stable-2.6-staging branch. > >> > >> hw/9pfs/9p.c | 5 +++-- > >> 1 file changed, 3 insertions(+), 2 deletions(-) > >> > >> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c > >> index dfe293d11d1c..91a497079acb 100644 > >> --- a/hw/9pfs/9p.c > >> +++ b/hw/9pfs/9p.c > >> @@ -1320,13 +1320,14 @@ static void v9fs_walk(void *opaque) > >> goto out_nofid; > >> } > >> =20 > >> + v9fs_path_init(&dpath); > >> + v9fs_path_init(&path); > >> + > >> err =3D fid_to_qid(pdu, fidp, &qid); > >> if (err < 0) { > >> goto out; > >> } > >> =20 > >> - v9fs_path_init(&dpath); > >> - v9fs_path_init(&path); > >> /* > >> * Both dpath and path initially poin to fidp. > >> * Needed to handle request with nwnames =3D=3D 0 > >> =20 > >=20 > > =20 >=20 >=20 > There is still a possible segv I think, in out_nofid : >=20 > if (nwnames && nwnames <=3D P9_MAXWELEM) { > for (name_idx =3D 0; name_idx < nwnames; name_idx++) { > v9fs_string_free(&wnames[name_idx]); > =20 > &wnames[name_idx] could NULL if pdu_unmarshal() fails. >=20 We're safe because wnames[] is fully allocated and zeroed: if (nwnames && nwnames <=3D P9_MAXWELEM) { wnames =3D g_malloc0(sizeof(wnames[0]) * nwnames); <--- here qids =3D g_malloc0(sizeof(qids[0]) * nwnames); for (i =3D 0; i < nwnames; i++) { err =3D pdu_unmarshal(pdu, offset, "s", &wnames[i]); if (err < 0) { goto out_nofid; } But I agree that the calls to v9fs_string_free() without the corresponding calls to v9fs_string_init(), as it is done everywhere else, is disturbing and should be addressed. Thanks. -- Greg >=20 >=20 > C. >=20 >=20 >=20 >=20