From nobody Wed Dec 17 15:38:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9186CC6FD18 for ; Tue, 18 Apr 2023 19:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231897AbjDRTXH (ORCPT ); Tue, 18 Apr 2023 15:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231880AbjDRTWm (ORCPT ); Tue, 18 Apr 2023 15:22:42 -0400 Received: from out-56.mta1.migadu.com (out-56.mta1.migadu.com [95.215.58.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D1B59F3 for ; Tue, 18 Apr 2023 12:22:40 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1681845439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QzMcqFYscz72KP3TmeLDjijPd9/k3SLnhV2/G7k5hR8=; b=mviSc7RbCH2D7fFCZ9rb4DUG+OC0BByXxKZzp9FI0XGUGpNEmKKzfNI4NNVirpnlTdbfsf 0lwGO5AA+0GTfmQA7K4m0jss0ktsI05wf/4E28QTmrI4KZ8wPO4aSi3XIR0MlxygdklAWz 1C/mP+kVhjZAWTGXhQrFQfeLCx44Pa8= From: Roman Gushchin To: Vinod Koul Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH] dmaengine: virt-dma: fix a potential NULL-pointer dereference Date: Tue, 18 Apr 2023 12:16:03 -0700 Message-Id: <20230418191603.2291521-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" vchan_complete() contains a potential NULL-pointer dereference: the vd variable is checked for being non-NULL under a spinlock, but few lines below &vd->tx_result is passed as a second arg to dmaengine_desc_callback_invoke() unconditionally. This issue was spotted by looking into the code, I'm not aware of any real world consequences. It seems like dmaengine_desc_callback_invoke() is never using the second argument in cases when vd is NULL, this is why we haven't seen any crashes. To make it safer, let's pass NULL to dmaengine_desc_callback_invoke() if vd is NULL. Signed-off-by: Roman Gushchin --- drivers/dma/virt-dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/virt-dma.c b/drivers/dma/virt-dma.c index a6f4265be0c9..0c46ad18dae1 100644 --- a/drivers/dma/virt-dma.c +++ b/drivers/dma/virt-dma.c @@ -98,7 +98,7 @@ static void vchan_complete(struct tasklet_struct *t) } spin_unlock_irq(&vc->lock); =20 - dmaengine_desc_callback_invoke(&cb, &vd->tx_result); + dmaengine_desc_callback_invoke(&cb, vd ? &vd->tx_result : NULL); =20 list_for_each_entry_safe(vd, _vd, &head, node) { dmaengine_desc_get_callback(&vd->tx, &cb); --=20 2.40.0