From: Frank Li <Frank.li@oss.nxp.com>
To: Li Ximo <lixicaicai@gmail.com>
Cc: Keguang Zhang <keguang.zhang@gmail.com>,
Vinod Koul <vkoul@kernel.org>, 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>
Subject: Re: [PATCH v2 2/2] dmaengine: loongson1: guard issue_pending against empty lli_list
Date: Tue, 3 Nov 2026 09:16:23 -0600 [thread overview]
Message-ID: <aun6x4Br6rc0VXIc@SMW015318> (raw)
In-Reply-To: <20261103084638.1190232-2-lixicaicai@gmail.com>
On Tue, Nov 03, 2026 at 04:46:38PM +0800, Li Ximo wrote:
> From: Wang Haoran <haoranwangsec@gmail.com>
>
> ls1x_dma_issue_pending() calls list_first_entry(&desc->lli_list, ...)
list_first_entry()
> 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.
>
Cut this paragraph
> 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.
Cut this paragraph.
This common issue about list_first_entry(). Keep commit message simple
and leave important informaiton.
Frank
>
> 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 | 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
next prev parent reply other threads:[~2026-11-03 15:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:46 [PATCH v2 1/2] dmaengine: loongson1: reject zero-length sg requests in prep_slave_sg Li Ximo
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 [this message]
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=aun6x4Br6rc0VXIc@SMW015318 \
--to=frank.li@oss.nxp.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=lixicaicai@gmail.com \
--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®