From 3f41d3269e462c2c0a7d7c4cbdc20f0b07b166ee Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Fri, 23 Jul 2021 15:23:12 -0600 Subject: lib/cbfs: Call rdev_unmap on hash mismatch We don't want to leak any mappings. BUG=b:179699789 TEST=none Signed-off-by: Raul E Rangel Change-Id: Ibcd28ce12cbd5e221e8f4fa910fd8472bedb802f Reviewed-on: https://review.coreboot.org/c/coreboot/+/56576 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Karthik Ramasubramanian --- src/lib/cbfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 32b50da30c..52f73736da 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -309,8 +309,15 @@ void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg, loc = allocator(arg, size, &mdata); } else if (compression == CBFS_COMPRESS_NONE) { void *mapping = rdev_mmap_full(&rdev); - if (!mapping || cbfs_file_hash_mismatch(mapping, size, file_hash)) + + if (!mapping) + return NULL; + + if (cbfs_file_hash_mismatch(mapping, size, file_hash)) { + rdev_munmap(&rdev, mapping); return NULL; + } + return mapping; } else if (!CBFS_CACHE_AVAILABLE) { ERROR("Cannot map compressed file %s on x86\n", mdata.h.filename); -- cgit v1.2.3