efi_loader: Prevent leak of memory from tmp_files
PATCH 1/1 efi_loader: Prevent leak of memory from tmp_files
After the malloc of tmp_files and before its value is recorded an early exit will need to free tmp_files to prevent leaking that memory.
This issue was found by Smatch.
--- lib/efi_loader/efi_capsule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/efi_loader/efi_capsule.c +3 -1
@@ -1096,8 +1096,10 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)while (1 ) { tmp_size = dirent_size; ret =EFI_CALL ((*dirh->read)(dirh, &tmp_size, dirent)); -if (ret !=EFI_SUCCESS ) +if (ret !=EFI_SUCCESS ) { +free (tmp_files); goto err; + }if (!tmp_size)break ;
---
base-commit: 8d22c596c6f82132c006ba89481275c60b5b0e2d
change-id: 20251003-efi_capsule-48cd72edc60a
Best regards,
Signature · 1 line
Andrew Goodbody <[email protected]>
Quoted 4 lines · Andrew Goodbody
After the malloc of
tmp_filesand before its value is recorded an early exit will need to freetmp_filesto prevent leaking that memory.This issue was found by Smatch.
Thank you for following up through all those issues indicated by static code analysis.
Tom could grant you access to Coverity to look at what is reported there (https://scan.coverity.com/projects/das-u-boot).
Quoted 12 lines
Signed-off-by Andrew Goodbody <[email protected]>--- lib/efi_loader/efi_capsule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/efi_loader/efi_capsule.c +0
-0@@ -1096,8 +1096,10 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)while (1 ) {
lib/efi_loader/efi_capsule.c static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num) · line 1105
Quoted 10 lines
lib/efi_loader/efi_capsule.c +3
-1tmp_size = dirent_size; ret =EFI_CALL ((*dirh->read)(dirh, &tmp_size, dirent)); -if (ret !=EFI_SUCCESS ) +if (ret !=EFI_SUCCESS ) { +free (tmp_files); goto err; + }if (!tmp_size)break ;
LGTM
Quoted 9 lines · Heinrich Schuchardt
Quoted 4 lines · Andrew Goodbody
After the malloc of
tmp_filesand before its value is recorded an early exit will need to freetmp_filesto prevent leaking that memory.This issue was found by Smatch.
Thank you for following up through all those issues indicated by static code analysis.
Tom could grant you access to Coverity to look at what is reported there (https://scan.coverity.com/projects/das-u-boot).
Thanks Heinrich. Tom has already granted me access to Coverity. I am not quite sure where my priorities will be next but I hope to at least look at adding Smatch to CI.
Andrew
Quoted 25 lines
Quoted 11 lines
Signed-off-by Andrew Goodbody <[email protected]>---
lib/efi_loader/efi_capsule.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)lib/efi_loader/efi_capsule.c +0
-0@@ -1096,8 +1096,10 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)lib/efi_loader/efi_capsule.c static efi_status_t efi_capsule_scan_dir(u16 · line 1105
Quoted 10 lines
lib/efi_loader/efi_capsule.c +3
-1while (1) { tmp_size = dirent_size; ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent)); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + free(tmp_files); goto err; + } if (!tmp_size) break;LGTM
Reviewed-by Heinrich Schuchardt <[email protected]>