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=1796381308; b=Ffo6e8BYKIXg3D4pskrL9/X4vOM2JgJxiWRL7+cia6IzzmTmHjkt1f3gSHT/0s1E7xK7 I/CQd8Lgd6T9vwzDeIZqPZ4LBTSPLxWEltgFVSiBwIOYgIzxFkqD9lW7WFQDWvtJAC6U/ /7I7EPhLbxNaqm/+5VS44YkUGmvB30UewLyblBhCoHLCWeSjZXzkvEao7ODGwsoDBGIwx f2cSQWfYsG+h++WS3w5Q5pg5jMlDrqGDAyRBmILrG6FdG0gmIpRYhvBMfQIVuDiOu1hP5 U26CXabeJylHMIAuoqoVg/aKCGbzdQDS94dwpjU/HtElIieKa1r4p3ljp6eBXDvRerw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381308; 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=JVZnPVJghmqyB0kVVMIKsF+5TtQvoEj+XrsVL5DlWg4=; b=XLb67PAQw6MAG6G3oNBMaqQgtFp16SLS3tBtAI8yGhHwrCpOu83bSmjBxVGJx9rSxFyg 59A8zRx7Sai9ncCK9PjijTCFHcDatJaDRbWUecaeGt6zlg81aLy2rIYSiXOTvnkAtBkKV i5Nfx1mFZr4c4gYxqogxk2Azs+gcOq20M/PzshMv7J5Rf7Rpcqt27hPQHnpBisypOWwHC hPPNh8LSj01gIjpJhFUKLW3p25M5+ilt/Z2nFqxFHEsLPYW4YfOVni2lhcCbGJZ1z7fvH vo391qsH5QWKkjQPNbEbUiF7MUguVmrcv+c7RRbuW6OZL/GRfVsDIRCEQcuuBG9ahbw== 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=wTqW6lJH; 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 A1373606A332; Fri, 4 Dec 2026 10:48:28 +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=wTqW6lJH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1642C1F000CE; Fri, 4 Dec 2026 10:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381308; bh=JVZnPVJghmqyB0kVVMIKsF+5TtQvoEj+XrsVL5DlWg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wTqW6lJHWCp4n8HYtNgtuByfG8q+y7mtqdWCXl+5tlxQPOz1FOwdh6guPagOjKHjV s0nRGMqaWpCNiuUR/AWhNGp9wM7H2x7VUoIgADfuHOmyuxxsdkKRdsSUM8ZGW7Ww3x mbLH2jwKD1bW1HlZ+i4bsXNg/DB+wzp1idD6SVwc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Christoph Hellwig , Keith Busch Subject: [PATCH 7.3 647/742] nvmet: use overflow-safe range checks in the file backend Date: Fri, 4 Dec 2026 19:08:31 +0900 Message-ID: <20261204100652.279041997@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shao Mingyin commit bcd5316e708d418f03707c183571549ad878cfff upstream. The file backend shifts a host-supplied SLBA to form a byte offset before checking it against the namespace size. The shift can discard high bits: with a 4 KiB block size, SLBA 2^52 + 1 becomes offset 4096. The range check then accepts a command aimed outside the namespace and the backend accesses data at the wrapped offset. Reject overflowing LBA-to-byte conversions and check the transfer length against the remaining namespace size without adding it to the offset. Apply the checks to reads, writes, discard and write zeroes. Fixes: 9c891c139894 ("nvmet: check fileio lba range access boundaries") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/target/io-cmd-file.c | 40 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -117,6 +117,19 @@ static void nvmet_file_io_done(struct ki nvmet_req_complete(req, status); } +static bool nvmet_file_check_lba_range(struct nvmet_req *req, u64 slba, + u64 len, loff_t *pos) +{ + u64 pos64; + + if (check_shl_overflow(slba, req->ns->blksize_shift, &pos64) || + pos64 > req->ns->size || len > req->ns->size - pos64) + return false; + + *pos = pos64; + return true; +} + static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) { ssize_t nr_bvec = req->sg_cnt; @@ -131,8 +144,9 @@ static bool nvmet_file_execute_io(struct if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC) is_sync = true; - pos = le64_to_cpu(req->cmd->rw.slba) << req->ns->blksize_shift; - if (unlikely(pos + req->transfer_len > req->ns->size)) { + if (unlikely(!nvmet_file_check_lba_range(req, + le64_to_cpu(req->cmd->rw.slba), + req->transfer_len, &pos))) { ret = -ENOSPC; goto complete; } @@ -282,19 +296,22 @@ static void nvmet_file_execute_discard(s int i; for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) { + u64 len64; + status = nvmet_copy_from_sgl(req, i * sizeof(range), &range, sizeof(range)); if (status) break; - offset = le64_to_cpu(range.slba) << req->ns->blksize_shift; - len = le32_to_cpu(range.nlb); - len <<= req->ns->blksize_shift; - if (offset + len > req->ns->size) { + if (check_shl_overflow((u64)le32_to_cpu(range.nlb), + req->ns->blksize_shift, &len64) || + !nvmet_file_check_lba_range(req, le64_to_cpu(range.slba), + len64, &offset)) { req->error_slba = le64_to_cpu(range.slba); status = errno_to_nvme_status(req, -ENOSPC); break; } + len = len64; ret = vfs_fallocate(req->ns->file, mode, offset, len); if (ret && ret != -EOPNOTSUPP) { @@ -339,16 +356,17 @@ static void nvmet_file_write_zeroes_work int mode = FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE; loff_t offset; loff_t len; + u64 len64; int ret; - offset = le64_to_cpu(write_zeroes->slba) << req->ns->blksize_shift; - len = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) << - req->ns->blksize_shift); - - if (unlikely(offset + len > req->ns->size)) { + if (check_shl_overflow((u64)le16_to_cpu(write_zeroes->length) + 1, + req->ns->blksize_shift, &len64) || + !nvmet_file_check_lba_range(req, le64_to_cpu(write_zeroes->slba), + len64, &offset)) { nvmet_req_complete(req, errno_to_nvme_status(req, -ENOSPC)); return; } + len = len64; ret = vfs_fallocate(req->ns->file, mode, offset, len); nvmet_req_complete(req, ret < 0 ? errno_to_nvme_status(req, ret) : 0);