|
| 1 | +From 54f404b5ad8e63d99e3283646b543b2842a22fd3 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Binh-Minh <bmribler@hdfgroup.org> |
| 3 | +Date: Tue, 12 Aug 2025 20:06:42 -0400 |
| 4 | +Subject: [PATCH] Refix of the attempts in PR-5209 |
| 5 | + |
| 6 | +This PR addresses the root cause of the issue by adding a sanity-check immediately |
| 7 | +after reading the file space page size from the file. |
| 8 | + |
| 9 | +The same fuzzer in GH-5376 was used to verify that the assert before the vulnerability |
| 10 | +had occurred and that an error indicating a corrupted file space page size replaced it. |
| 11 | + |
| 12 | +Upstream Patch Reference: https://patch-diff.githubusercontent.com/raw/HDFGroup/hdf5/pull/5722.patch |
| 13 | +--- |
| 14 | + src/H5Fsuper.c | 2 ++ |
| 15 | + src/H5Ofsinfo.c | 3 +++ |
| 16 | + 2 files changed, 5 insertions(+) |
| 17 | + |
| 18 | +diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c |
| 19 | +index d9fe3a7..1c8dc6c 100644 |
| 20 | +--- a/src/H5Fsuper.c |
| 21 | ++++ b/src/H5Fsuper.c |
| 22 | +@@ -746,6 +746,8 @@ H5F__super_read(H5F_t *f, H5P_genplist_t *fa_plist, bool initial_read) |
| 23 | + if (!(flags & H5O_MSG_FLAG_WAS_UNKNOWN)) { |
| 24 | + H5O_fsinfo_t fsinfo; /* File space info message from superblock extension */ |
| 25 | + |
| 26 | ++ memset(&fsinfo, 0, sizeof(H5O_fsinfo_t)); |
| 27 | ++ |
| 28 | + /* f->shared->null_fsm_addr: Whether to drop free-space to the floor */ |
| 29 | + /* The h5clear tool uses this property to tell the library |
| 30 | + * to drop free-space to the floor |
| 31 | +diff --git a/src/H5Ofsinfo.c b/src/H5Ofsinfo.c |
| 32 | +index 5b69235..2bb6ea6 100644 |
| 33 | +--- a/src/H5Ofsinfo.c |
| 34 | ++++ b/src/H5Ofsinfo.c |
| 35 | +@@ -182,6 +182,9 @@ H5O__fsinfo_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNU |
| 36 | + if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_size(f), p_end)) |
| 37 | + HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding"); |
| 38 | + H5F_DECODE_LENGTH(f, p, fsinfo->page_size); /* File space page size */ |
| 39 | ++ /* Basic sanity check */ |
| 40 | ++ if (fsinfo->page_size == 0 || fsinfo->page_size > H5F_FILE_SPACE_PAGE_SIZE_MAX) |
| 41 | ++ HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "invalid page size in file space info"); |
| 42 | + |
| 43 | + if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end)) |
| 44 | + HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding"); |
| 45 | +-- |
| 46 | +2.45.4 |
| 47 | + |
0 commit comments