public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver
@ 2018-07-25 19:47 Vladimir Olovyannikov
  2018-07-26 15:52 ` Ard Biesheuvel
  2018-07-27  0:57 ` Zeng, Star
  0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Olovyannikov @ 2018-07-25 19:47 UTC (permalink / raw)
  To: edk2-devel; +Cc: Vladimir Olovyannikov

FvSimpleFileSystem on read always allocates a FileBuffer, and never frees
it. This causes memory leaks. It is especially bad for reading scripts
line-by-line. In some cases memory leak can exceed 1GB.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Vladimir Olovyannikiov <vladimir.olovyannikov@broadcom.com>
---
 .../Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c       | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
index 746f2ced708a..fde208594737 100644
--- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
+++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
@@ -704,6 +704,7 @@ FvSimpleFileSystemRead (
 
     Status = FvFsReadFile (File->Instance->FvProtocol, File->FvFileInfo, &FileSize, &FileBuffer);
     if (EFI_ERROR (Status)) {
+      FreePool (FileBuffer);
       return EFI_DEVICE_ERROR;
     }
 
@@ -714,6 +715,8 @@ FvSimpleFileSystemRead (
     CopyMem (Buffer, (UINT8*)FileBuffer + File->Position, *BufferSize);
     File->Position += *BufferSize;
 
+    FreePool (FileBuffer);
+
     return EFI_SUCCESS;
   }
 }
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver
  2018-07-25 19:47 [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver Vladimir Olovyannikov
@ 2018-07-26 15:52 ` Ard Biesheuvel
  2018-07-27  0:57 ` Zeng, Star
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2018-07-26 15:52 UTC (permalink / raw)
  To: Vladimir Olovyannikov, Zeng, Star, Eric Dong; +Cc: edk2-devel@lists.01.org

(add maintainers)

On 25 July 2018 at 21:47, Vladimir Olovyannikov
<vladimir.olovyannikov@broadcom.com> wrote:
> FvSimpleFileSystem on read always allocates a FileBuffer, and never frees
> it. This causes memory leaks. It is especially bad for reading scripts
> line-by-line. In some cases memory leak can exceed 1GB.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Vladimir Olovyannikiov <vladimir.olovyannikov@broadcom.com>
> ---
>  .../Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c       | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
> index 746f2ced708a..fde208594737 100644
> --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
> +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
> @@ -704,6 +704,7 @@ FvSimpleFileSystemRead (
>
>      Status = FvFsReadFile (File->Instance->FvProtocol, File->FvFileInfo, &FileSize, &FileBuffer);
>      if (EFI_ERROR (Status)) {
> +      FreePool (FileBuffer);
>        return EFI_DEVICE_ERROR;
>      }
>
> @@ -714,6 +715,8 @@ FvSimpleFileSystemRead (
>      CopyMem (Buffer, (UINT8*)FileBuffer + File->Position, *BufferSize);
>      File->Position += *BufferSize;
>
> +    FreePool (FileBuffer);
> +
>      return EFI_SUCCESS;
>    }
>  }
> --
> 2.18.0
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver
  2018-07-25 19:47 [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver Vladimir Olovyannikov
  2018-07-26 15:52 ` Ard Biesheuvel
@ 2018-07-27  0:57 ` Zeng, Star
  1 sibling, 0 replies; 3+ messages in thread
From: Zeng, Star @ 2018-07-27  0:57 UTC (permalink / raw)
  To: Vladimir Olovyannikov, edk2-devel@lists.01.org; +Cc: Zeng, Star

Reviewed-by: Star Zeng <star.zeng@intel.com> and pushed the patch at b5bd3ed64898db1088a9468446a0d2d0dc7185e8 with changing the title a little to " MdeModulePkg FvSimpleFileSystemDxe: Fix memory leak in Read function ".

Thanks,
Star
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Vladimir Olovyannikov
Sent: Thursday, July 26, 2018 3:48 AM
To: edk2-devel@lists.01.org
Cc: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
Subject: [edk2] [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver

FvSimpleFileSystem on read always allocates a FileBuffer, and never frees it. This causes memory leaks. It is especially bad for reading scripts line-by-line. In some cases memory leak can exceed 1GB.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Vladimir Olovyannikiov <vladimir.olovyannikov@broadcom.com>
---
 .../Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c       | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
index 746f2ced708a..fde208594737 100644
--- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
+++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
@@ -704,6 +704,7 @@ FvSimpleFileSystemRead (
 
     Status = FvFsReadFile (File->Instance->FvProtocol, File->FvFileInfo, &FileSize, &FileBuffer);
     if (EFI_ERROR (Status)) {
+      FreePool (FileBuffer);
       return EFI_DEVICE_ERROR;
     }
 
@@ -714,6 +715,8 @@ FvSimpleFileSystemRead (
     CopyMem (Buffer, (UINT8*)FileBuffer + File->Position, *BufferSize);
     File->Position += *BufferSize;
 
+    FreePool (FileBuffer);
+
     return EFI_SUCCESS;
   }
 }
--
2.18.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-27  1:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25 19:47 [PATCH v1] MdeModulePkg: Fix memory leak in FvSimpleFileSystem driver Vladimir Olovyannikov
2018-07-26 15:52 ` Ard Biesheuvel
2018-07-27  0:57 ` Zeng, Star

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox