libnvme: zero-init ns in __nvme_transport_handle_open_direct()#3348
Closed
Mateusz-Nowicki-Embedded wants to merge 1 commit into
Closed
libnvme: zero-init ns in __nvme_transport_handle_open_direct()#3348Mateusz-Nowicki-Embedded wants to merge 1 commit into
Mateusz-Nowicki-Embedded wants to merge 1 commit into
Conversation
When __nvme_transport_handle_open_direct() is called for a controller character device (e.g. /dev/nvmeX), sscanf() of the device name against "nvme%dn%d" matches only the controller id, returns 1, and leaves `ns` uninitialised. The ioctl_probing path then propagates that stack value via dummy.nsid into the NVME_IOCTL_ADMIN64_CMD submission, which the kernel forwards verbatim as the SQE's NSID into the admin Submission Queue ring. The NSID field of the SQE is therefore filled with whatever stack contents happened to live in `ns` at that point. On x86_64 these are consistently in the 0x00007fXX range, which corresponds to the high half of user-space pointers and leaks a few bytes of caller stack into device-visible memory. Initialise ns to 0 so the probe NSID is deterministic. The probe is still submitted to the controller and still gets rejected with Invalid Queue Identifier (the probe carries opcode 0 / CDW10 = 0, i.e. a Delete I/O SQ targeting SQID 0); only the previously leaked bytes are now zeros. Signed-off-by: Mateusz Nowicki <mateusz.nowicki@posteo.net>
Collaborator
|
unfortunately, it's not that simple as it turns out: #3312 |
Collaborator
|
Fixed with #3357. Thanks for your report! Highly appreciated! |
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.
Minimal fix for an uninitialized-variable info leak in the ioctl_probing path.
When opening
/dev/nvmeX(controller char dev), the localnsvariable is left uninitialized after the "nvme%dn%d" sscanfreturns 1, then copied into
dummy.nsidand submitted as a real admin SQE. A few bytes of caller-stack memory end up indevice-visible memory (typically the high half of a user-space pointer on x86_64,
0x00007fXX...).This is the smallest possible fix — just initialize
ns = 0so the leaked bytes become zeros. The dummy probe is still sent and still rejected by the controller as before.Alternative: see #3349 for a more invasive fix that also removes the dummy submission entirely
(probe via NULL argp +ENOTTY/EFAULT distinction).