ata: pata_parport: fix FIFO drain to read 4 bytes at a time
Subsystems (2)
PATCH 1/1 ata: pata_parport: fix FIFO drain to read 4 bytes at a time
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.
---
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(-)
drivers/ata/pata_parport/pata_parport.c +8 -4
@@ -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
Signature · 1 line
2.25.1