ocp-smart-extended-log: fix sizeof mismatch in malloc for get_c0_log_page()#3555
Open
sahmed-ibm wants to merge 1 commit into
Open
Conversation
…page() The get_c0_log_page() function allocates a buffer @DaTa to hold the C0 SMART extended log page, but passes sizeof of an unrelated scalar type as the malloc operand instead of sizeof of the struct @DaTa points to. If the compiler inserts alignment padding into the struct, the allocation will be smaller than the struct size, causing a heap buffer overflow when the struct fields are accessed beyond the allocated region. Fix by using sizeof(*data) to ensure the correct amount of memory is allocated and zeroed for the struct. Signed-off-by: Sarah Ahmed <sarah.ahmed@ibm.com>
Collaborator
|
according pahole which is in hex #define C0_SMART_CLOUD_ATTR_LEN 0x200 and later in the code we do nvme_init_get_log(&cmd, NVME_NSID_ALL,
(enum nvme_cmd_get_log_lid)OCP_LID_SMART,
NVME_CSI_NVM, data, C0_SMART_CLOUD_ATTR_LEN);As far I understand your argument is that the compiler might insert padding? If this would happen the data struct would be useless. |
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.
The get_c0_log_page() function allocates a buffer @DaTa to hold the C0 SMART extended log page, but passes sizeof of an unrelated scalar type as the malloc operand instead of sizeof of the struct @DaTa points to.
If the compiler inserts alignment padding into the struct, the allocation will be smaller than the struct size, causing a heap buffer overflow when the struct fields are accessed beyond the allocated region.
Fix by using sizeof(*data) to ensure the correct amount of memory is allocated and zeroed for the struct.