From nobody Mon Nov 09 19:14:08 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jNfbN4pQWz70LGS for ; Mon, 09 Nov 2026 19:14:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jNfbN3yhlz4TBk for ; Mon, 09 Nov 2026 19:14:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794251648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=znC2TUaQki/P5AKdFA0Ek8VXfCoGFGiqyA9zSdrYr0Y=; b=dgsMXe4gqEZ5jYF5Vf/Xx1N7PeU4SgBkOPKfLgJK3gGvIFpaIEKuwpRneT/+IpEOowakp3 dPDw0SMgOs7XeHQiRB6+ihUmzpjmZRU8FL0rbesFMd4MNX6CWvb1/P6cb781A6m0qTJXDM TuuuXTx4B/gE6ejaevaw6y12j/pTzg0pBbY859gzY1bJ9WSMQNkmHwjeXIw7/ts/uK4HF8 YgtlCBTopqApIKMWZ3sKkGERrcIbXkF/MZaFFQgtaf52EK+maaBlv2u9MPyjgs0lmDY0jL zivDaA+q0ROLsq3W1e477xGlzeBsSLotm3SlBGRNTkKMAIhMFBl1ilJE9OSbjw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794251648; b=hAIjUQ8C6BKn2I3Nria4tRc5oJI2/7UrNJwJ56rMCc8yF/OV/PgMf/d+QCZVBGwV46oCdQ 7dFQQlxvrfJAkRCUvRQenmmSI1sD0SoYiR/I+LIMur5D37R+6MtXqFjODaOY1Y9IdfG0Kv /xn9KHJQJyKsH5pj2/mZb9jp4d6DPi3GRHf5B1zmlNZPR6tagx8Y416bH4/X9mWPKo3rzn 0e3J9FTYGy25G5/DwfUKIN/VetuvcIRKPlE/lCSy0So3bBD8Knb4plJLORA6YcI6eFWml0 B+Ev9kKecb8LKwtvAEtrFNqyZMMEkqHFDx5G2KrxUFpOr0xffkPHTnlLaKtZ1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794251648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=znC2TUaQki/P5AKdFA0Ek8VXfCoGFGiqyA9zSdrYr0Y=; b=lggLMujShqo3B6QDZBji3hvVDeR1A72p9VJsGWG1KktIEJt7t8GIvU+vQG5nYFfJseJ0Uk 5rVWcBIKKuQwmm2jvOWF5Y1wSDhW8rgyA/JOnHoui9q2AaDQBT8NCJeZ/hiHCm9CvY1yFW c16FNZAkwOZN1KVa5ZlpAwRZ9sAthA7AvSt0sPmS6N+af39mJz/GBoCbFNYvozhym/OA4n /9Pihl29Z6e34Gttl9wTcn5AqEaSkkZ5xnjzCifOpy8oIRE4AJf0bVKzlK0igPt7OjGdeZ 85PzsdsEVky5ZxKMIeU/d6EpX/NB6Rdj01XMhsaZPutQQZMyRYLeK6HkJDZISw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jNfbN3cBjztWj for ; Mon, 09 Nov 2026 19:14:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e4e3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 09 Nov 2026 19:14:08 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kenneth D. Merry Subject: git: 3892a6453fc6 - main - nvme: Mask the fields in the Format NVM command builder List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ken X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3892a6453fc60e00b0d6cd5c5d7e2606b4b51e7c Auto-Submitted: auto-generated Date: Mon, 09 Nov 2026 19:14:08 +0000 Message-Id: <6af21b80.e4e3.22fdfcf0@gitrepo.freebsd.org> The branch main has been updated by ken: URL: https://cgit.FreeBSD.org/src/commit/?id=3892a6453fc60e00b0d6cd5c5d7e2606b4b51e7c commit 3892a6453fc60e00b0d6cd5c5d7e2606b4b51e7c Author: Kenneth D. Merry AuthorDate: 2026-11-09 18:46:57 +0000 Commit: Kenneth D. Merry CommitDate: 2026-11-09 18:59:12 +0000 nvme: Mask the fields in the Format NVM command builder nvme_admin_format_cmd() did not mask any of the fields it composes into cdw10, so an out of range value in one field would corrupt neighboring fields. In particular, an LBA format index greater than 15 would bleed into the metadata settings and protection information fields. It also had no support for LBA format indexes above 15, which NVMe 2.0 encodes via the separate LBAFU field. Mask all of the fields, and encode bits 5:4 of the LBA format index in the LBAFU field (cdw10 bits 13:12). Also reject out of range LBA format indexes in camcontrol's nvformat global (-G) mode, which has no namespace data to validate against. The per-namespace mode already validates the index against NLBAF. sys/dev/nvme/nvme.h: Mask the SES, PIL, PI, MSET and LBAF fields in nvme_admin_format_cmd() and encode the upper two bits of the LBA format index in LBAFU. sbin/camcontrol/nvformat.c: Reject LBA format indexes greater than 63 in -G mode. Reported by: llm-postcr Fixes: 7a9e4375316b Fixes: 80f090111ae4 MFC after: 1 week Sponsored by: Spectra Logic Co-authored-by: Claude Fable 5 --- sbin/camcontrol/nvformat.c | 6 ++++++ sys/dev/nvme/nvme.h | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sbin/camcontrol/nvformat.c b/sbin/camcontrol/nvformat.c index 94af800db422..a41b490d62bc 100644 --- a/sbin/camcontrol/nvformat.c +++ b/sbin/camcontrol/nvformat.c @@ -246,6 +246,12 @@ nvmeformat(struct cam_device *device, int argc, char **argv, char *combinedopt, ses = 0; if (lbaf < 0) lbaf = 0; + else if (lbaf > 63) { + warnx("%s: LBA format %d is out of range", __func__, + lbaf); + error = 1; + goto bailout; + } if (mset < 0) mset = 0; if (pi < 0) diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h index e3b8f1f9ced4..34929ee58f5e 100644 --- a/sys/dev/nvme/nvme.h +++ b/sys/dev/nvme/nvme.h @@ -2315,8 +2315,9 @@ void nvme_admin_format_cmd(struct nvme_command *cmd, uint32_t nsid, { cmd->opc = NVME_OPC_FORMAT_NVM; cmd->nsid = htole32(nsid); - cmd->cdw10 = htole32((ses << 9) | (pil << 8) | (pi << 5) | (mset << 4) | - lbaf); + cmd->cdw10 = htole32(((lbaf & 0x30) << 8) | ((ses & 0x7) << 9) | + ((pil & 0x1) << 8) | ((pi & 0x7) << 5) | ((mset & 0x1) << 4) | + (lbaf & 0x0f)); } static inline