From: yeeli <[email protected]>
key_options[] is used by setup-passphrase and update-passphrase, but
it is not terminated with OPT_END(). The option parser walks the
array until it finds an OPTION_END entry, so it runs past the end of
key_options[] and interprets the adjacent sanitize_options[] array.
Before the fix, --crypto-erase is silently accepted and the command
prints the bogus usage:
$ ndctl setup-passphrase --crypto-erase
usage: ndctl setup-passphrase <nmem0> [<nmem1>..<nmemN>] [<options>]
-b, --bus <bus-id> <nmem> must be on a bus with an
id/provider of <bus-id>
-v, --verbose turn on debug
-k, --key-handle <key-handle>
master encryption key handle
-m, --master-passphrase
use master passphrase
-b, --bus <bus-id> <nmem> must be on a bus with an
id/provider of <bus-id>
-v, --verbose turn on debug
-c, --crypto-erase crypto erase a dimm
-o, --overwrite overwrite a dimm
-z, --zero-key pass in a zero key
-m, --master-passphrase
use master passphrase
After the fix, the same command rejects the invalid option and
prints only the valid options:
$ ndctl setup-passphrase --crypto-erase
Error: unknown option `crypto-erase'
usage: ndctl setup-passphrase <nmem0> [<nmem1>..<nmemN>] [<options>]
-b, --bus <bus-id> <nmem> must be on a bus with an
id/provider of <bus-id>
-v, --verbose turn on debug
-k, --key-handle <key-handle>
master encryption key handle
-m, --master-passphrase
use master passphrase
An AddressSanitizer build reports a global-buffer-overflow
immediately after key_options[].
Terminate key_options[] with OPT_END() so parsing stops at the end of
the array.
Tested by building ndctl on the target test system: both passphrase
commands now show only the four expected options, and --crypto-erase
is rejected as an unknown option.
Fixes: 374369ac2f67 ("ndctl: master phassphrase management support")
Signed-off-by: yeeli <[email protected]>
---
ndctl/dimm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index 533ab04..bae7782 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -1276,6 +1276,7 @@ static const struct option key_options[] = {
BASE_OPTIONS(),
KEY_OPTIONS(),
MASTER_OPTIONS(),
+ OPT_END(),
};
static const struct option sanitize_options[] = {
--
2.34.1