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=1796387633; b=DkoNiGn8ihDQIqVJCUUiCujkYGZiaJ+yY86X9w6WihuzOgNxPgUsG7ds3NIwV09+a5+n fiXh3j84npRXELBEXL0r3HEyZRt1Hx3R99pzItlXjWj8asujz4LjcIRLQpI/MFOTjearA CPY43e1Qgn810facyKfOCVSAe/dZVh9Fxam480JbGEeD5dSQbkRR79pPcLUKFvtiFccMD EtbfC/W2iCTOihlKWC9MQDArqI4dikICPrtRejeiQy9PRwxC/9aTy+2IM9ELzg1TgE7DV JWvl25VwWHhVjia6kjZKJZSoRv+CCBq2brF3x/2PlGKImjjh9TgsXGpFJXCuYJEgLiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387633; 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=ENQXe+Rt7eW5Mw+6TKyKGDhGHEYte3jeGQSb87bffC0=; b=WrSM3imt5+SHnSnHXLxKUxZsfXNVVEYzcQg3lu7zXVNqhtATfU0qZm5XqvP1iQ3P7X0z ifZT3pls+Fqy8aO7w3tMgwIgXa461GLIVkt8/zRlJ9dMLaKV0EUFNaPusdMzN/pCV7cLp Be+O3vr2rKH8LuuoztZfJ3Wf4xRSgG9oN9NX4IiKINRt8eRThuhT0zR9ew5hFv2A1zW/Y EO5caqWDF71fGqc2QaWdzV4+RhXAe898GxWGZjCaA8/IrSsaZHl+YCsGwsRYhS1+ODRwG Gd9E2Iar+4mckJ8exCFzv07YkRlT6w0i30+7qin4SW7WIVjWK1tLCiPyPyxAUhN+PPQ== 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=NIv6AjkI; 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 2BF5E606A32D; Fri, 4 Dec 2026 12:33:53 +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=NIv6AjkI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 939211F000CE; Fri, 4 Dec 2026 12:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387633; bh=ENQXe+Rt7eW5Mw+6TKyKGDhGHEYte3jeGQSb87bffC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NIv6AjkIJYCsWSVRlpBv6949EKr5JcOt6TxsQo8PML0NlH6xYHpgstreM46cysMGU vhkIZ/eWlYCpbNzHszNJ3ZhyQJxEHrX4uxkAGlZ+oRCP9yC1xL6WFeFVW7PdD6ApG0 bnnJNAaiDF2H58bqJT1OS/F5AAKwkUjhnqeQvEcc= 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.1 0327/1059] scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets Date: Fri, 4 Dec 2026 18:57:38 +0900 Message-ID: <20261204100652.738490386@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 branch's older sdev_printk format and do_device_access() argument list (no group or atomic flag), applying only the u64 and %llu changes. ] 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 620911ccd134f..edf9a027d70c8 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3733,7 +3733,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; @@ -3807,14 +3808,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) { @@ -3841,7 +3842,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); @@ -3852,7 +3855,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