Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B6E7C43334 for ; Wed, 29 Jun 2022 13:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbiF2NGW (ORCPT ); Wed, 29 Jun 2022 09:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbiF2NGU (ORCPT ); Wed, 29 Jun 2022 09:06:20 -0400 Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A696D34BA6; Wed, 29 Jun 2022 06:06:18 -0700 (PDT) Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 641811C0C05; Wed, 29 Jun 2022 15:06:17 +0200 (CEST) Date: Wed, 29 Jun 2022 15:06:17 +0200 From: Pavel Machek To: Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Liang He , Thomas Bogendoerfer , yangtiezhu@loongson.cn, linux-mips@vger.kernel.org Subject: Re: [PATCH AUTOSEL 4.9 11/13] mips/pic32/pic32mzda: Fix refcount leak bugs Message-ID: <20220629130617.GE13395@duo.ucw.cz> References: <20220628022657.597208-1-sashal@kernel.org> <20220628022657.597208-11-sashal@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="X3gaHHMYHkYqP6yf" Content-Disposition: inline In-Reply-To: <20220628022657.597208-11-sashal@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org --X3gaHHMYHkYqP6yf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Liang He >=20 > [ Upstream commit eb9e9bc4fa5fb489c92ec588b3fb35f042ba6d86 ] >=20 > of_find_matching_node(), of_find_compatible_node() and > of_find_node_by_path() will return node pointers with refcout > incremented. We should call of_node_put() when they are not > used anymore. It looks like this may introduces an use-after-free bug: > +++ b/arch/mips/pic32/pic32mzda/init.c > @@ -131,13 +131,18 @@ static int __init pic32_of_prepare_platform_data(st= ruct of_dev_auxdata *lookup) > np =3D of_find_compatible_node(NULL, NULL, lookup->compatible); > if (np) { > lookup->name =3D (char *)np->name; > - if (lookup->phys_addr) > + if (lookup->phys_addr) { > + of_node_put(np); > continue; > + } > if (!of_address_to_resource(np, 0, &res)) > lookup->phys_addr =3D res.start; > + of_node_put(np); > } > } lookup->name now contains pointer taken from np->name, but we did put() on the np. What guarantees np->name is not freed? Best regards, Pavel --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --X3gaHHMYHkYqP6yf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRPfPO7r0eAhk010v0w5/Bqldv68gUCYrxOSQAKCRAw5/Bqldv6 8sEMAJ9Wi5qZTh56Crna6boxGUkle0M5/QCgsd1WeGfdmFHYdY1YLbCN29nJ5yA= =mGn2 -----END PGP SIGNATURE----- --X3gaHHMYHkYqP6yf--