public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Paulo Alcantara <pcacjr@zytor.com>, edk2-devel@lists.01.org
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Andrew Fish <afish@apple.com>,
	 Michael D Kinney <michael.d.kinney@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Star Zeng <star.zeng@intel.com>, Eric Dong <eric.dong@intel.com>,
	Mark Doran <mark.doran@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>,
	hao.a.wu@intel.com
Subject: Re: [PATCH v5 0/6] read-only UDF file system support
Date: Fri, 8 Sep 2017 10:35:50 +0200	[thread overview]
Message-ID: <8ca69ac9-4f5a-3aa9-f150-844b0aeeb898@redhat.com> (raw)
In-Reply-To: <a6503830-ab44-ae5c-7e44-1d26507f3627@zytor.com>

Paulo,

On 09/08/17 02:56, Paulo Alcantara wrote:
> Ray,
>
> On 07/09/2017 20:13, Paulo Alcantara wrote:
>> v5:
>>   - Fixed OVMF IA32 build.
>>   - Fixed a typo in UdfDriveBindingStop() ("This" -> "SimpleFs") which
>>     broke retrieval of private fs data from SimpleFs protocol --
>>     identified by 'reconnect -r' command in UEFI shell.
>
> Follow the diff between v4 and v5 for Mde*Pkg changes (forgot to include
> it when resending):
>
> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> index 8ad14fe594..2dbcff0be4 100644
> --- a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> @@ -372,7 +372,7 @@ UdfRead (
>        PrivFileData->FileSize,
>        &PrivFileData->FilePosition,
>        Buffer,
> -      BufferSize
> +      (UINT64 *)(UINTN)BufferSize^M
>        );

This change is not correct.

(1) The UdfRead() function takes the following parameter:

  IN OUT  UINTN              *BufferSize,

This means that, in an IA32 or ARM build,

  sizeof *BufferSize == 4

and in an AARCH64 or X64 build,

  sizeof *BufferSize == 8

(2) The above type-casting is part of a call to the ReadFileData()
function. The ReadFileData() function takes the following parameter:

  IN OUT  UINT64                 *BufferSize

This means that, regardless of architecture,

  sizeof *BufferSize == 8

The consequence is that, in an IA32 or ARM build, the ReadFileData()
function will both read and write beyond the end of the outermost
caller's "BufferSize" variable. The write is a problem without a doubt,
but the read is a problem too if the outermost caller's "BufferSize" (a
UINT32 object) is followed by four bytes that are not all zero. Then
ReadFileData() will attempt to read more than 4GB of data.

The right way to fix this is the following:

> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> index 2dbcff0be4a3..07c7ec207fcd 100644
> --- a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
> @@ -326,6 +326,7 @@ UdfRead (
>    VOID                            *NewFileEntryData;
>    CHAR16                          FileName[UDF_FILENAME_LENGTH] = { 0 };
>    UINT64                          FileSize;
> +  UINT64                          BufferSizeUint64;
>  
>    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
>  
> @@ -364,6 +365,7 @@ UdfRead (
>        goto Done;
>      }
>  
> +    BufferSizeUint64 = *BufferSize;
>      Status = ReadFileData (
>        BlockIo,
>        DiskIo,
> @@ -372,8 +374,10 @@ UdfRead (
>        PrivFileData->FileSize,
>        &PrivFileData->FilePosition,
>        Buffer,
> -      (UINT64 *)(UINTN)BufferSize
> +      &BufferSizeUint64
>        );
> +    ASSERT (BufferSizeUint64 <= MAX_UINTN);
> +    *BufferSize = (UINTN)BufferSizeUint64;
>    } else if (IS_FID_DIRECTORY_FILE (Parent->FileIdentifierDesc)) {
>      if (ReadDirInfo->FidOffset == 0 && PrivFileData->FilePosition > 0) {
>        Status = EFI_DEVICE_ERROR;

Thanks,
Laszlo

>    } else if (IS_FID_DIRECTORY_FILE (Parent->FileIdentifierDesc)) {
>      if (ReadDirInfo->FidOffset == 0 && PrivFileData->FilePosition > 0) {
> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
> b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
> index 9f10c78ca9..49dc7077b7 100644
> --- a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
> @@ -264,7 +264,7 @@ UdfDriverBindingStop (
>      EFI_OPEN_PROTOCOL_GET_PROTOCOL
>      );
>    if (!EFI_ERROR (Status)) {
> -    PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (This);
> +    PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (SimpleFs);^M
>
>      //
>      // Uninstall child handle
>
>
> Thanks,
> Paulo



  parent reply	other threads:[~2017-09-08  8:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-07 23:13 [PATCH v5 0/6] read-only UDF file system support Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 1/6] MdePkg: Add UDF volume structure definitions Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 2/6] MdeModulePkg/PartitionDxe: Add UDF file system support Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 3/6] MdeModulePkg: Initial UDF/ECMA-167 " Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 4/6] OvmfPkg: Enable UDF " Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 5/6] ArmVirtPkg: " Paulo Alcantara
2017-09-07 23:13 ` [PATCH v5 6/6] Nt32Pkg: " Paulo Alcantara
2017-09-08  2:24   ` Ni, Ruiyu
2017-09-08  0:56 ` [PATCH v5 0/6] read-only " Paulo Alcantara
2017-09-08  2:41   ` Ni, Ruiyu
2017-09-08  3:35     ` Paulo Alcantara
2017-09-08  6:25   ` Ni, Ruiyu
2017-09-08  8:35   ` Laszlo Ersek [this message]
2017-09-08 11:46     ` Paulo Alcantara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ca69ac9-4f5a-3aa9-f150-844b0aeeb898@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox