[edk2-devel] [PATCH 07/13] OvmfPkg/QemuKernelLoaderFsDxe: don't expose kernel command line

Ard Biesheuvel posted 13 patches 5 years, 11 months ago
There is a newer version of this series
[edk2-devel] [PATCH 07/13] OvmfPkg/QemuKernelLoaderFsDxe: don't expose kernel command line
Posted by Ard Biesheuvel 5 years, 11 months ago
We have no need for exposing the kernel command line as a file,
so remove support for that. Since the remaining blobs (kernel
and initrd) are typically much larger than a page, switch to
the page based allocator for blobs at the same time.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
index efecbd817da1..b8d64e2781fc 100644
--- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
+++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
@@ -30,7 +30,6 @@
 typedef enum {
   KernelBlobTypeKernel,
   KernelBlobTypeInitrd,
-  KernelBlobTypeCommandLine,
   KernelBlobTypeMax
 } KERNEL_BLOB_TYPE;
 
@@ -45,7 +44,6 @@ typedef struct {
 STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] = {
   { QemuFwCfgItemKernelSize,      QemuFwCfgItemKernelData,      L"kernel"  },
   { QemuFwCfgItemInitrdSize,      QemuFwCfgItemInitrdData,      L"initrd"  },
-  { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline" }
 };
 
 STATIC UINT64 mTotalBlobBytes;
@@ -865,7 +863,7 @@ FetchBlob (
   //
   // Read blob.
   //
-  Blob->Data = AllocatePool (Blob->Size);
+  Blob->Data = AllocatePages (EFI_SIZE_TO_PAGES (Blob->Size));
   if (Blob->Data == NULL) {
     DEBUG ((DEBUG_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n",
       __FUNCTION__, (INT64)Blob->Size, Blob->Name));
@@ -969,7 +967,7 @@ QemuKernelLoaderFsDxeEntrypoint (
   while (BlobType > 0) {
     CurrentBlob = &mKernelBlob[--BlobType];
     if (CurrentBlob->Data != NULL) {
-      FreePool (CurrentBlob->Data);
+      FreePages (CurrentBlob->Data, EFI_SIZE_TO_PAGES (CurrentBlob->Size));
       CurrentBlob->Size = 0;
       CurrentBlob->Data = NULL;
     }
-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55146): https://edk2.groups.io/g/devel/message/55146
Mute This Topic: https://groups.io/mt/71669020/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 07/13] OvmfPkg/QemuKernelLoaderFsDxe: don't expose kernel command line
Posted by Laszlo Ersek 5 years, 11 months ago
On 03/02/20 08:29, Ard Biesheuvel wrote:
> We have no need for exposing the kernel command line as a file,
> so remove support for that.

OK

> Since the remaining blobs (kernel
> and initrd) are typically much larger than a page, switch to
> the page based allocator for blobs at the same time.

Not sure why this matters, but I don't mind. However:

> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
> index efecbd817da1..b8d64e2781fc 100644
> --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
> +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c
> @@ -30,7 +30,6 @@
>  typedef enum {
>    KernelBlobTypeKernel,
>    KernelBlobTypeInitrd,
> -  KernelBlobTypeCommandLine,
>    KernelBlobTypeMax
>  } KERNEL_BLOB_TYPE;
>  
> @@ -45,7 +44,6 @@ typedef struct {
>  STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] = {
>    { QemuFwCfgItemKernelSize,      QemuFwCfgItemKernelData,      L"kernel"  },
>    { QemuFwCfgItemInitrdSize,      QemuFwCfgItemInitrdData,      L"initrd"  },
> -  { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline" }
>  };
>  
>  STATIC UINT64 mTotalBlobBytes;
> @@ -865,7 +863,7 @@ FetchBlob (
>    //
>    // Read blob.
>    //
> -  Blob->Data = AllocatePool (Blob->Size);
> +  Blob->Data = AllocatePages (EFI_SIZE_TO_PAGES (Blob->Size));

(1) EFI_SIZE_TO_PAGES expects a UINTN, but KERNEL_BLOB.Size is UINT32.
Please cast the argument.

>    if (Blob->Data == NULL) {
>      DEBUG ((DEBUG_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n",
>        __FUNCTION__, (INT64)Blob->Size, Blob->Name));
> @@ -969,7 +967,7 @@ QemuKernelLoaderFsDxeEntrypoint (
>    while (BlobType > 0) {
>      CurrentBlob = &mKernelBlob[--BlobType];
>      if (CurrentBlob->Data != NULL) {
> -      FreePool (CurrentBlob->Data);
> +      FreePages (CurrentBlob->Data, EFI_SIZE_TO_PAGES (CurrentBlob->Size));

(2) Same as (1).

>        CurrentBlob->Size = 0;
>        CurrentBlob->Data = NULL;
>      }
> 

With (1) and (2) fixed:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55223): https://edk2.groups.io/g/devel/message/55223
Mute This Topic: https://groups.io/mt/71669020/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-