Received: from eggs.gnu.org ([2001:4830:134:3::10]:40953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkpUA-0004h7-96 for qemu-devel@nongnu.org; Fri, 16 Sep 2016 05:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkpU7-000123-IV for qemu-devel@nongnu.org; Fri, 16 Sep 2016 05:31:06 -0400 Received: from 4.mo177.mail-out.ovh.net ([46.105.37.72]:33513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkpU7-00011h-8g for qemu-devel@nongnu.org; Fri, 16 Sep 2016 05:31:03 -0400 Received: from player699.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id 42A3BFFD080 for ; Fri, 16 Sep 2016 11:31:01 +0200 (CEST) References: <147398054143.25432.18026157491978434193.stgit@bahia> <20160916091955.0706cc6a@bahia> <1a7c2900-5e47-b1a1-e18f-c4d950d90978@kaod.org> <20160916105207.3d14af87@bahia> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= Message-ID: Date: Fri, 16 Sep 2016 11:30:54 +0200 MIME-Version: 1.0 In-Reply-To: <20160916105207.3d14af87@bahia> 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: Greg Kurz Cc: qemu-devel@nongnu.org, Paolo Bonzini , qemu-stable@nongnu.org, "Aneesh Kumar K.V" , Michael Roth On 09/16/2016 10:52 AM, Greg Kurz wrote: > On Fri, 16 Sep 2016 09:37:48 +0200 > C=C3=A9dric Le Goater wrote: >=20 >> 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= _free() >>>> on uninitialized paths. >>>> =20 >>> >>> I'll add this to the changelog: >>> >>> It is a regression introduced by the following commit: >>> >>> 56f101ecce0e 9pfs: handle walk of ".." in the root directory >>> =20 >>>> Let's fix this by initializing dpath and path before calling fid_to_= qid(). >>>> >>>> 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 = present >>>> 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 >> >> >> There is still a possible segv I think, in out_nofid : >> >> 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: ah yes. I got confused by the structures. Reviewed-by: C=C3=A9dric Le Goater C. > 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; > } >=20 > But I agree that the calls to v9fs_string_free() without the correspond= ing > calls to v9fs_string_init(), as it is done everywhere else, is disturbi= ng > and should be addressed. >=20 > Thanks. >=20 > -- > Greg >=20 >> >> >> C. >> >> >> >> >=20