EmbeddedPkg: Fix Android Boot Command Line Length Bug

Curently, AndroidBootImgLib expects input kernel command line
to never exceed 256 unicode characters where the image header
allows for 512 ascii characters. If image header allows 512
ascii characters, similar number of unicode characters should be
allowed at the minimum.

Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
This commit is contained in:
Ashish Singhal 2023-11-29 20:44:13 -07:00 committed by mergify[bot]
parent 4f99b5fb93
commit c0207583e0
1 changed files with 18 additions and 13 deletions

View File

@ -322,11 +322,12 @@ AndroidBootImgGetFdt (
EFI_STATUS EFI_STATUS
AndroidBootImgUpdateArgs ( AndroidBootImgUpdateArgs (
IN VOID *BootImg, IN VOID *BootImg,
OUT VOID *KernelArgs OUT VOID **KernelArgs
) )
{ {
CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE]; CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
EFI_STATUS Status; EFI_STATUS Status;
UINT32 NewKernelArgSize;
// Get kernel arguments from Android boot image // Get kernel arguments from Android boot image
Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs); Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs);
@ -334,16 +335,23 @@ AndroidBootImgUpdateArgs (
return Status; return Status;
} }
NewKernelArgSize = ANDROID_BOOTIMG_KERNEL_ARGS_SIZE;
*KernelArgs = AllocateZeroPool (sizeof (CHAR16) * NewKernelArgSize);
if (*KernelArgs == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
return EFI_OUT_OF_RESOURCES;
}
AsciiStrToUnicodeStrS ( AsciiStrToUnicodeStrS (
ImageKernelArgs, ImageKernelArgs,
KernelArgs, *KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE >> 1 NewKernelArgSize
); );
// Append platform kernel arguments // Append platform kernel arguments
if (mAndroidBootImg->AppendArgs) { if (mAndroidBootImg->AppendArgs) {
Status = mAndroidBootImg->AppendArgs ( Status = mAndroidBootImg->AppendArgs (
KernelArgs, *KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE NewKernelArgSize
); );
} }
@ -616,6 +624,10 @@ AndroidBootImgBoot (
UINTN RamdiskSize; UINTN RamdiskSize;
IN VOID *FdtBase; IN VOID *FdtBase;
if ((Buffer == NULL) || (BufferSize == 0)) {
return EFI_INVALID_PARAMETER;
}
NewKernelArg = NULL; NewKernelArg = NULL;
ImageHandle = NULL; ImageHandle = NULL;
@ -637,14 +649,7 @@ AndroidBootImgBoot (
goto Exit; goto Exit;
} }
NewKernelArg = AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); Status = AndroidBootImgUpdateArgs (Buffer, &NewKernelArg);
if (NewKernelArg == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Status = AndroidBootImgUpdateArgs (Buffer, NewKernelArg);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Exit; goto Exit;
} }