mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roman Gushchin <roman.gushchin@linux.dev>
To: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	Roman Gushchin <roman.gushchin@linux.dev>
Subject: [PATCH] dmaengine: virt-dma: fix a potential NULL-pointer dereference
Date: Tue, 18 Apr 2023 12:16:03 -0700	[thread overview]
Message-ID: <20230418191603.2291521-1-roman.gushchin@linux.dev> (raw)

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 <roman.gushchin@linux.dev>
---
 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


                 reply	other threads:[~2023-04-18 19:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230418191603.2291521-1-roman.gushchin@linux.dev \
    --to=roman.gushchin@linux.dev \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®