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 9308C41443C; Wed, 23 Sep 2026 14:13:10 +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=1790172791; cv=none; b=r0yZ4QY77wyIteOrx1Mw7hoElEYC4/uT8TyxuPOX9Ct0wy6WaLdCc+CT/z2U+o+3S7b2qxj4bZda4NohHfKxYEVInPDQUEPmGEgOcRRwzJDjZw77dqNYSD+FabiO6cTeJQTHZ8l3Ywp6x/CEFcTCYZB7Pa0BxE+eq2jqyw6MNmc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790172791; c=relaxed/simple; bh=aVnSVd6GTz0/uUrkb1eGiur4SU0EZmk/v4pEWsAPFzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MOdPnEhQrcQeHcZfGz/2ghRaDZnPkmvaPLAGQOm7EkQG6MlFUGrnxqg295skhs4TMQ7Auxil4BixiDhrNFWvABL+89RzOUhpn9nRSykGQxYplJ4Q6HcWLcN8Q1b4B4/JrkmQaqnUCt+xXHnkf5Lcq5JJ4ba6SlrWi1D+TaGf/S0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=d4y1VuCd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="d4y1VuCd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DE2F1F000FF; Wed, 23 Sep 2026 14:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790172790; bh=orQwFfY+ovdapEbvDt8GwNdW0tHbPO2kHPnHHROYhww=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d4y1VuCdTwW/hajE+H+FcadnZTG5HjoYjOxiA8h1s/fyDpGLYL96jGkqan8DkNjj4 nPTi2CvyyqVbmhWxPfhp22Av/X3DPYB7T5rFnoBbldAK4e6SVCFkQAC/o2hUJx+B9r jj4jCBWTKk/SS9MH67aUZLw5/Gxh6sreCKjvZaoU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Frank Li , Logan Gunthorpe , Shivank Garg , Vinod Koul , Sasha Levin Subject: [PATCH 7.2 062/438] dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel() Date: Wed, 23 Sep 2026 16:01:23 +0200 Message-ID: <20260923140646.401414046@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260923140644.756254324@linuxfoundation.org> References: <20260923140644.756254324@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shivank Garg [ Upstream commit e873c74132f0c5f1452816cd9bb26208f0bba1e1 ] When dma_device_put() drops the last reference on chan->device->ref, dma_device_release() runs and may free the dma_device along with its channels. dma_chan_put() then still reads chan->device->owner via dma_chan_to_owner() for the trailing module_put(). KASAN catches it: slab-use-after-free in dma_chan_put+0x3e6/0x4c0 Read of size 8 by task insmod/6319 Freed by task 6319: kfree+0x225/0x470 dma_chan_put+0x395/0x4c0 dmaengine_put+0xf8/0x160 Cache the module owner in dma_chan_put() before the put so the trailing module_put() does not need chan->device. Fixes: 8ad342a86359 ("dmaengine: Add reference counting to dma_device struct") Suggested-by: Sashiko Link: https://sashiko.dev/#/patchset/20260518-dmaengine-kref-fix-v1-1-4d6125048fb7@amd.com Reviewed-by: Frank Li Reviewed-by: Logan Gunthorpe Signed-off-by: Shivank Garg Link: https://patch.msgid.link/20260822-dmaengine-kref-fix-v5-3-d4a4ee47d927@amd.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/dmaengine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 4d8c6655c7a15..7de33df0529a7 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -495,10 +495,13 @@ static int dma_chan_get(struct dma_chan *chan) */ static void dma_chan_put(struct dma_chan *chan) { + struct module *owner; + /* This channel is not in use, bail out */ if (!chan->client_count) return; + owner = dma_chan_to_owner(chan); chan->client_count--; /* This channel is not in use anymore, free it */ @@ -518,7 +521,7 @@ static void dma_chan_put(struct dma_chan *chan) /* This channel is not in use anymore, drop the device ref */ if (!chan->client_count) dma_device_put(chan->device); - module_put(dma_chan_to_owner(chan)); + module_put(owner); } enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie) -- 2.53.0