From: Li Ximo <lixicaicai@gmail.com>
To: Keguang Zhang <keguang.zhang@gmail.com>, Vinod Koul <vkoul@kernel.org>
Cc: Frank Li <Frank.Li@kernel.org>,
linux-mips@vger.kernel.org, dmaengine@vger.kernel.org,
linux-kernel@vger.kernel.org,
Wang Haoran <haoranwangsec@gmail.com>,
Li Ximo <lixicaicai@gmail.com>
Subject: [PATCH v2 1/2] dmaengine: loongson1: reject zero-length sg requests in prep_slave_sg
Date: Tue, 3 Nov 2026 16:46:37 +0800 [thread overview]
Message-ID: <20261103084638.1190232-1-lixicaicai@gmail.com> (raw)
From: Wang Haoran <haoranwangsec@gmail.com>
dmaengine_prep_slave_sg() forwards an sg_len of 0 to the driver
unmodified. ls1x_dma_prep_slave_sg() does not reject it, and
ls1x_dma_prep_lli() then builds no LLIs (the for_each_sg() loop body
never executes) yet still returns success, producing a descriptor with
an empty lli_list that is queued as a valid transfer.
Reject sg_len == 0 requests early; a zero-length transfer is meaningless
anyway.
This issue was found by static analysis.
Reported-by: Wang Haoran <haoranwangsec@gmail.com>
Reported-by: Li Ximo <lixicaicai@gmail.com>
Signed-off-by: Wang Haoran <haoranwangsec@gmail.com>
---
v1: https://lore.kernel.org/r/20261026115113.3359939-1-lixicaicai@gmail.com
v2: split the two independent fixes into separate patches as requested
by Frank Li; no code change.
drivers/dma/loongson/loongson1-apb-dma.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma/loongson/loongson1-apb-dma.c b/drivers/dma/loongson/loongson1-apb-dma.c
index 89786cbd2..e7eb40584 100644
--- a/drivers/dma/loongson/loongson1-apb-dma.c
+++ b/drivers/dma/loongson/loongson1-apb-dma.c
@@ -302,6 +302,9 @@ ls1x_dma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl,
dev_dbg(chan2dev(dchan), "sg_len=%u flags=0x%lx dir=%s\n",
sg_len, flags, dmaengine_get_direction_text(dir));
+ if (!sg_len)
+ return NULL;
+
desc = ls1x_dma_alloc_desc();
if (!desc)
return NULL;
--
2.30.2
next reply other threads:[~2026-11-03 8:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:46 Li Ximo [this message]
2026-11-03 8:46 ` [PATCH v2 2/2] dmaengine: loongson1: guard issue_pending against empty lli_list Li Ximo
2026-11-03 15:16 ` Frank Li
2026-11-03 15:11 ` [PATCH v2 1/2] dmaengine: loongson1: reject zero-length sg requests in prep_slave_sg Frank Li
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=20261103084638.1190232-1-lixicaicai@gmail.com \
--to=lixicaicai@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=haoranwangsec@gmail.com \
--cc=keguang.zhang@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@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®