From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 140BB313546; Wed, 3 Dec 2025 16:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764780374; cv=none; b=Al1249qG8qpwW8lbC1+XrhH4yZLRu4BCN1jNMmJrfedPxcW+Hcq895bHGWaWeKAxZNxMILq/MWpLl6v+Nwknf/wNuFJ4Sv8UFy6bgQfWBd6qFUFkqSGRbBRTgYDKzRGtj+JNr888NJ+vyqFiSGZb55Gnot+nAqdTM747Cl2qNno= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764780374; c=relaxed/simple; bh=zjZ6WoSyER9ZYOqhxDc+s4qM1WxdpjEV5dY9ThD7aB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9WNSLxd9YM1ZWhJicIfeoX5vRzwfkKcwiMqyylRdSiSu/iotYy61s4X/7BcnovVjEMY5t53cFj0bCEL4vy5/xxXH/nF+ltqNWa+AJ08nTDWCD4oJWg4x4IPJTachm2lzZz+GSYCWuvrl2okb1u+GQiZGMf+CbawzNlGrL3cwRU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qgaP4nFa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qgaP4nFa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A793C4CEF5; Wed, 3 Dec 2025 16:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1764780373; bh=zjZ6WoSyER9ZYOqhxDc+s4qM1WxdpjEV5dY9ThD7aB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgaP4nFa5dkbATPWMVERHSWWt6+oAitXwHKYUOCqBvWn6sUlOsYb6s6AuUdUjX5TJ fhvU+Zo6reXxbLRLuuKqVSLOJn+aUWeA11zb5lJyJDl34yjzvo3NL3yzFv7HLWBCNk ZpQqzzEsOSSUL62vtuS5RFACGGCG+U+HvrsW+780= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Desnes Nunes , Alan Stern Subject: [PATCH 6.1 538/568] usb: storage: Fix memory leak in USB bulk transport Date: Wed, 3 Dec 2025 16:29:00 +0100 Message-ID: <20251203152500.417338079@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251203152440.645416925@linuxfoundation.org> References: <20251203152440.645416925@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Desnes Nunes commit 41e99fe2005182139b1058db71f0d241f8f0078c upstream. A kernel memory leak was identified by the 'ioctl_sg01' test from Linux Test Project (LTP). The following bytes were mainly observed: 0x53425355. When USB storage devices incorrectly skip the data phase with status data, the code extracts/validates the CSW from the sg buffer, but fails to clear it afterwards. This leaves status protocol data in srb's transfer buffer, such as the US_BULK_CS_SIGN 'USBS' signature observed here. Thus, this can lead to USB protocols leaks to user space through SCSI generic (/dev/sg*) interfaces, such as the one seen here when the LTP test requested 512 KiB. Fix the leak by zeroing the CSW data in srb's transfer buffer immediately after the validation of devices that skip data phase. Note: Differently from CVE-2018-1000204, which fixed a big leak by zero- ing pages at allocation time, this leak occurs after allocation, when USB protocol data is written to already-allocated sg pages. Fixes: a45b599ad808 ("scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()") Cc: stable Signed-off-by: Desnes Nunes Reviewed-by: Alan Stern Link: https://patch.msgid.link/20251031043436.55929-1-desnesn@redhat.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/transport.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/usb/storage/transport.c +++ b/drivers/usb/storage/transport.c @@ -1204,7 +1204,23 @@ int usb_stor_Bulk_transport(struct scsi_ US_BULK_CS_WRAP_LEN && bcs->Signature == cpu_to_le32(US_BULK_CS_SIGN)) { + unsigned char buf[US_BULK_CS_WRAP_LEN]; + usb_stor_dbg(us, "Device skipped data phase\n"); + + /* + * Devices skipping data phase might leave CSW data in srb's + * transfer buffer. Zero it to prevent USB protocol leakage. + */ + sg = NULL; + offset = 0; + memset(buf, 0, sizeof(buf)); + if (usb_stor_access_xfer_buf(buf, + US_BULK_CS_WRAP_LEN, srb, &sg, + &offset, TO_XFER_BUF) != + US_BULK_CS_WRAP_LEN) + usb_stor_dbg(us, "Failed to clear CSW data\n"); + scsi_set_resid(srb, transfer_length); goto skipped_data_phase; }