Skip to content

Commit 4310c19

Browse files
authored
This PR fixes issue #5383, which was occurring due to actual_len + H5C_IMAGE_EXTRA_SPACE being 0. When realloc was called, it freed image, but gets sent to done before new_image can be assigned to image. Because the pointer for image isn't null, it attempts to free it here again, causing the double free to occur. This PR addresses Quincey's concern and fixes the issue while preserving new_image and image. The bug was first reproduced using the fuzzer and the POC file from #5383. With this change, the double free no longer occurs.
1 parent 3895461 commit 4310c19

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

release_docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ Added Fortran wrapper h5fdsubfiling_get_file_mapping_f() for the subfiling file
585585

586586
Fixes GitHub issue #5329
587587

588+
### Fixed security issue CVE-2025-2925
589+
Actual_len + H5C_IMAGE_EXTRA_SPACE, which was used by H5MM_realloc as the size input, could equal 0 due to bad inputs. When H5MM_realloc was called, it freed image, but then could get sent to done before new_image could be assigned to image. Because the pointer for image wasn't null, it was freed again in done, causing a double-free vulnerability. H5C__load_entry() now checks for an image buffer length of 0 before calling H5MM_realloc.
590+
591+
Fixes Github issue #5383
592+
588593
### Fixed security issue CVE-2025-6857
589594

590595
An HDF5 file had a corrupted v1 B-tree that would result in a stack overflow when performing a lookup on it. This has been fixed with additional integrity checks.

src/H5Centry.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,14 @@ H5C__load_entry(H5F_t *f,
10521052
*/
10531053
do {
10541054
if (actual_len != len) {
1055+
/* Verify that the length isn't a bad value */
1056+
if (len == 0)
1057+
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "len is a bad value");
1058+
10551059
if (NULL == (new_image = H5MM_realloc(image, len + H5C_IMAGE_EXTRA_SPACE)))
10561060
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()");
10571061
image = (uint8_t *)new_image;
1062+
10581063
#if H5C_DO_MEMORY_SANITY_CHECKS
10591064
H5MM_memcpy(image + len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE);
10601065
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */
@@ -1105,10 +1110,15 @@ H5C__load_entry(H5F_t *f,
11051110
if (H5C__verify_len_eoa(f, type, addr, &actual_len, true) < 0)
11061111
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "actual_len exceeds EOA");
11071112

1113+
/* Verify that the length isn't 0 */
1114+
if (actual_len == 0)
1115+
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "actual_len is a bad value");
1116+
11081117
/* Expand buffer to new size */
11091118
if (NULL == (new_image = H5MM_realloc(image, actual_len + H5C_IMAGE_EXTRA_SPACE)))
11101119
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, NULL, "image null after H5MM_realloc()");
11111120
image = (uint8_t *)new_image;
1121+
11121122
#if H5C_DO_MEMORY_SANITY_CHECKS
11131123
H5MM_memcpy(image + actual_len, H5C_IMAGE_SANITY_VALUE, H5C_IMAGE_EXTRA_SPACE);
11141124
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */

0 commit comments

Comments
 (0)