libnvme: take only pairs of hexadecimal digits in a secret - #3829
Open
kariya-mitsuru wants to merge 1 commit into
Open
libnvme: take only pairs of hexadecimal digits in a secret#3829kariya-mitsuru wants to merge 1 commit into
kariya-mitsuru wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
libnvmf_create_raw_secret()means to reject a secret that is not hexadecimal,but
sscanf("%02x")takes a sign, skips leading whitespace without counting ittowards the field width, and reports a conversion where it stopped at a
character it could not convert. So a secret of
-1repeated comes outbyte-identical to
ffrepeated, and 63 spaces followed byfbuilds all 32bytes 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-tlsas well.libnvme/tests/raw-secret.ccovers both, and fails on the parent commit.Independent of #3827, which fixes the KX-HMAC-CHAP side of this in the plugin.