* [PATCH] ata: pata_parport: fix FIFO drain to read 4 bytes at a time
@ 2026-12-05 6:39 Praneeth Balasubramanian
0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:39 UTC (permalink / raw)
To: Damien Le Moal, Niklas Cassel
Cc: Praneeth Balasubramanian, stable, linux-ide, linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-05 6:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 6:39 [PATCH] ata: pata_parport: fix FIFO drain to read 4 bytes at a time Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox