Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5417320rdb; Wed, 13 Dec 2023 08:06:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqvDFF+TK5Ln0cxTftuFkCpLMDd48H6DPSGH9y9DvjDWpzhrpq3NnWm4B9+cLBYKfuPGmM X-Received: by 2002:a17:903:190:b0:1cf:88d9:c3b1 with SMTP id z16-20020a170903019000b001cf88d9c3b1mr5008457plg.62.1702483567972; Wed, 13 Dec 2023 08:06:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702483567; cv=none; d=google.com; s=arc-20160816; b=fXlnJaRCdxn80kOXMCl/epDTsnfFGudfsNjgdBojxrKrkqlCDxMRhlG9mpCSiHavbQ cwLjbAtC6e89LJEyub3/FGzcnbzI65WByw35U5GjH5aHb2qVAqDsDDYJoil9yxfVJr5W MwBfUB7xZPK3Xo3svw9eigxVsq8JcXa57h852f8F6fyM2VxAVh5eEtmF6Z4SbMKMkFjt IgUV6Yn4IgGjaodtKIniByN0liTMpD0P6eOH7/E0G7kAqY9K2nuHjvUOQMcmu0xb3G30 qDKi+5ZNF52CZbH/w5u3TpFy3uGLNTVFW9ergh9kfeXcgTPN4A+0aKLT54Yp8HT1BgHT cogw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vP0CuvtnE+r/ntZNTtv47/xL+GFWmIspcly1Iqw0j54=; fh=Pds6JOqLhIxYGh60MD8BxQAK2lsDexWaUz5dqOS89hc=; b=bF2J8blfoQJ5GxPS01Lpck2pjxE+puW4zbl97VTx022rdUEAUiQmF7hQE1/PvOVPC8 c4hCtYzchUt1ef7gDnRPDXWQOwLcYNVOEtHnKoaZOywcMPScpjg7ZXrHcZbQd4jHN5Te Bh2ct+ByiSvetzrNXWdbsaqO0kHYbm39FK2qoTgVLa5MEcmhlKEfYwQo37pUC2kbEdIb +cpb2z6UM/rumLaeTpUQhXNcuFRneMql1dGDUB1Cacar0XMz77IBg9LZn9W0sxGqepZs zYRfxffJSg/a2fdxPq1pv03o1RiJaxhkUEcTRajILccSPlp9dEkzarD9D/qwdv1OhMfL 5psA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=54WpcFRk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id az4-20020a170902a58400b001d05ec3be0bsi9729384plb.130.2023.12.13.08.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 08:06:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=54WpcFRk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BAADC802AFC0; Wed, 13 Dec 2023 08:05:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233240AbjLMQFG (ORCPT + 99 others); Wed, 13 Dec 2023 11:05:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233262AbjLMQFE (ORCPT ); Wed, 13 Dec 2023 11:05:04 -0500 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66933AC; Wed, 13 Dec 2023 08:05:10 -0800 (PST) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BDAeIhK020074; Wed, 13 Dec 2023 17:04:54 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=selector1; bh=vP0Cuvt nE+r/ntZNTtv47/xL+GFWmIspcly1Iqw0j54=; b=54WpcFRkZY3+P0q8YGNKJ1L 3/vcUxpmMxvEPoMd4eASPOSK4gswANmkfFk33VIp8PBPN1flMJ8cdpNRDhpjtuKm MeXMSIwMUVzwo3n8p+c19CSPDDqMMr9N36CiyFD0chWuCK8opJx8aQvAemes3DvG Wms6WMBRrPT9EE5ENnb50SPvNhU5mfUKnkWkvEQ67Px/szRmrTJl0kYAzXh8R/ma zirqhNkc4ef3bniaAVjesfFFiLEWAiT3I5WwGQMcLdXj2Mf16RtD20L2WdtpRKak iQoNF0LJQEXSW/kE3pkNpkdW5KAicYTP2o2ZO6ZN8JAvRuqfGPUVs6QcLcLaGVQ= = Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3uyb2k1by1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 17:04:54 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5BF0B100057; Wed, 13 Dec 2023 17:04:53 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 28F7A24B88D; Wed, 13 Dec 2023 17:04:53 +0100 (CET) Received: from localhost (10.252.16.151) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 13 Dec 2023 17:04:52 +0100 From: Amelie Delaunay To: Vinod Koul , Dave Jiang CC: , Amelie Delaunay , , Subject: [PATCH] dmaengine: fix NULL pointer in channel unregistration function Date: Wed, 13 Dec 2023 17:04:52 +0100 Message-ID: <20231213160452.2598073-1-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.252.16.151] X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-13_09,2023-12-13_01,2023-05-22_02 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 08:05:21 -0800 (PST) __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 --- 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.25.1