From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9AD62C54E68 for ; Thu, 21 Mar 2024 12:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ng2QeUp+kj+aIR+UmrWIGyEuaqm7MkbVMHPwajdtz3Q=; b=kSdp495YaFl66Ks/1Tk/GrdSP6 SnckNmUCFuadvWrbcq7IHIhP5F041lmtoiXoIQ1rzbAwpihcM3vdNunW2lKUeqy7LjyWfvtxbaCaQ B3w0EaIq4mDE5gBwFSwheGI7Ts5cDUce6EacjEdIWJgUn/JpbMyq1adznTwy2ftRjt0oyoARppWWn Lm3ucoGMgJn/0aMUO+VXjlF/MT9a5DW18chUyPpfkehEQhGhWoUXQ6/J8OJwdc9jpnByR4hTDVFl+ jh11gzHrN4/VWqBx8LTufERaGMdfmkiJX3vwcBBP+opHnEcb+OLkpYRR06KYhXA4GKIZ+ghGw3wlt /WnYX1kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnHls-000000030M8-2FHt; Thu, 21 Mar 2024 12:43:48 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnHlp-000000030LG-20Ar for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2024 12:43:46 +0000 Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4V0lSH2Vhvz1R7nm; Thu, 21 Mar 2024 20:41:03 +0800 (CST) Received: from kwepemm600007.china.huawei.com (unknown [7.193.23.208]) by mail.maildlp.com (Postfix) with ESMTPS id 0BDD41A0172; Thu, 21 Mar 2024 20:43:38 +0800 (CST) Received: from [10.174.185.179] (10.174.185.179) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 20:43:37 +0800 Subject: Re: [PATCH] irqchip/gic-v3-its: Fix double free on error To: Guanrui Huang CC: , , , , References: <20240321110454.89410-1-guanrui.huang@linux.alibaba.com> From: Zenghui Yu Message-ID: Date: Thu, 21 Mar 2024 20:43:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20240321110454.89410-1-guanrui.huang@linux.alibaba.com> Content-Language: en-US X-Originating-IP: [10.174.185.179] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600007.china.huawei.com (7.193.23.208) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_054345_729812_2C24A521 X-CRM114-Status: GOOD ( 20.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2024/3/21 19:04, Guanrui Huang wrote: > In its_vpe_irq_domain_alloc, when its_vpe_init() returns an error > with i > 0, its_vpe_irq_domain_free may free bitmap and vprop_page, > and then there is a double free in its_vpe_irq_domain_alloc. > > Fix it by checking if bitmap is empty in its_vpe_irq_domain_alloc. > If bitmap is empty and i > 0, means that bitmap have been clear and free > in its_vpe_irq_domain_free. > > Signed-off-by: Guanrui Huang > --- > drivers/irqchip/irq-gic-v3-its.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > index fca888b36680..98a1be90caef 100644 > --- a/drivers/irqchip/irq-gic-v3-its.c > +++ b/drivers/irqchip/irq-gic-v3-its.c > @@ -4562,9 +4562,14 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq > } > > if (err) { > - if (i > 0) > + if (i > 0) { > its_vpe_irq_domain_free(domain, virq, i); > > + /* bitmap and vprop_page be freed in its_vpe_irq_domain_free */ > + if (bitmap_empty(bitmap, nr_ids)) It looks like that 'bitmap' can't be non-empty if you managed to get here. Right? > + return err; > + } > + > its_lpi_free(bitmap, base, nr_ids); > its_free_prop_table(vprop_page); > } Is it possible that we handle these 2 cases together? I.e., does the following approach help? if (err) its_vpe_irq_domain_free(domain, virq, i); Thanks, Zenghui _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel