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 9B6201641AE; Mon, 29 Jan 2024 17:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706548416; cv=none; b=YXvqPeHnR1cQGIiLfc/91Yn4fB3WslYFh68mhP7pVemBUighLdpb+0gqJ71y52fYB8pt4bC33n0mbzP/GlsfAEjKogpp6G+dB0QJFR+2b00JYOJN+/wjb3kgeqsqwzLo5ldaJDc6VNYyJZ1SAEgbdfq5pyHcZB1T2Pi7hzgb2ho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706548416; c=relaxed/simple; bh=MA+smWX36Cj0dYSbxB7dem9AhN0pLwHzw51cWraTJ0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxahIIqEHH59iut3GoKqFbvizWkpPdjDmdqHJ16pldGRssm/nSI7qOoXOk2SgcVeSUvanMzrjFFXUcHC/7LjG2e+ZnCzDrV+gP8WzV0AsexBV2FZX1J48iTOWnuv2tOD8vxEo6d1wNhmSt9YiTXJfokT5+UC/GG6clOYuDJYhXs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PLg4ZJUr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PLg4ZJUr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 649FEC43390; Mon, 29 Jan 2024 17:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706548416; bh=MA+smWX36Cj0dYSbxB7dem9AhN0pLwHzw51cWraTJ0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PLg4ZJUrZ5EEUSMxZC9iPzCI350v64XfLF1NeIxqXyPB9lg8i2AOCmpy1HCIX+PI7 6uXvr0aXdZdyFMZivYVpl0Woa6kvTHTsgWoee+cORtXG/HtW9HxyPD/ojHa6z+SIeA qVP6ywGgNwa/OKbT1+xko+UgF1oONarCXeetkD98= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Amelie Delaunay , Dave Jiang , Vinod Koul , Sasha Levin Subject: [PATCH 6.6 014/331] dmaengine: fix NULL pointer in channel unregistration function Date: Mon, 29 Jan 2024 09:01:18 -0800 Message-ID: <20240129170015.382016015@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129170014.969142961@linuxfoundation.org> References: <20240129170014.969142961@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amelie Delaunay [ Upstream commit f5c24d94512f1b288262beda4d3dcb9629222fc7 ] __dma_async_device_channel_register() can fail. In case of failure, chan->local is freed (with free_percpu()), and chan->local is nullified. When dma_async_device_unregister() is called (because of managed API or intentionally by DMA controller driver), channels are unconditionally unregistered, leading to this NULL pointer: [ 1.318693] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000d0 [...] [ 1.484499] Call trace: [ 1.486930] device_del+0x40/0x394 [ 1.490314] device_unregister+0x20/0x7c [ 1.494220] __dma_async_device_channel_unregister+0x68/0xc0 Look at dma_async_device_register() function error path, channel device unregistration is done only if chan->local is not NULL. Then add the same condition at the beginning of __dma_async_device_channel_unregister() function, to avoid NULL pointer issue whatever the API used to reach this function. Fixes: d2fb0a043838 ("dmaengine: break out channel registration") Signed-off-by: Amelie Delaunay Reviewed-by: Dave Jiang Link: https://lore.kernel.org/r/20231213160452.2598073-1-amelie.delaunay@foss.st.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/dmaengine.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index b7388ae62d7f..491b22240221 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -1103,6 +1103,9 @@ EXPORT_SYMBOL_GPL(dma_async_device_channel_register); static void __dma_async_device_channel_unregister(struct dma_device *device, struct dma_chan *chan) { + if (chan->local == NULL) + return; + WARN_ONCE(!device->device_release && chan->client_count, "%s called while %d clients hold a reference\n", __func__, chan->client_count); -- 2.43.0