From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179485; b=EnvlFMFqDgndhvq71IxhW90HfcQtpKZQdG8lqqBxBc/RQ4QP2CtUOCcBciAlrfzk5v6/ HPNC+3dZOIQAGFXUMvWok0SwtGkRl2WBIcPthMks1cUz8eY93mmCWMxojB/UKSoOv1tVA xVX/N7BeOcKJuLRGcGPYIAcpR51U047P5wnX9avK2nIfl0+iznvMdKQM1SsRDZ6HN0OOB YcR/LFfLRlvXRVgnWQfGUJuhD0XO16CMOtNK+TXFku8KJvNG+tbCcQigm/WgGgwaHWUDy 9E85K0pXteS0KKPyMh29HKyS4vdWGobN2y+L4Zu2t021b1znbvYmmwt954dR6atVeLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179485; 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=7qcBBOK1pGjuJ1SrSryCb8o9PezJBhSMPJm3svZB0lE=; b=ejBfa0RUlilQqAEvkOwzy+Dyqd0zPH/qpOdxOjIdF6dlNJhCt4Rke0akuEMXrM8lrjLg AiSPd1qB1NPYQ4lGktFc4JXDzel05ZIdUWc6CAzh2UzRc29SpZ60I1cHpjoIU8J1obJy8 o56lS4y6N0rF7FQ8f7yvTK+7LXxmOA+a0jV4NRHCHBfsON2viw1nZa7SLW8CbbNd7K4rK y61OTt0RqTnJGA28KBvmlPcmIY544FzKlb64eAzHu8qU7g/ocWxQmtbP5x9BvpC0TWs4G BK6egb3j3GHcCBRIrqMtEKr5bOUjh7pNoh/XvX5qeAuOp8eBugAbTWQ67UuttihWsbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=EjBoiGym; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 6F131606A322 for ; Wed, 2 Dec 2026 02:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6F131606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=EjBoiGym Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-386cf1041cdso13054792eec.0 for ; Tue, 01 Dec 2026 18:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1796179484; x=1796784284; 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=7qcBBOK1pGjuJ1SrSryCb8o9PezJBhSMPJm3svZB0lE=; b=EjBoiGymK6f8oS9NuRNxi4je6d7TzwTZvN+nOdHtty8bXUfgxjxZ1HrOeIUQaNHw7Z D7iDfJGypk6bZtiPLkhjj9KD4GAUFPdeqPYljdt1xkBjhoxGhxijny2ygpM8F4HwvqoG djE4oD9ALh4dj3/LDbHfPa+HmIiOrylzmIBhgHPsiTa6jq+mhElGOZ19i55cilXuOEgI kwEs/fN6qWxU342Fa/CqjlAiPCLFo9BDvmMl21AgbuP68zWJTFLwkhyr86hj9x8u+i7i KtKvIItQoNK5TeHsV8O35za51fCaa+fposjzJ+sSbgzMw+0FQf2ut1qFlWXSc1S/Mnfh Ez1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179484; x=1796784284; 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=7qcBBOK1pGjuJ1SrSryCb8o9PezJBhSMPJm3svZB0lE=; b=izh96XX+Af7Qr5llkCcvAbLjgAe5CcqgGlJ2c/nqwFR1Qj+lsloXIDzbt0Pgqyeuvd QeAsA4lKeNNrFhHZ+6NIMiSKyf4JiqWEiQJ2yarfvXEx0ALOL/wHi9yxEx+lGjpuEIoh upx9Vl9eE6cD7PO//0J/pbuVfNDOiq5CxyC3My8c8fYww3Q1kfKitCnmF5+/usz4REq9 NdIHmlvUHRPA//QGDQkX0bupJhkMUDCiJBaXD9u96uFaIR5Hlu7Z3brLnfovrbU23D/3 jp07fHaMPZpDYjP3CjtiE2Xpo9kmtmkHzLjpYwqw6WkQinx4FpjhZNNpLuEbUJl2eEPv cqOQ== X-Forwarded-Encrypted: i=1; AL+hErHDhOoJYRZOtI4AhHIiGmxdSJCAJ2sovyd2GylCixXksFENbSa2N5LvUsEpVHXA9DUQ8erZEsG5SUdOzbg=@vger.kernel.org X-Gm-Message-State: APuU4Z96Jqq2G8o9/vhuZYh1UENdnWDgUwaegFwDHE5/Ie5HfdzgRnUP 5PQdSLwcr/Yq09Nd9KSRjONXc5NZiv38dB9+GsTPd3NXlDdrqUlDuz8YMHCNlPTLv5c= X-Gm-Gg: AZFdTZeSZzvc+cL5jmtS2d0eOVat2NqUL0SaBXL6KCYiRIdmY+tiBAxsnS8xJFZaGdL Zrjg6Q4rtANYPxYpzKQG7yCWK7vMpJOWsHC0D+REzILbRk0SbG6ztwaNJ9hsRxCTEB8ZEh+JlCG hDmZfv5PlBxR6fkctslZrg4ryuH8+ovoxyg//qgmHD81HWfQsYtHTLmyUc45zHRn+blniPw+Mt/ nQWddGeVGj4kMwYPranhhU3m6ozVgDhuWUSwghIgCn2mKduqXgPw2AX9x0QHJgmaLgyOLnYiBLF ekXr8uXsKBdAUj9/rOMekWeC+fiKDjcbwx1y8HQigrQWvCfa08qyLavqXi3TT8YfvM5c1s8Ao+H Q9l/1EXRvdXwZohxKHAHUBPuDRm/7DFRrjdtdPWwlk1d8Hs3wrm0ze/7ZEm+H+jSmr+nxEcsh3k igZCQ7RqJMiVD5V5Xb0XCI/5kAg2dFP7eDZlg3GpQsmwPKQvsyubGFNKPCUD6QWCORTwpciJKTe rYo97YmREff5KHoYSG79ysVIRfeM9PGs0CWkhhTGSSDdX8wAzNmylcvigxNgwNBi9EpSmjrF/Aa ou4qdRLEFUoGYGzOXQhDVx34Se7m7jVt3zKylDTO6VFTbeSMj6Bb6VRCAZdAYHNbqniajTF2ZaI UBzX+WR+Y+8ZpKq94eyTlU040Mw== X-Received: by 2002:a05:7301:1694:b0:386:9cae:abef with SMTP id 5a478bee46e88-38733c0c8e6mr387797eec.36.1796179484491; Tue, 01 Dec 2026 18:44:44 -0800 (PST) Received: from localhost.localdomain ([2603:8003:6d40:6669:64d9:8f5c:3d5:8f62]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386992b404bsm96287890eec.1.2026.12.01.18.44.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 18:44:44 -0800 (PST) From: Artem Dinaburg To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org Cc: lihaofeng@kylinos.cn, 13266079573@163.com, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org Subject: [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length Date: Tue, 1 Dec 2026 21:44:41 -0500 Message-ID: <20261202024441.52639-1-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 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 For device-to-host commands other than READ_10 and READ_CD, usbat_hp8200e_transport() reads the response length from the device's ATA LBA_ME and LBA_HI registers and passes it to usbat_read_block() without comparing it to scsi_bufflen(srb). A device that reports more data than the command buffer holds makes the transfer run past the end of the buffer. Fail the command with a transport error in that case instead of reading the response. Haofeng Li found this first and posted a patch that clamps the length instead (see Closes). Found and fixed with AI assistance. Reported-by: Haofeng Li Closes: https://lore.kernel.org/r/20260822194728.4151923-1-lihaofeng@kylinos.cn Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Artem Dinaburg --- Sent as a new patch with Alan Stern's go-ahead; Haofeng's has had no replies since August: https://lore.kernel.org/r/5e690176-2e2c-4166-af06-9a35ff190173@rowland.harvard.edu Tested on mainline 19cc08c1a6a6 in QEMU (q35, KASAN) with an emulated HP 8200e: an oversized reported length now fails the command with a transport error and no oversized bulk-IN is issued; a well-behaved device still answers INQUIRY, TEST UNIT READY and READ CAPACITY. Built with W=1 on mainline and usb-next. drivers/usb/storage/shuttle_usbat.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c index 563a2beeeb44..35129e82612c 100644 --- a/drivers/usb/storage/shuttle_usbat.c +++ b/drivers/usb/storage/shuttle_usbat.c @@ -1673,6 +1673,9 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us) else len = *status; + /* The device reports the length; don't overrun the buffer */ + if (len > scsi_bufflen(srb)) + return USB_STOR_TRANSPORT_ERROR; result = usbat_read_block(us, scsi_sglist(srb), len, scsi_sg_count(srb)); -- 2.55.0