diff options
author | Raul E Rangel <rrangel@chromium.org> | 2021-07-23 15:23:12 -0600 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2021-10-20 15:55:21 +0000 |
commit | 3f41d3269e462c2c0a7d7c4cbdc20f0b07b166ee (patch) | |
tree | 3eee8eb312ea3f983c2b9a3b7d414555b3e5a8c2 /src/lib | |
parent | 4396358fd314d5cf4dfb01b6d7176159707df226 (diff) | |
download | coreboot-3f41d3269e462c2c0a7d7c4cbdc20f0b07b166ee.tar.gz coreboot-3f41d3269e462c2c0a7d7c4cbdc20f0b07b166ee.tar.bz2 coreboot-3f41d3269e462c2c0a7d7c4cbdc20f0b07b166ee.zip |
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 <rrangel@chromium.org>
Change-Id: Ibcd28ce12cbd5e221e8f4fa910fd8472bedb802f
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56576
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/cbfs.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 32b50da30ce9..52f73736da6c 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); |