Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/56576 )
Change subject: lib/cbfs: Call rdev_unmap on hash mismatch ......................................................................
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 --- M src/lib/cbfs.c 1 file changed, 8 insertions(+), 1 deletion(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved Karthik Ramasubramanian: Looks good to me, approved
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 32b50da..52f7373 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -309,8 +309,15 @@ 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);