Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9043403pxu; Mon, 28 Dec 2020 05:15:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUi07f8/ZTdD5cpji3bg470pa0id8a00VQVThoI4B8O0z61bHaDihYm2ZC1K5o/hI92PzS X-Received: by 2002:a50:fc8b:: with SMTP id f11mr42391247edq.11.1609161306160; Mon, 28 Dec 2020 05:15:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161306; cv=none; d=google.com; s=arc-20160816; b=DMrvqIl6vJuL3TsDOVPCFywlX5zzJDk+SmzdUobBneiGd1Oqfn7eDUOEozl1UjDxcq o2y2pM3urYycdXOvYaA1XLXHhKsKg1GJqx6zbz84gZwAgrChyp1hntB2GfJkaS2XhLpx f6xS0RmDCoryJAbiaAT6VFgb2fJ8whaWeIZ3CUW+CdtnBigWdobmjDBvfJP6D9wATP6j mCwVuylATw5AXXoCEigfBvn5AAkZM35PtAsYLjMSDdiIFpKvn3UT47lrtZ+c+uUmtmcR s+XHio4Ww1qfknkEg3NFCr8DqHvNWGEgk1aZ+X4IZwfqC3L6U/Zwcw6ZHB0g8beEcYJ/ u/iA== 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=tuUUVFUrPBUa/ANZa3RIm8CR3asN2nJvKaGhe4OKi90=; b=Vrp7EMDGI0K8ACZtCyzNSmxDFBVxjCVd8WRb3qx/ZxDfXMZFX6f5+hiVXwpItacVkW 7MtYqh+m4sQsK1dGZDzSO/6Rl2sgAU7jlzB+tVmu2Yt3AAOj8m/0oYPSyl+PNGl07ff3 Bq6rsMqtJaWn9D+e7iOE2PTlkn9b8NZYWZidIpGoM/wAhQe8GBeWneBdCrVqsQMidI2K DycLNsZhStOS3IwQppXfApXsQ7+Soi9H7iVDmEDWvFZlj6NeYHXc2PXKS3IXwRhhWzOl 5jDEVgDxpNJ6F8jj1m2GBgHZ8C4lEUxol1bEJ699Cc5/XD76s1/XSO9U6xO7AOYuEYzI 8smw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wBgil7U/"; 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 o22si20262417edq.400.2020.12.28.05.14.43; Mon, 28 Dec 2020 05:15:06 -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="wBgil7U/"; 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 S1732152AbgL1NMs (ORCPT + 99 others); Mon, 28 Dec 2020 08:12:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:40112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732149AbgL1NMr (ORCPT ); Mon, 28 Dec 2020 08:12:47 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 28D7220728; Mon, 28 Dec 2020 13:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161151; bh=ubpvGQAi+4xzZy3SHNH2TkM7VPePppAwaNcDFHGmGeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wBgil7U/+wVxHrEwWn+F5oO6rvC1h80zbBf/gHzYR1V0A9FeBSeQUaLNysaR+iLXA Qp88i/NTPpDC16O+YBYYh04eYsBZ+YfhbMXY550zWnfwkftvKNr+2aS0F8QB/FPawG deDEcNBHZbp1D2NL8AhQUaUeVGK+sM4tCTO4H5bM= 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 4.14 119/242] genirq/irqdomain: Dont try to free an interrupt that has no mapping Date: Mon, 28 Dec 2020 13:48:44 +0100 Message-Id: <20201228124910.553037007@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 0d54f8256b9f4..cafea68749e0a 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1364,8 +1364,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