public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Paulo Alcantara <pcacjr@zytor.com>
To: Laszlo Ersek <lersek@redhat.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 08:46:01 -0300	[thread overview]
Message-ID: <17fde1d5-c9ec-2a42-87a0-136cdef90861@zytor.com> (raw)
In-Reply-To: <8ca69ac9-4f5a-3aa9-f150-844b0aeeb898@redhat.com>



On 08/09/2017 05:35, Laszlo Ersek wrote:
> 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.

You're right. Thanks for the explanation.

> 
> 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;

I'll include this in v6.

Paulo


      reply	other threads:[~2017-09-08 11:45 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
2017-09-08 11:46     ` Paulo Alcantara [this message]

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=17fde1d5-c9ec-2a42-87a0-136cdef90861@zytor.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