From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452763; b=YKxY0iqU6jUgC22aq6CHeXG1EzRcjRC3tybL6rzLkt8bNi28ncOWzBeY4K97XcQytEMC IWLv1rduwai/Jl0JFxszyc1VTOoz0KZwxDCLqc3EQCnQXTPmhHdJMEhuYJyPABBJ8G8Ss S1PqZdxcMJj5uCUssHAtIQ18TvQ4DhS9rGQYp9mnO8rumtTHucWIt07yvG5F5jon28Jg7 1vERbZB27bKp0mfCRWmF7tW/5WwXdeDwn6ExNK6B5lYkVaz7JhZOzwWg7xwbknjicxUV/ ZlkX8vpnbcsmeD9H4MRc24b6CcCl89UByFC2ku3BsUHxkyQ4iRo3LywWrwUGVksDc6Q== 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=kfMOsc+hzHcZ0ui+4bapGClovk/xjIl/oIhKV5EvYFmYm9BooaxnOPBFBihzXGlmrsgN H76lkALbbwjXAnH/SNgtwJaygnGdj93KLV6foOnHAyanf6Gh6c92PS6mfqsyhaBtGucPT WBmlJdwuZ8RMtm7sfUD710rQh3lIX7OnW64MPTYKPrOTbPBxdQyfMchnCbg7niky/Lzz5 Ag6nA4I2heEW7PFTEZUZ1ZqD8YxjcZ9o/MtfPQFEJ7YkX36Pw/TShw9xaj71mHlvGRl0K 3xP/B09O6VBN9jLf3AI38m2fQAikcHABVLYjbKU0CS7MnSUbGuUee8pxG5ot0FfJQjw== 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.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 2F655606A6A0 for ; Sat, 5 Dec 2026 06:39:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F655606A6A0 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-f171.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso3780865eec.0 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=moJqZ3WhKxnKcfVdis6tqn2tEK2tZTR9wV4t35OHDDnvjiqtm+Mzel/phzJahZzgCB FOZTQxkUOMXI2L1fKejXHPnJVIwKkp8nybR3Pc+uZUeNCp53zm71RwVXKjJvgnafGh4m gI/RB5sTmW/D94HFCKGbyGu91PxoxMJ3d3nVmyxBh0hzgwJqxE9jbkaDJwuBE5Jwo5Fo NTCGT2OPquIhmSRJnqpwO2Zd2JONyFaeDEmct7nZtiTaTsoPhGhE5FNpVtXJKvqLVqdj o5jcDeSIiQl4adi7HJWkUMMRK7YYP/4meBw7xKipslOFaKaaYrK2XHtJy4J2Vaz++co/ Z18g== X-Forwarded-Encrypted: i=1; AL+hErFplxsux3/1pUjugbdKNaN1xxrLNmw2oF9YL+3vG0UPxe3UxJAKYB9caukC14u7aF/nqtb8EM4=@vger.kernel.org X-Gm-Message-State: AB4q+uFFIbfLzHXk8uSwyDKTeBsPpMl2mXHYm4myyk2qJrWY5731As2v tID0fxSsXUyxZQbvMWS6Sagxsjvwlu81xq3EqJV0vXKBiSrVhP0GVbR2 X-Gm-Gg: AZFdTZd7i1l7Qp8mfn5M5gLnb/TNyv32/9N0wJD7DlyYCYmI4iwTLlf6wWs272ZGtaM zQoAaORpAsyCSM5HKMpEeKtbAD4ExoQx5xRVhSyKznJZM0+YR52wdUgc3wmq+UTj0CgEnNIKD8U IlKGtVbxsR3VMkt58ADEWcIHRyDkv179k0V16tE6XNzXLo+8LozQCu9b+GTFwW0jLHALI6XqRPz wHkzaImWfkkISMJPj8odhrNp1YVg7vyyv5+Prgj1+kxmkPnSd5gC4WNyYNAWq+Y9AgnapUUr5sP HbaSaufMqSUKxaEDUHptJAgbxE80bphTZwn4MRyfgqefKcMmvNIkqw9RZuG5AZpb7f8xuQbPGOk 5vnY8qNWgAdnEp5rI/6ndQxK0s0eOOvc25JDmlalAMoyT2AT5XWCfrC5E4t8bs8p4yAUv1BpzVh eRsuBSq+hagq7+udve6ImEi33SiLieLnbTd1hyDwnH9z5DmVJNrJpB36983ri7ehV01eKcQ7vJb HkqraI3BBoU87Bxkk1ilG8mH2HMzWD6Zti0LBD0qxJ7oMQwQxEzQZsZImnc6GNDPLQFWPZ77ec3 QgAmAZA7YDo0jlPPtqPSsEaHyqNF10h2HU4Xo9Ha41W3hLCtFYNDYKWFgRGcYdbos/c= 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: stable@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