Skip to content

libnvme: take only pairs of hexadecimal digits in a secret - #3829

Open
kariya-mitsuru wants to merge 1 commit into
linux-nvme:masterfrom
kariya-mitsuru:libnvme-reject-non-hex-secret
Open

libnvme: take only pairs of hexadecimal digits in a secret#3829
kariya-mitsuru wants to merge 1 commit into
linux-nvme:masterfrom
kariya-mitsuru:libnvme-reject-non-hex-secret

Conversation

@kariya-mitsuru

Copy link
Copy Markdown
Contributor

libnvmf_create_raw_secret() means to reject a secret that is not hexadecimal,
but sscanf("%02x") takes a sign, skips leading whitespace without counting it
towards the field width, and reports a conversion where it stopped at a
character it could not convert. So a secret of -1 repeated comes out
byte-identical to ff repeated, and 63 spaces followed by f builds all 32
bytes out of that one digit.

It also reads a lone trailing character as a byte of its own, zero padded, which
reaches nvme keys gen-tls as well.

libnvme/tests/raw-secret.c covers both, and fails on the parent commit.

Independent of #3827, which fixes the KX-HMAC-CHAP side of this in the plugin.

libnvmf_create_raw_secret() means to reject a secret that is not
hexadecimal, but sscanf("%02x") takes a sign, skips leading whitespace
without counting it towards the field width, and reports a conversion
where it stopped at a character it could not convert. So "-1" repeated
comes out as 0xff repeated, and 63 spaces followed by "f" builds all 32
bytes out of that one digit.

It also reads a lone trailing character as a byte of its own, zero
padded. That one reaches gen-tls as well, but nothing can depend on the
byte it invents.

Convert the pair with shr_hex_to_int() instead of emitting a secret the
caller never gave.

Signed-off-by: Mitsuru Kariya <kariya_mitsuru@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant