From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C8B1BD512 for ; Mon, 12 Jun 2023 10:32:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50249C433D2; Mon, 12 Jun 2023 10:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686565933; bh=+keJ35w1Mwm1XG1akpgtGBh5lPJ0KeXMXauTf+X1jsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zIULG4t/JOGXZj8+KF2yu775Bat6CwCRrwCQneo8zSOE9M4tJvOJeQB7WS6tUMYNx iiyylU5Yz87OEM4SjoPA81/RMGAzk1Jx7KZUK22mW0mqB1FSmKi7emYg0T149McyjZ s0ku2LGF+hM7IDUkrjsymMACmB85YGG5VwSAO3Jg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ben Hutchings , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.4 17/45] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release() Date: Mon, 12 Jun 2023 12:26:11 +0200 Message-ID: <20230612101655.337916771@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612101654.644983109@linuxfoundation.org> References: <20230612101654.644983109@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Ben Hutchings [ Upstream commit 7c5d4801ecf0564c860033d89726b99723c55146 ] irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap. So we need to clear the pointer to our glue structure in rmap before doing that, not after. Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj array entries") Signed-off-by: Ben Hutchings Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/ZHo0vwquhOy3FaXc@decadent.org.uk Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- lib/cpu_rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c index 920403fa5b0de..51621fde0b488 100644 --- a/lib/cpu_rmap.c +++ b/lib/cpu_rmap.c @@ -268,8 +268,8 @@ static void irq_cpu_rmap_release(struct kref *ref) struct irq_glue *glue = container_of(ref, struct irq_glue, notify.kref); - cpu_rmap_put(glue->rmap); glue->rmap->obj[glue->index] = NULL; + cpu_rmap_put(glue->rmap); kfree(glue); } -- 2.39.2