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=1796384958; b=y+ngCUhiB53biHH/2uqpetGKghpagzUyBU45Qms2CRh5KwlCZX2UKpPiOD5DYexdPbv1 jwi5wmlCwOMRaPGI7cvhIoSRP4YNBCJzAGlRagofVM31RLZ8eNratHR8KZaseR2pu50Tt OuDq/GM5LG77sSchwfZD2z3FGj0QTxF/i1ZDNLCkt1KQ/1mG6+e+LLKMT5LucGsNkYbZQ eFQGEOzMyne7hl2fIPOherXWshXxyWMSuEnbqzkL6iQC7j2zC4TFFnu4UfHAzFh6b5l92 OIU+ok1urS9WoUOG1mVRLzDiHS0FH+oK5AjuI9c7Jg3mH+Tm3huq945ozN2HFNDXHrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384958; 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=JVm+97C7WbianGaNvGIRCsbhlV5xGIdzdI4sABmKIjI=; b=0Ozy9gVCaBF0TOkB2jgns2TQnqVM3YGcx2dH8bvY2IZ/Iq7lFKHBnRU3D4esUwenbnna XBxjKaHTctpV54bRtALx/2tEPyqL23xUNSkc58ml5erc73O+v5mQjNXxij/NX1A5mUyHB 4JjxLjMH9iXh9peqPH7meeIDQLVJJKHSp1fPKmZNMly8ti4eBcbquBdOeEKhCkBsdFF1e zoKgjlSEnmFxIdFhRC24fF6OGxM+fdvjYvy9KmaJ/U4pe9yl0YY15pm+rURUEUIYnfJYM BefUi2QnC22UTJQIsen48yzFaHiavCJ2YLYtGbpkFVwWjauzBXLcWyQqnhFqpj6U+jw== 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=F71Z6vYr; 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 B6FFC606A339; Fri, 4 Dec 2026 11:49:18 +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=F71Z6vYr Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED4B21F00A14; Fri, 4 Dec 2026 11:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384958; bh=JVm+97C7WbianGaNvGIRCsbhlV5xGIdzdI4sABmKIjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F71Z6vYrqw2A0JNeNjLCP7BYVwPJR95lo10IPSH6K/i1CAK4yPAKX084VqG2HhjPq Od3/LGulO2+wbz8fGi4q+oWGSRL339FPM57pkpfjEqoiKjw9aD7hkkC+5+DZiEH5Ev ysRpAVGFbtkPAwVdrfbUk1hwkTvBml/mvuS3XjGM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Niklas Cassel , Damien Le Moal , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 6.6 0362/1167] scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets Date: Fri, 4 Dec 2026 18:56:29 +0900 Message-ID: <20261204100711.411358520@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: Niklas Cassel [ Upstream commit 92feb036a2d33c7b78b8daa2384f5c70d6679a91 ] resp_write_scat() computes the length of an LBA range in bytes as a 32-bit product, num_by = num * lb_size, and adds it to sg_off, the 32-bit offset of the next range in the data-out buffer. The product wraps for a range of 4 GiB or more, which check_device_access_params() allows once the store is that large, and sg_off wraps once the ranges add up to 4 GiB, which neither their number nor their overlap prevents. The ranges that follow are then written from the wrong offset in the buffer. Make num_by and sg_off 64-bit, and pass do_device_access() sg_off capped at the length of the buffer. An offset at the end of the buffer copies nothing, and sg_copy_buffer(), which takes it as an off_t, is never given one larger than the buffer that it copies. Assisted-by: LLM Fixes: 481b5e5c7949 ("scsi: scsi_debug: add resp_write_scat function") Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Link: https://patch.msgid.link/20260929082456.857423-21-cassel@kernel.org Signed-off-by: Martin K. Petersen (Oracle) [ sashal: Kept this tree's existing log line and six-argument do_device_access() call, applying only the u64 types, %llu formats and the min_t() capped offset. ] Signed-off-by: Sasha Levin --- drivers/scsi/scsi_debug.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f7a3c20a4acf7..7e4e119b67250 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3721,7 +3721,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, struct sdeb_store_info *sip = devip2sip(devip, true); u8 wrprotect; u16 lbdof, num_lrd, k; - u32 num, num_by, bt_len, lbdof_blen, sg_off, cum_lb; + u32 num, bt_len, lbdof_blen, cum_lb; + u64 num_by, sg_off; u32 lb_size = sdebug_sector_size; u32 ei_lba; u64 lba; @@ -3795,14 +3796,14 @@ static int resp_write_scat(struct scsi_cmnd *scp, num = get_unaligned_be32(up + 8); if (sdebug_verbose) sdev_printk(KERN_INFO, scp->device, - "%s: %s: k=%d LBA=0x%llx num=%u sg_off=%u\n", + "%s: %s: k=%d LBA=0x%llx num=%u sg_off=%llu\n", my_name, __func__, k, lba, num, sg_off); if (num == 0) continue; ret = check_device_access_params(scp, lba, num, true); if (ret) goto err_out_unlock; - num_by = num * lb_size; + num_by = (u64)num * lb_size; ei_lba = is_16 ? 0 : get_unaligned_be32(up + 12); if ((cum_lb + num) > bt_len) { @@ -3829,7 +3830,9 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true); + ret = do_device_access(sip, scp, + min_t(u64, sg_off, scsi_bufflen(scp)), + lba, num, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -3840,7 +3843,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out_unlock; } else if (unlikely(sdebug_verbose && (ret < num_by))) sdev_printk(KERN_INFO, scp->device, - "%s: write: cdb indicated=%u, IO sent=%d bytes\n", + "%s: write: cdb indicated=%llu, IO sent=%d bytes\n", my_name, num_by, ret); if (unlikely((sdebug_opts & SDEBUG_OPT_RECOV_DIF_DIX) && -- 2.53.0