Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9119730pxu; Mon, 28 Dec 2020 07:07:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzraDcZ4E8YnzxmacsBOfS1IZJgg73Hz8sf61C1fgJkt4A92JfwJJ2yW0I+GYeYNMDCQrVA X-Received: by 2002:aa7:d459:: with SMTP id q25mr42286975edr.279.1609168051241; Mon, 28 Dec 2020 07:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609168051; cv=none; d=google.com; s=arc-20160816; b=T/za3hsU+lQkV6cVMMLOXlwvLHoDP7cwvMgn5dgKBYykha3n6L2UZq2LbyX7cXC8kO flfzMUAbj4CSClWZSPBeiE3D2bnml+SPun+iayYBhReRpGde+/LUHormxGpCCAYvlb0b Ryx7rMnCrKDSLMb9U6jv/MLkgekXMuATkbigT9Vlfs3gLdRNChjvFoDw/bRO3nz9dms9 525KTIJEWsMjmZD9L3Jh91on2l8RDxi+CehWEE1hnjRe0RBl8RZncW7F7486hJv2heXI 0AqrZV5or3w/AbX1CJ9YyFrVnCHJLL/Dev5HNzBKtYdJTqpnORtSuQJkU0uylw/Ly7lC s0Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ypWoOwz1ysqwjAbDp0Nyw1Ql2AJYrDxkq7NRSZZtaP8=; b=GZ+HwkFQdJhujBbq+AKcQ8Bd8y2w8qe+2GGKPt7kNHg4osn53n2VHUq9Rn1rtV7lRh bB/Wc4LK4cXv9bKe6Y/h6zMEf2P2LQq/xwmmggGFEXat1VKfnVoICgMsRuu2MiLPXMFD pmxqYM+ma4jUbmJnbes/hM+dY4FSGAAOBaRN8EtVU8sOBEU7RkLbzknHzkAwpaJWpYvp 8hySDP0MsfJyD0MtP6uaMAOTdmz8QNlnUD98LJeqyiOAX71GVWaPpRkQCIlqF9CjD/fC DTJp4fyCJIXEDtA58ftOgQIK2CUkkN9UOXhEMsRu23hsbOkcAPkp278H5MP4UWaEUyMn kQlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3AbbujC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf18si18713308ejb.202.2020.12.28.07.07.08; Mon, 28 Dec 2020 07:07:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3AbbujC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439644AbgL1OL1 (ORCPT + 99 others); Mon, 28 Dec 2020 09:11:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:45302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439113AbgL1OKp (ORCPT ); Mon, 28 Dec 2020 09:10:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84B84207AB; Mon, 28 Dec 2020 14:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164605; bh=Z5GmOLu91jeUJl+RSVW2l8+cxGJv73ZlIK0VswWH3ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q3AbbujCsLmtHvoWPmRJsxF0V+qoxvFgxpKgz0yBjuUbaHe6FFCFBThmrxUL0ra5w afm576LPrIpRU3OEdwKsFmyMBnCpD8LN4OHgk7YizN/4kvrxEDx+KlrZiOo2WqLWQ8 roVJMkzCuLnSeM16+uqOsfba+7io8ODr2k/0+9Fk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Zyngier , Thomas Gleixner , Sasha Levin Subject: [PATCH 5.10 233/717] genirq/irqdomain: Dont try to free an interrupt that has no mapping Date: Mon, 28 Dec 2020 13:43:51 +0100 Message-Id: <20201228125032.151313790@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit 4615fbc3788ddc8e7c6d697714ad35a53729aa2c ] When an interrupt allocation fails for N interrupts, it is pretty common for the error handling code to free the same number of interrupts, no matter how many interrupts have actually been allocated. This may result in the domain freeing code to be unexpectedly called for interrupts that have no mapping in that domain. Things end pretty badly. Instead, add some checks to irq_domain_free_irqs_hierarchy() to make sure that thiss does not follow the hierarchy if no mapping exists for a given interrupt. Fixes: 6a6544e520abe ("genirq/irqdomain: Remove auto-recursive hierarchy support") Signed-off-by: Marc Zyngier Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20201129135551.396777-1-maz@kernel.org Signed-off-by: Sasha Levin --- kernel/irq/irqdomain.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index e4ca69608f3b8..c6b419db68efc 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1373,8 +1373,15 @@ static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain, unsigned int irq_base, unsigned int nr_irqs) { - if (domain->ops->free) - domain->ops->free(domain, irq_base, nr_irqs); + unsigned int i; + + if (!domain->ops->free) + return; + + for (i = 0; i < nr_irqs; i++) { + if (irq_domain_get_irq_data(domain, irq_base + i)) + domain->ops->free(domain, irq_base + i, 1); + } } int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain, -- 2.27.0