All of lore.kernel.org
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Vinod Koul <vkoul@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org, Frank Li <Frank.Li@kernel.org>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] dmaengine: ioatdma: fix the source count check for XOR validate via PQ
Date: Fri,  4 Dec 2026 22:41:37 -0800	[thread overview]
Message-ID: <20261205064137.2527034-1-praneethb2002@gmail.com> (raw)

When the channel has PQ but no XOR, XOR validation is done with a PQ
validate descriptor. ioat_prep_pqxor_val() passes src[0] as the P
result and the other src_cnt - 1 buffers as sources. But it picks
the 16-source helper by looking at src_cnt, not src_cnt - 1.

So a 9-source XOR validation reaches __ioat_prep_pq16_lock() with 8
sources. That function only handles 9 to 16 sources. It allocates the
smallest super extended descriptor for 8 sources, and
src16_cnt_to_hw(8) wraps to 7 in the 3-bit field, which means 16
sources to the hardware. The engine then reads source entries from
memory past the allocated descriptor.

Choose the helper by the number of sources that are passed on, as
ioat_prep_pqxor() and ioat_prep_pq() do. An 8-source validation then
uses __ioat_prep_pq_lock(), which handles up to 8.

Only hardware with RAID16SS and PQ but without XOR uses this path.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: 7727eaa4490b ("ioatdma: Adding support for 16 src PQ ops and super extended descriptors")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3,
    then checked against the source and partly rewritten with Claude Opus
    5.5. I reviewed the patch and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.

 drivers/dma/ioat/prep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ioat/prep.c b/drivers/dma/ioat/prep.c
index 033d9f2b3e2a..0a255f28d903 100644
--- a/drivers/dma/ioat/prep.c
+++ b/drivers/dma/ioat/prep.c
@@ -694,7 +694,8 @@ ioat_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
 	flags |= DMA_PREP_PQ_DISABLE_Q;
 	pq[1] = pq[0]; /* specify valid address for disabled result */
 
-	return src_cnt_flags(src_cnt, flags) > 8 ?
+	/* src[0] is the destination, so src_cnt - 1 sources are passed on */
+	return src_cnt_flags(src_cnt - 1, flags) > 8 ?
 		__ioat_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
 				       scf, len, flags) :
 		__ioat_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,

base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1


                 reply	other threads:[~2026-12-05  6:41 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=20261205064137.2527034-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.