Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5844122rwe; Tue, 18 Apr 2023 12:24:32 -0700 (PDT) X-Google-Smtp-Source: AKy350YSYhIAod6eNpkrw8BhDkcqUIMyYQYuksO2snEJ8A1BMjVcFBvYfGQX2FO+FP8h6SAcwhvR X-Received: by 2002:a17:903:188:b0:1a6:bb7b:7a68 with SMTP id z8-20020a170903018800b001a6bb7b7a68mr3404540plg.37.1681845872385; Tue, 18 Apr 2023 12:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681845872; cv=none; d=google.com; s=arc-20160816; b=NMTtkEvNkifkQiiXHHEunXZiLfaPTvuUrVAu/8i/uaXLRRwWJDhp41k66DgAtF76+A w39O5NG2RBirYxE+kaXz9FFiDx0gvsyTOSErQdRVhdBOX6IVfFlvO7aMfuErdTZd8GQ/ hxypoQr7l/rbFxhRN3lfomMqBO82bFi886lQrXQ/m23dSGxXRSGy4gaSXWTBbzin0J5a OudNiBDG0bJlmwimrn8JpIVV3O4GVMutXf3i5NdtN6RfAa33uqa9TDOEFn2N/LN1pGVj lkq/RwD5Zh1SgvHumepqNFY6ERT7MliZ5vRnB3vGKVli9X+J5Gk2OY+KQS5EVwDinYK0 pyVQ== 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=QzMcqFYscz72KP3TmeLDjijPd9/k3SLnhV2/G7k5hR8=; b=S7Q8n/xk++j9MFWyp+kde+Nf43egD2ULs+OrPbhxMXFP5EAt+ITVE5hXm1ZnYyve5s wpDeRGJO4CWjyiJAOabo+j6GUwJ/y5vizApPobeEcecLuxppj9EBy1QXltUVqhcFMQEO 4eHMJoIayodkHxqHYtBFFfUJqJCamnzbu6nRteTAsBcQuRm9rc0ulvKpraHB07iup9mL Pu7/+YKaHhaiLfO63lbcgOrPyc3led9W8p8lrRkeYWcm6vu8vQ9h80ckbgbZ1ytbyeIh lMoovM+e1mWVEq97a+2HZxyOLFsIcCiHbG/YFiZ+pZm082SHCBx8x4z9TF/KontkyPrT ++YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mviSc7Rb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a170902a50e00b001a639f7eb37si3059539plq.14.2023.04.18.12.24.20; Tue, 18 Apr 2023 12:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mviSc7Rb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231947AbjDRTXG (ORCPT + 99 others); Tue, 18 Apr 2023 15:23:06 -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: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); - dmaengine_desc_callback_invoke(&cb, &vd->tx_result); + dmaengine_desc_callback_invoke(&cb, vd ? &vd->tx_result : NULL); list_for_each_entry_safe(vd, _vd, &head, node) { dmaengine_desc_get_callback(&vd->tx, &cb); -- 2.40.0