From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452763; b=qJ+k1PfZydevF2at9K4iXH5QDnoTk1OlNo5/f/DdQfF0zbJGy+1rbcbLM/yXY1I3fO6a DDRxhesa+e+kvC0ya4MIqX41EK2fFS0WEmdANiLaWIeOt/vu7MpzQHzcz6ONY49d0KXf7 T04zyg9WRY5Vj+BIdHXP/VZXVt/vWe4Ii5W4pNwOruUMS8fxvhh1jjy1IuM6eAm819FRT RQqi1oMB3ss1MuU6KPsz/jsNmbVGOJJDjRTJeJDrgNOncGjMUbF5jgu2a9IEHm3N4NrVb s+NrzvBFKD+/+xU+rBim05TOHSQKqdvDEq+y2ogeyiHsc9flS9cSNvxiGdwkJDd7CPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452763; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=YqjY7fDxQh3Kxe3LYuDsoOp7PZ7ajiQ6aFWX0HhC+eI=; b=cGrgK1zCnmcp/MHcNKbye+kRDJvmNPU1fob/FwPZYdKuOliYgLS16GPVvWD1q0ihcM6w cHFK2pn1DS/ybb7byxdIQposkdFhRi0o+blPYExQSPGmipfxJkYv09p5Paf7oTgvM0xKo PWeX90FaFTBKGJ0j7KP64DfacM6epz2CRAvv9SfC6hXL4IiQyxMZYLJIFB673oybSn+bm 5ZcXZsQU0DSYrv/jHVJkLoGwqx6DTjbeuLKtuiFtxSXz5YDkP1vX5ledIHKLxC9Mx9BrZ rlIf5Mty+TolEZ4n1DWbNrZCkdz5PWU2KNtss6d9qKcqpkAHerO87eipBQ5T+93UE6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qeAP+zge; arc=none smtp.remote-ip=74.125.82.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41EE1606A6A2 for ; Sat, 5 Dec 2026 06:39:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41EE1606A6A2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qeAP+zge Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-386bd881d39so2982687eec.1 for ; Fri, 04 Dec 2026 22:39:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452762; x=1797057562; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=YqjY7fDxQh3Kxe3LYuDsoOp7PZ7ajiQ6aFWX0HhC+eI=; b=qeAP+zgeU8kKQhH4VrE/yKmRnvOwQ44v6wsWjhSBunTAhvJ1j/8/jkv7/TG2r/ztSd bqZsFsgat+oO405YvJ5SWqzfYy2nw8Dv4g9khBDhUxwhF/17Jo1lVY+8RHf9xW0Jbarm rmQXfvV/YipsGQ/5lcfezEilXR13y7YVqDNbPN2JWI8AkouvmD/otLdONmnQKapuqHcO wRDezDR1UXKrmZu8NfZ+AoRhFkydDCAJezWlWrW+oNm01iLWaYOR5Uvu7g/SDwcISsqS U7vgYzdTiarfbO2gcmC9ianyD9vxizJKV4aeJQNusZ0/gwJUbyeAMTIBW54Vu1yt37Al Eo7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452762; x=1797057562; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YqjY7fDxQh3Kxe3LYuDsoOp7PZ7ajiQ6aFWX0HhC+eI=; b=ea/XxDYUAkgEnFDLmuk2Is6p2t10MnptHXTDQZsaVqrHhm1ihybusTFOqm9uarJtaQ TPxvR9yFFdhzfkFvUAWPO2cHHd9RWYIkqQ+YyhiIiTbip0u889I06+D0VzRfhVfyCVoS Eh5QWVOyIFpqg65FypStx99DoQmwZsGlPgzGLGyNbcHF1TzYFNnFJbCNy6VmVq/MdXDT Vt/hoM0B4wvZPncKncF1AesfBisf67BzXVpLyYly+IlhIutRuGUEPVrq5JQSOSiCQk1Y rho8ySEmni8zI/QKjFNG2hlYMf6a3gOEoMdV/PkcTgnCG08Ew0ILUlgT5kmK5bwjK52p tlYw== X-Forwarded-Encrypted: i=1; AL+hErFm86jSdZiQJKVhBgL94AnH3KBiWGqIFdKxYl7VcQy63xIm2vx1jOhbpmHUA8czgcxF96PGPzVOiy8=@vger.kernel.org X-Gm-Message-State: AB4q+uFzXB1NIHoef2sXlZDZQZne6Rhkc92GHfJe9W3GIDPEBpFXgcIB vgZQ9kpqlFYbYU7QERmXeK9JMMSZ/lvXw35WNkZCrGS8xaIdcZb0yU+x X-Gm-Gg: AZFdTZee3Hf7E71aVxZYUE9Qjw61dxcJWelqRj6PbarM3lugp7FJua8ULf4A2jJx9tS iQCNq2L01KoHnDXkXbz562j4LcTFlLTI/6kMlMQz4ZRldGjEeQS/0N1dNyJZyfunPosUdu3nSak Al3+FCZBQFz/Z7CfOeEx2xaqwYbx8wwvGYDLcN9tXmXrsIFINO902/Th89zyVvDzsPaGwAmhY+6 BLwz6s3jSUmCeQXVMNfGwpyUpRnig6UaF0iPKBCzVJcqPiWC5cVuFFzaG+J4TTI+W0xk8cMF2Qv elix1YDQF5A7AyXeo3rbIuUhsOyPw6cgvXva2ReOzIKCnLJ97Z6aVbq82KzBRME/0Cup57uTvHC ShQBgA6xYII6LixeLw2HdJmXx8TvUlfA8huHv2W0A9+Uhl9AOXTuFxkaPWpSHNIprRY2qD7lzNu sMCNKCxVP2cYm3cwEVS+ELmUX83PR4wVUi33RInr68Ec3vtC9HtxlblUaBuOCAGdrEV63W/KEWK xUvN/mS0cE3haf1nfmDBdXadTFRaoYMjdi3DUhN4R8B8c75J5o5+sRZ3Y0rB12DoslEyinDsvcs kGi5h/eqtyHg9zmMEX5k7ZTXief/js8ZY5arYSX5a7h7n2ge5g02l+grjNq3D7SvmGg= X-Received: by 2002:a05:7300:2215:b0:381:3a24:1be2 with SMTP id 5a478bee46e88-387520d057dmr6180242eec.13.1796452762292; Fri, 04 Dec 2026 22:39:22 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5e7dsm16303190eec.19.2026.12.04.22.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:39:21 -0800 (PST) From: Praneeth Balasubramanian To: Damien Le Moal , Niklas Cassel Cc: Praneeth Balasubramanian , 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 Message-Id: <20261205063914.2524991-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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