-
-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix vuln OSV-2024-381 #5202
base: develop
Are you sure you want to change the base?
Fix vuln OSV-2024-381 #5202
Conversation
src/H5Faccum.c
Outdated
@@ -881,6 +881,12 @@ H5F__accum_free(H5F_shared_t *f_sh, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr | |||
H5_CHECKED_ASSIGN(overlap_size, size_t, (addr + size) - accum->loc, haddr_t); | |||
new_accum_size = accum->size - overlap_size; | |||
|
|||
/* Ensure overlap_size and new_accum_size are within bounds */ | |||
if (overlap_size > accum->alloc_size || new_accum_size > accum->alloc_size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the specific vulnerability, but a more complete fix may be needed here. Consider the case where both overlap_size
and new_accum_size
end up slightly below accum->alloc_size
. It may make more sense to calculate a pointer to the last valid byte in accum->buf
and then make use of the H5_IS_BUFFER_OVERFLOW
macro from H5private.h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the specific vulnerability, but a more complete fix may be needed here. Consider the case where both
overlap_size
andnew_accum_size
end up slightly belowaccum->alloc_size
. It may make more sense to calculate a pointer to the last valid byte inaccum->buf
and then make use of theH5_IS_BUFFER_OVERFLOW
macro from H5private.h.
You are right. The current fix does not fully resolve the overflow
[Warning] This PR is generated by AI
PR Title: Fix Heap-Buffer-Overflow Vulnerability in HDF5 - OSV-2024-381
PR Description:
overlap_size
andnew_accum_size
) exceeded the allocated buffer size (alloc_size
), leading to a heap-buffer-overflow. This occurred due to the lack of bounds checking on these calculated values.Sanitizer Report Summary:
The sanitizer detected a heap-buffer-overflow when the program attempted to read 361 bytes from an offset -41 into a 520-byte heap buffer. The overflow occurred due to an incorrect calculation and lack of bounds checking in the
H5F__accum_free
function at/src/H5Faccum.c:885:17
. This issue propagated through multiple function calls, ultimately leading to a memory access violation.Full Sanitizer Report:
Files Modified:
src/H5Faccum.c
Patch Validation:
The patch has been validated using the provided PoC. It successfully resolves the heap-buffer-overflow issue identified in the sanitizer report. The program no longer exhibits the memory violation, and no new issues were introduced.
Links: