Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
lib/handle.c: Bounds check for block exceeding page length (CVE-2021-…
…3504) Hives are encoded as fixed-sized pages containing smaller variable- length blocks: +-------------------+-------------------+-------------------+-- | header |[ blk ][blk][ blk ]|[blk][blk][blk] | +-------------------+-------------------+-------------------+-- Blocks should not straddle a page boundary. However because blocks contain a 32 bit length field it is possible to construct an invalid hive where the last block in a page overlaps either the next page or the end of the file: +-------------------+-------------------+ | header |[ blk ][blk][ blk ..... ] +-------------------+-------------------+ Hivex lacked a bounds check and would process the registry. Because the rest of the code assumes this situation can never happen it was possible to have a block containing some field (eg. a registry key name) which would extend beyond the end of the file. Hivex mmaps or mallocs the file, causing hivex to read memory beyond the end of the mapped region, resulting in reading other memory structures or a crash. (Writing beyond the end of the mapped region seems to be impossible because we always allocate a new page before writing.) This commit adds a check which rejects the malformed registry on hivex_open. Credit: Jeremy Galindo, Sr Security Engineer, Datto.com Signed-off-by: Richard W.M. Jones <rjones@redhat.com> Fixes: CVE-2021-3504 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1949687
- Loading branch information