From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452764; b=DcqxwrOyfSBwes1IRzbbfARUfhjIFCXvha1qiuGIHjyc0fAnCiv00Xja3ym/Tf4QZxHa Cpd8I0jYkH3KOGtmLOGb3bqU7EuNtxaupHSJ0Ckj7NgUmhpPIWfFvoUZRgn1/dwGvjhaa Mjwuss/ZDKcymTDiRAOOU/0u0yHpLygppXJpyBAb51qDYV3te17B0fNu+F47/rbsU2Cil 4wPUObTnRjL+10XJy3oNfRNRdqr3n/JPzAqL95J3Nb/mFJtnyiLJ6nxsLIRXS3djI1rDA R3a5Ni0CUvy8ljsBnXt3rzZ7GMFZ0ZWEXdE8YrYDnx/oB505n1pDjLjTpzeOPEspcbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452764; 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=AzbwjYwR87iOAp8L20es0a3EgSBJElv4CHzKX6r82Q5lmoWTnR5G3VJi9MsiRnlBti7l cf4TZEHaowIYxxMYSRu2CAbn8B8kPYaCgofG7SlO2hwbyKEQyWkPqfNk6nrWER4RujRhG cXFJ3P3yoFI6wTqg02h9O9vwMmGcdvNHngjuZkVzVgMTGoE9BSRTy1YqLiLqDRwQbylQj Ma7LYobxcPl6Xzn7VVuCc3uzSZ7w97ils/7J196bBPCmTM1OHJTDhJRuqUhUPMciog1B3 FDDoZyk1bZFyUizcuzr3GQ68cdyxKxCVPWa4R8CjPNOa9+IBtFbBI/8Sj4uJmut88+w== 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.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 2B064606A69E for ; Sat, 5 Dec 2026 06:39:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B064606A69E 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-f169.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso3780864eec.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=IdD7R896QQlHPTaybKe2rP+WSYYDcoSmOfUtvVGhEsJZI07W3sWYiN6Vq5QSwS0SBj zcGnfylJFLqEeB4ZH0VtTBQDb3PM/ZN/wQGV/CXBbx7d6ukuJsb89fewcxYxC37dtV0B uA3cTwkE5iaFtcbHwXbpnLO71iWGyAFIyQfWkc2Gu9FLrPTXkZyVm4tlgpGigvVpNBvj F4tfUk10tQrcVA0hGYGCSAo97kE6WPaq990ApQxhtOsUxsuSA7Q2kdyzR56S/sdY4Bo8 zo7JK5ghDRvV99eCCRepw/PMKelNdScxHCGm1TFr3QiQbPCFGXqL5uguSTM61nl+MqIt JC7Q== X-Forwarded-Encrypted: i=1; AL+hErEGt+WNpfQ6DsifUY8kVUOl3XdjHW12hsI/qzeXhE9IU4nyNQx4lKe4uhm0ttU4IRy8E8IG4RmvrtpVAso=@vger.kernel.org X-Gm-Message-State: AB4q+uFOqp/AhG2FxQ/7H6jkUsWolOCcW6kBnUCMrcXtMSKDJDoAuYLP Segndm4jxxAWleDDk0smdhZCveqKlLtmaPAiTbIyt6XsEYhgOTPtRpNp5HGymzsc X-Gm-Gg: AZFdTZfoH8Lk2UfNctoA695p0YlahnJIFH3MT314ytsCsymL95i+VcJoyU2/zETRuJY DaV9LPCDCIr6IG4HrsR/77T2lGxAaPdvYK/EdX68dik91Rqhbkkxcab97b29UCWCfxFTMq5hVu/ l1RguOcebylhxIr4djd2aGMWUFSTebFpgJFNZLtef+8aeb/d07fJL7ZQwF6u5bgaL2NrXIHliyR hrvQr3voH5MIHMeQqybmhwi/d6Sw+CatbJ1e7PmmmDYRKKWHuxYYCTBB93eZm+pmZTKCwYkwnOD 45McjTWp12ToH/ph8eCvw65mLbOh44HKlRJM7gxjg5zJ0kqcq06qtzSwZ2TP3sMEJoKn4C84aDy sQNucROAV7HW7LSziPZWcKXyRI8UQc9MK0W3ZJ6NLXn0EHhi+GzuoIPnz90n23HqgGduB/KGYBJ WPo9yN+3KIu9G6wWYPRX/P+NiSHnePXY963Vb+eL+jOLpJMvC81B+zj4s5TXjb+l4GsSQDhxU9r +Mdmctj9QrmoNKK8nQeRmSGEzCU/HnExBIYdVzmCb0lIIKIoFoOIBQs/iS3Xa9gbopJmtZOYiFS +FHcp0pMgy8SelM0CQsswxd4e5rHszfaCFCjESPawkrDl8BjM+hUnV/HyPrFXpDS+LY= 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-kernel@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