From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Damien Le Moal <dlemoal@kernel.org>, Niklas Cassel <cassel@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org, linux-ide@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] ata: pata_parport: fix FIFO drain to read 4 bytes at a time
Date: Fri, 4 Dec 2026 22:39:14 -0800 [thread overview]
Message-ID: <20261205063914.2524991-1-praneethb2002@gmail.com> (raw)
pata_parport_drain_fifo() flushes incoming data on the error recovery
path by calling the protocol driver's read_block() with count = 2. The
kbic driver requires count to be a multiple of 4. Modes 1 and 5 of
kbic_read_block() loop count / 4 times. With count = 2 the loops do
nothing and no data moves. DRQ never clears and the drain loop runs to
its 64K limit. It reports 65536 bytes drained even though nothing was
read.
frpw.c and epat.c are worse. Their mode 5 handlers write to
buf[count - 4]. With count = 2 that is two bytes before the two-byte
junk buffer on the stack. Each drain call underwrites the stack below
that buffer.
Read 4 bytes per iteration into a u32 and advance count by 4. All
protocol drivers treat count as a byte count. The value 4 is a valid
multiple for the byte, 16-bit and 32-bit transfer modes. The drain now
moves data in every mode and the reported byte count matches what was
read. In frpw.c and epat.c the write lands inside the 4-byte buffer.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 246a1c4c6b7f ("ata: pata_parport: add driver (PARIDE replacement)")
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/ata/pata_parport/pata_parport.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
index f0fe921a10b4..b5703f33c66d 100644
--- a/drivers/ata/pata_parport/pata_parport.c
+++ b/drivers/ata/pata_parport/pata_parport.c
@@ -300,7 +300,7 @@ static void pata_parport_drain_fifo(struct ata_queued_cmd *qc)
int count;
struct ata_port *ap;
struct pi_adapter *pi;
- char junk[2];
+ u32 junk;
/* We only need to flush incoming data when a command was running */
if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE)
@@ -308,10 +308,14 @@ static void pata_parport_drain_fifo(struct ata_queued_cmd *qc)
ap = qc->ap;
pi = ap->host->private_data;
- /* Drain up to 64K of data before we give up this recovery method */
+ /*
+ * Drain up to 64K of data before we give up this recovery method.
+ * Read 4 bytes at a time: some protocol drivers (kbic) require
+ * count to be a multiple of 4.
+ */
for (count = 0; (pata_parport_check_status(ap) & ATA_DRQ)
- && count < 65536; count += 2) {
- pi->proto->read_block(pi, junk, 2);
+ && count < 65536; count += 4) {
+ pi->proto->read_block(pi, (char *)&junk, 4);
}
if (count)
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.25.1
reply other threads:[~2026-12-05 6:39 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=20261205063914.2524991-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.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