From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF531355F5C for ; Mon, 13 Jul 2026 20:56:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783976205; cv=none; b=Trtat71W01g06kYruMFPkHN8mmia0EGXdW/dTaskOZicOHIT/Q+bISYep08VBPZDIpgu6XN1n2WwILCajwbmVkFD62C3sRETtWjQn7kQ5RGCSJf17XpDTU2jQEPbyrlckEh0rYWHFnLI7FKAXhm6SJRyjjaPyYsnl81x2pLsP+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783976205; c=relaxed/simple; bh=9EfNdVHht+pn5ku8/RprBfyqq6clf14podwcTzJUQy8=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=YayziOtR1tmO2bf3qJNuf90fq0aaCpNpbJ8FyG8c8rJyohNxF1r8p+UpTOp7/pDaZWAkP16AJX5jhg8lQIjEhiCCLZ0k7JvxWCJojeZ4NQak8bZQCLvt21xVc19dPMc7tVT5EXw+2rj8+fEJH7O2itIdqH+lTGGpOAn2bUuxmZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m2PccMWY; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m2PccMWY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 869261F000E9; Mon, 13 Jul 2026 20:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783976204; bh=E1eHw5sv1rlFVT28LoJja+efoEmdreliANF29qXqM+0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=m2PccMWYXO/v1w4uGi3tDuJxep9ou593iuu40sHrQ7ZbyTT4fWWij41aWo22rbXAO JrA7K6tDdsfCSSXxFh2vLvmgnpVu20CFB5l9nv3ujo2boyOutrRM5II3zOPd+Sjco9 NG62+wWF+0Gf8UKnW6qh0n0SLZCkwGI2gUSXnKK/Al0PFz9zZdt9iXjzcf57e8RVlP pglnIrf8TRtiUX3IpBa+D2Go7I65T1x6WvSgVt970Lm71JPptZj5H3WQ/uhSWbAeWd xx0i73xmGZn3737KIuli9stAKyB78XqXzsC8gJF4ex0FAwXsTEAnEO4HpYDUKzZAck 40L4UPXjrIRpw== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wjNhi-00000004dsB-3HFh; Mon, 13 Jul 2026 20:56:42 +0000 Date: Mon, 13 Jul 2026 21:58:32 +0100 Message-ID: <874ii261zb.wl-maz@kernel.org> From: Marc Zyngier To: Kemeng Shi Cc: tglx@kernel.org, jason@lakedaemon.net, lpieralisi@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 3/6] irqchip/gic-v3-its: Fix leak in its_vpe_irq_domain_alloc() In-Reply-To: <3c684d7d-75ec-49dd-b735-174ec9385974@huaweicloud.com> References: <20260702033050.1583-1-shikemeng@huaweicloud.com> <20260702033050.1583-4-shikemeng@huaweicloud.com> <87fr216nx2.wl-maz@kernel.org> <86ldbopl97.wl-maz@kernel.org> <3c684d7d-75ec-49dd-b735-174ec9385974@huaweicloud.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: shikemeng@huaweicloud.com, tglx@kernel.org, jason@lakedaemon.net, lpieralisi@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 13 Jul 2026 14:05:06 +0100, Kemeng Shi wrote: >=20 > =E5=9C=A8 2026/7/6 16:36:52, Marc Zyngier =E5=86=99=E9=81=93: > > On Fri, 03 Jul 2026 02:44:53 +0100, > > Kemeng Shi wrote: > >> > >> =E5=9C=A8 2026/7/3 6:12:57, Marc Zyngier =E5=86=99=E9=81=93: > >>>> When its_irq_gic_domain_alloc() fails, the following > >>>> its_vpe_irq_domain_free() skips calling its_vep_teardown() for the > >>>> corresponding irq. Call its_vpe_teardown() when its_irq_gic_domain_a= lloc() > >>>> is failedto avoid the leak issue. > >>>> > >>>> Fixes: 7d75bbb4bc1ad ("irqchip/gic-v3-its: Add VPE irq domain alloca= tion/teardown") > >>>> Signed-off-by: Kemeng Shi > >>>> --- > >>>> drivers/irqchip/irq-gic-v3-its.c | 4 +++- > >>>> 1 file changed, 3 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-= gic-v3-its.c > >>>> index 3e4edcb64065..8968bedefdba 100644 > >>>> --- a/drivers/irqchip/irq-gic-v3-its.c > >>>> +++ b/drivers/irqchip/irq-gic-v3-its.c > >>>> @@ -4666,8 +4666,10 @@ static int its_vpe_irq_domain_alloc(struct ir= q_domain *domain, unsigned int virq > >>>> break; > >>>> err =3D its_irq_gic_domain_alloc(domain, virq + i, > >>>> vm->vpes[i]->vpe_db_lpi); > >>>> - if (err) > >>>> + if (err) { > >>>> + its_vpe_teardown(vm->vpes[i]); > >>>> break; > >>>> + } > >>> There is already a spot for error handling in this function, we don't > >>> need a second one. > >> When its_irq_gic_domain_alloc() fails at index i, its_vpe_init(vpes[i]) > >> has already succeeded but the exisiting its_vpe_irq_domain_free(domain= , virq, i) > >> only tears down VPEs with index [0, i - 1], so its_vpe_teardown(vpes[i= ]) is still > >> needed. > >> So I guess you mean we can increase index when its_irq_gic_domain_allo= c() fails to > >> free the resource with existing error handling? > >> Please correct me if I'm miss anything. > >=20 > > What I mean is this. > >=20 > > M. > > =09 > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic= -v3-its.c > > index b57d81ad33a0a..4b1a3b497d7c4 100644 > > --- a/drivers/irqchip/irq-gic-v3-its.c > > +++ b/drivers/irqchip/irq-gic-v3-its.c > > @@ -4674,8 +4674,10 @@ static int its_vpe_irq_domain_alloc(struct irq_d= omain *domain, unsigned int virq > > irqd_set_resend_when_in_progress(irq_get_irq_data(virq + i)); > > } > > =20 > > - if (err) > > + if (err) { > > + its_vpe_teardown(vm->vpes[i]); > When its_vpe_init() fails, the error path calls its_vpe_teardown(vm->vpes= [i]) on > an uninitialized vpe, which may cause a NULL dereference by access NULL v= pt_page in > its_vpe_teardown(vm->vpes[i])->its_free_pending_table(vpe->vpt_page)->pag= e_address(pt). >=20 > To reuse the existing spot, something like a flag to indicate whether its= _vpe_init() > succeeded should be added. Maybe we can keep change of this patch which s= eems simpler. This is becoming a bit tedious. It's not like a managing the life cycle of a pointer and checking for its validity is particularly hard, is it? M. --=20 Jazz isn't dead. It just smells funny.