git: e02aae338b1b - stable/15 - nvmecontrol: Range-check the format command's field values
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 21:00:48 UTC
The branch stable/15 has been updated by ken:
URL: https://cgit.FreeBSD.org/src/commit/?id=e02aae338b1bc52426dd055b34979eda7a353d47
commit e02aae338b1bc52426dd055b34979eda7a353d47
Author: Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-10 21:12:21 +0000
Commit: Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-16 16:14:21 +0000
nvmecontrol: Range-check the format command's field values
The format command accepted any 32-bit value for -m, -p, -l and
--ses and passed it into the Format NVM command. Before
eae727676169 an out-of-range value spilled into the adjacent cdw10
fields, which usually drew an error from the controller; after it,
the value is masked to the field width, so a mistyped value is
silently accepted with a different meaning. Most seriously,
--ses 8 masked to SES=0 and performed a plain format with no erase
at all, exiting 0. A value like --ses 10 masked to a cryptographic
erase while bypassing the FNA cryptographic erase capability check,
which compares the unmasked value.
Reject values outside the ranges nvmecontrol.8 documents, which are
the values the spec defines: 0-1 for -m and -l, 0-3 for -p, and
0-2 for --ses. The checks run at option validation time, before
the device is opened, and the capability check now only ever sees
valid values.
While here, document --ses in nvmecontrol.8; it was missing from the
format subcommand's option list.
Reported by: llm-postcr
Reviewed by: imp
Fixes: eae727676169
MFC after: 1 week
Sponsored by: Spectra Logic
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Differential Revision: https://reviews.freebsd.org/D61406
(cherry picked from commit 3d6f886151f9ee6f3bf16ea3367a4b540df3f911)
---
sbin/nvmecontrol/format.c | 10 ++++++++++
sbin/nvmecontrol/nvmecontrol.8 | 20 +++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/sbin/nvmecontrol/format.c b/sbin/nvmecontrol/format.c
index 741a69412e58..c88192e5d01e 100644
--- a/sbin/nvmecontrol/format.c
+++ b/sbin/nvmecontrol/format.c
@@ -127,6 +127,16 @@ format(const struct cmd *f, int argc, char *argv[])
"Only one of -E, -C or -s may be specified\n");
arg_help(argc, argv, f);
}
+ if (opt.ms != NONE && opt.ms > 1)
+ errx(EX_USAGE, "metadata setting must be 0 or 1");
+ if (opt.pi != NONE && opt.pi > 3)
+ errx(EX_USAGE,
+ "protection information type must be between 0 and 3");
+ if (opt.pil != NONE && opt.pil > 1)
+ errx(EX_USAGE,
+ "protection information location must be 0 or 1");
+ if (opt.ses > SES_CRYPTO)
+ errx(EX_USAGE, "secure erase setting must be between 0 and 2");
target = opt.dev;
lbaf = opt.lbaf;
diff --git a/sbin/nvmecontrol/nvmecontrol.8 b/sbin/nvmecontrol/nvmecontrol.8
index 4497263d5873..5fbc5f4a08f6 100644
--- a/sbin/nvmecontrol/nvmecontrol.8
+++ b/sbin/nvmecontrol/nvmecontrol.8
@@ -33,7 +33,7 @@
.\"
.\" Author: Jim Harris <jimharris@FreeBSD.org>
.\"
-.Dd July 31, 2026
+.Dd November 10, 2026
.Dt NVMECONTROL 8
.Os
.Sh NAME
@@ -545,6 +545,24 @@ physically erase the underlying media.
Enables Cryptographic Erase during format.
All user data is erased cryptographically by deleting the encryption key,
rendering it unintelligible.
+.It Fl Fl ses Ar ses
+Secure Erase Settings.
+.Bl -tag -compact -width 6n
+.It Dv 0
+Do not perform a secure erase.
+.It Dv 1
+User Data Erase, as with
+.Fl E .
+.It Dv 2
+Cryptographic Erase, as with
+.Fl C .
+.El
+Only one of
+.Fl E ,
+.Fl C ,
+or
+.Fl Fl ses
+may be specified.
.El
.Pp
When formatting specific namespace, existing values are used as defaults.