[PATCH v2 2/2] dmaengine: loongson1: guard issue_pending against empty lli_list

From: Li Ximo

Date: Tue Nov 03 2026 - 03:55:04 EST


From: Wang Haoran <haoranwangsec@xxxxxxxxx>

ls1x_dma_issue_pending() calls list_first_entry(&desc->lli_list, ...)
without checking whether the list is empty. list_first_entry() does not
return NULL for an empty list; it returns the container_of() of the list
head pointer, i.e. a wild pointer into the enclosing
struct ls1x_dma_desc/virt_dma_desc area. The bogus &lli->phys is then
passed to ls1x_dma_start(), which dereferences it (out-of-bounds read)
and programs the DMA controller with the garbage address.

Switch to list_first_entry_or_null() with a NULL check so an empty
lli_list can never reach the hardware programming path. The companion
patch rejects the known producer of such descriptors (sg_len == 0 in
ls1x_dma_prep_slave_sg()); this guard covers any remaining path.

This issue was found by static analysis.

Reported-by: Wang Haoran <haoranwangsec@xxxxxxxxx>
Reported-by: Li Ximo <lixicaicai@xxxxxxxxx>
Signed-off-by: Wang Haoran <haoranwangsec@xxxxxxxxx>
---
v1: https://lore.kernel.org/r/20261026115113.3359939-1-lixicaicai@xxxxxxxxx
v2: split the two independent fixes into separate patches as requested
by Frank Li; no code change.

drivers/dma/loongson/loongson1-apb-dma.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

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
@@ -478,8 +481,11 @@ static void ls1x_dma_issue_pending(struct dma_chan *dchan)
struct ls1x_dma_desc *desc = to_ls1x_dma_desc(vd);
struct ls1x_dma_lli *lli;

- lli = list_first_entry(&desc->lli_list,
- struct ls1x_dma_lli, node);
+ lli = list_first_entry_or_null(&desc->lli_list,
+ struct ls1x_dma_lli, node);
+ if (!lli)
+ return;
+
ls1x_dma_start(chan, &lli->phys);
}
}
--
2.30.2