From 741d1e9d3f368908e3cd1861ddd707e81e1fd576 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 15 Nov 2023 18:35:23 -0700 Subject: bootstd: Avoid freeing a non-allocated buffer EFI applications can be very large and thus used to cause boot failures when malloc() space was exhausted. A recent changed fixed this by using the kernel_addr_r environment var as the address of the buffer. However, it still frees the buffer when the bootflow is discarded. Fix this by introducing a flag to indicate whether the buffer was allocated, or not. Note that kernel_addr_r is not the last word here. It might be better to use lmb to place images. But there is a lot of refactoring to do before we can remove the environment variables. The distro scripts rely on them so it is safe for bootstd to do so too. Fixes: 6a8c2f9781c bootstd: Avoid allocating memory for the EFI file Signed-off-by: Simon Glass Reported by: Simon Glass Reported by: Shantur Rathore Reviewed-by: Heinrich Schuchardt Tested-by: Shantur Rathore --- boot/bootflow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'boot/bootflow.c') diff --git a/boot/bootflow.c b/boot/bootflow.c index 6922e7e0c4e..1ea2966ae9a 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -467,7 +467,8 @@ void bootflow_free(struct bootflow *bflow) free(bflow->name); free(bflow->subdir); free(bflow->fname); - free(bflow->buf); + if (!(bflow->flags & BOOTFLOWF_STATIC_BUF)) + free(bflow->buf); free(bflow->os_name); free(bflow->fdt_fname); free(bflow->bootmeth_priv); -- cgit v1.2.3