public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/Partition: Fix media probe
@ 2018-01-25  9:44 Ruiyu Ni
  2018-01-25 10:48 ` Wang, Jian J
  0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2018-01-25  9:44 UTC (permalink / raw)
  To: edk2-devel

The call in ProbeMediaStatusEx() to the ReadDisk() function of the
EFI_DISK_IO_PROTOCOL interface implemented in DiskIoDxe/DiskIo.c
crashed in DiskIo2ReadWriteDisk() because of the NULL value of
the destination buffer pointer.

Pass the address of a buffer in the stack instead of a NULL
pointer.

The similar fix was applied to ProbeMediaStatus in commit
df473cc1fc9acd1a623ec7e05276f2f0635c19d2
* MdeModulePkg/PartitionDxe: Fix media probe

Somehow ProbeMediaStatusEx() wasn't changed together.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
---
 MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
index bb9d0b70ce..46c0877cee 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
@@ -4,7 +4,7 @@
   of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy
   MBR, and GPT partition schemes are supported.
 
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -777,11 +777,15 @@ ProbeMediaStatusEx (
   )
 {
   EFI_STATUS                 Status;
+  UINT8                      Buffer[1];
 
   //
-  // Read 1 byte from offset 0 but passing NULL as buffer pointer
+  // Read 1 byte from offset 0 to check if the MediaId is still valid.
+  // The reading operation is synchronious thus it is not worth it to
+  // allocate a buffer from the pool. The destination buffer for the
+  // data is in the stack.
   //
-  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, NULL);
+  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, (VOID*)Buffer);
   if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
     return Status;
   }
-- 
2.15.1.windows.2



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

* Re: [PATCH] MdeModulePkg/Partition: Fix media probe
  2018-01-25  9:44 [PATCH] MdeModulePkg/Partition: Fix media probe Ruiyu Ni
@ 2018-01-25 10:48 ` Wang, Jian J
  0 siblings, 0 replies; 2+ messages in thread
From: Wang, Jian J @ 2018-01-25 10:48 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org

Tested-by/Reviewed-by: Jian J Wang <jian.j.wang@intel.com>

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Thursday, January 25, 2018 5:45 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J <jian.j.wang@intel.com>
> Subject: [PATCH] MdeModulePkg/Partition: Fix media probe
> 
> The call in ProbeMediaStatusEx() to the ReadDisk() function of the
> EFI_DISK_IO_PROTOCOL interface implemented in DiskIoDxe/DiskIo.c
> crashed in DiskIo2ReadWriteDisk() because of the NULL value of
> the destination buffer pointer.
> 
> Pass the address of a buffer in the stack instead of a NULL
> pointer.
> 
> The similar fix was applied to ProbeMediaStatus in commit
> df473cc1fc9acd1a623ec7e05276f2f0635c19d2
> * MdeModulePkg/PartitionDxe: Fix media probe
> 
> Somehow ProbeMediaStatusEx() wasn't changed together.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> ---
>  MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
> b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
> index bb9d0b70ce..46c0877cee 100644
> --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
> +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
> @@ -4,7 +4,7 @@
>    of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy
>    MBR, and GPT partition schemes are supported.
> 
> -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions of the BSD
> License
>  which accompanies this distribution.  The full text of the license may be found
> at
> @@ -777,11 +777,15 @@ ProbeMediaStatusEx (
>    )
>  {
>    EFI_STATUS                 Status;
> +  UINT8                      Buffer[1];
> 
>    //
> -  // Read 1 byte from offset 0 but passing NULL as buffer pointer
> +  // Read 1 byte from offset 0 to check if the MediaId is still valid.
> +  // The reading operation is synchronious thus it is not worth it to
> +  // allocate a buffer from the pool. The destination buffer for the
> +  // data is in the stack.
>    //
> -  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, NULL);
> +  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, (VOID*)Buffer);
>    if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
>      return Status;
>    }
> --
> 2.15.1.windows.2



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

end of thread, other threads:[~2018-01-25 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-25  9:44 [PATCH] MdeModulePkg/Partition: Fix media probe Ruiyu Ni
2018-01-25 10:48 ` Wang, Jian J

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