From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385668; b=z4z2JQ+PovBsNLGu53hePElW/lqyAGBYfwGR/tLLSQjsH4bBqylYMiN7pGA/Norb1Ink sWCfKFYr51XWzviLGO8U1j5Ch8YX+q5+3ioq7XecFf0BoHnl5tBVtD+7zZDx+FA5IqfIB peRRQtBConBVs59B08A4w9wRw8MVRZMN8+lfflp6T2sWoDv4YqZ32OuoNXwuqeeP8zPCs eHeNT49UElFHJXBHFi2kzratqvMURpV9LmfDFNgO0p6Sy37zfTw7BXIhQx5mskg9C3cU6 TBwEi4tbY2Iy1eNtovlxvEyzEeuLT0tqidijfigG7xsLuffsOlQhbcwWFqHQJJ5yETA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385668; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=zrT68hSf2muwmSmp0QRxihs1abobviKwMZ8re20aHBk=; b=nDNyivAo9lbM+4e0U8ow4zsmaQO8JEPtWfmJCwUeLjUM2GcQhh4agzWojjpEOrv+S2VC yxJ2x7fIySquEiX2rEiuKFhO3CekIPRzNvJpbfcwxzgW7330QOyvGzTx9g69EniY1d38V W48MKaeGvQTrpoEdyE7b3xhyGiIo1xyWEa3p/KR8Y52Q2dWbRU4xfIyxBbTuwuUpyeh// KcIFPRWPLW1D/wbkdiFmwtjZhnf9Sl/fN9lJ14wE5Tzy2jCdCcWEV1XGXoqU8nJwpQxZi 8tdEdDYbAN457myqXtqyk+rZLfMxUj+Q/C/cCVu4b2qj0R+MuSFQEmRk3C7Ur5gh/mw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="b/6YKL4A"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13D48606A32C; Fri, 4 Dec 2026 12:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=b/6YKL4A Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85C871F000C2; Fri, 4 Dec 2026 12:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385667; bh=zrT68hSf2muwmSmp0QRxihs1abobviKwMZ8re20aHBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=b/6YKL4A2oiucQ+PSHjYw2e/tqobqtTTkDIRWn2aiIQsA0UQ7VkA5IhGQerBkpKJQ atO/RQDR6GEjM+E1PKEwq4GZNCuBjiiW2M6EvN69W7pr/DgkAoQ5hDZQOc8g9Y7dnj cC5Y49B6OP6cxq9uKQjOMBZwLbhGcSXSHs1t6QFw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Bin Yu , Cheng Wen , YuanZhe Liu <25031212351@stu.xidian.edu.cn>, Alan Stern Subject: [PATCH 6.6 0645/1167] usb: usbtest: prevent divide by zero in simple_io() with zero length Date: Fri, 4 Dec 2026 19:01:12 +0900 Message-ID: <20261204100718.858957624@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: YuanZhe Liu <25031212351@stu.xidian.edu.cn> commit fdaca138694111153f96c7d76877734b9dbf0e01 upstream. A divide error oops was observed in simple_io(): usbtest 1-1:1.0: TEST 3: write/1 0..0 bytes 16307 times Oops: divide error: 0000 [#1] SMP KASAN RIP: 0010:simple_io+0x2c4/0x540 drivers/usb/misc/usbtest.c:497 The variable-length tests (test 3 and test 4) compute the next URB size with "len %= max", where max is the original urb->transfer_buffer_length. However, when a zero-length transfer is requested (param->length == 0), simple_alloc_urb() still returns a valid URB with transfer_buffer_length set to 0. On the first vary update, "len %= max" divides by zero and the kernel oopses. Commit 564e69893c63 ("USB: usbtest: prevent a divide by zero bug") added the equivalent zero check to alloc_sglist(), which covers the scatterlist tests (test 7/8), but the single-URB variable-length path in simple_io() was left unprotected. Fix this by returning -EINVAL early from simple_io() when vary is requested but max is zero, so the divide by zero never occurs. Zero-length transfers without vary remain valid for the other callers of simple_io(). Cc: stable Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> Reviewed-by: Alan Stern Link: https://patch.msgid.link/20261016072750.34256-1-25031212351@stu.xidian.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/usbtest.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -466,6 +466,9 @@ static int simple_io( int retval = 0; unsigned long expire; + if (vary && !max) + return -EINVAL; + urb->context = &completion; while (retval == 0 && iterations-- > 0) { init_completion(&completion);