public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zeng, Star" <star.zeng@intel.com>
To: Ruiyu Ni <ruiyu.ni@intel.com>, edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Jiewen Yao <jiewen.yao@intel.com>,
	star.zeng@intel.com
Subject: Re: [PATCH 11/11] MdeModulePkg/Bus/Ufs: Ensure device not return more data than expected
Date: Tue, 16 Oct 2018 13:27:33 +0800	[thread overview]
Message-ID: <dd97aaaf-3458-1beb-e36d-161e63cac544@intel.com> (raw)
In-Reply-To: <20181015063833.61304-12-ruiyu.ni@intel.com>

On 2018/10/15 14:38, Ruiyu Ni wrote:
> From: Hao Wu <hao.a.wu@intel.com>
> 
> This commit adds checks to make sure the UFS devices do not return more
> data than the driver expected.
> 
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>

Thanks for the patch.
Reviewed-by: Star Zeng <star.zeng@intel.com>

Star

> ---
>   MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c        | 19 ++++++++++++--
>   .../Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c        | 30 +++++++++++++++++++---
>   2 files changed, 43 insertions(+), 6 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
> index 936f25da5e..9b87835ed8 100644
> --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
> +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
> @@ -857,6 +857,14 @@ UfsRwDeviceDesc (
>       SwapLittleEndianToBigEndian ((UINT8*)&ReturnDataSize, sizeof (UINT16));
>   
>       if (Read) {
> +      //
> +      // Make sure the hardware device does not return more data than expected.
> +      //
> +      if (ReturnDataSize > Packet.InTransferLength) {
> +        Status = EFI_DEVICE_ERROR;
> +        goto Exit;
> +      }
> +
>         CopyMem (Packet.InDataBuffer, (QueryResp + 1), ReturnDataSize);
>         Packet.InTransferLength = ReturnDataSize;
>       } else {
> @@ -1170,8 +1178,15 @@ UfsExecScsiCmds (
>     SwapLittleEndianToBigEndian ((UINT8*)&SenseDataLen, sizeof (UINT16));
>   
>     if ((Packet->SenseDataLength != 0) && (Packet->SenseData != NULL)) {
> -    CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> -    Packet->SenseDataLength = (UINT8)SenseDataLen;
> +    //
> +    // Make sure the hardware device does not return more data than expected.
> +    //
> +    if (SenseDataLen <= Packet->SenseDataLength) {
> +      CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> +      Packet->SenseDataLength = (UINT8)SenseDataLen;
> +    } else {
> +      Packet->SenseDataLength = 0;
> +    }
>     }
>   
>     //
> diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
> index 5756f637fd..0238264878 100644
> --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
> +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
> @@ -833,6 +833,7 @@ UfsStopExecCmd (
>     @param[in] QueryResp  Pointer to the query response.
>   
>     @retval EFI_INVALID_PARAMETER Packet or QueryResp are empty or opcode is invalid.
> +  @retval EFI_DEVICE_ERROR      Data returned from device is invalid.
>     @retval EFI_SUCCESS           Data extracted.
>   
>   **/
> @@ -853,6 +854,13 @@ UfsGetReturnDataFromQueryResponse (
>       case UtpQueryFuncOpcodeRdDesc:
>         ReturnDataSize = QueryResp->Tsf.Length;
>         SwapLittleEndianToBigEndian ((UINT8*)&ReturnDataSize, sizeof (UINT16));
> +      //
> +      // Make sure the hardware device does not return more data than expected.
> +      //
> +      if (ReturnDataSize > Packet->TransferLength) {
> +        return EFI_DEVICE_ERROR;
> +      }
> +
>         CopyMem (Packet->DataBuffer, (QueryResp + 1), ReturnDataSize);
>         Packet->TransferLength = ReturnDataSize;
>         break;
> @@ -1469,8 +1477,15 @@ UfsExecScsiCmds (
>     SwapLittleEndianToBigEndian ((UINT8*)&SenseDataLen, sizeof (UINT16));
>   
>     if ((Packet->SenseDataLength != 0) && (Packet->SenseData != NULL)) {
> -    CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> -    Packet->SenseDataLength = (UINT8)SenseDataLen;
> +    //
> +    // Make sure the hardware device does not return more data than expected.
> +    //
> +    if (SenseDataLen <= Packet->SenseDataLength) {
> +      CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> +      Packet->SenseDataLength = (UINT8)SenseDataLen;
> +    } else {
> +      Packet->SenseDataLength = 0;
> +    }
>     }
>   
>     //
> @@ -2226,8 +2241,15 @@ ProcessAsyncTaskList (
>           SwapLittleEndianToBigEndian ((UINT8*)&SenseDataLen, sizeof (UINT16));
>   
>           if ((Packet->SenseDataLength != 0) && (Packet->SenseData != NULL)) {
> -          CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> -          Packet->SenseDataLength = (UINT8)SenseDataLen;
> +          //
> +          // Make sure the hardware device does not return more data than expected.
> +          //
> +          if (SenseDataLen <= Packet->SenseDataLength) {
> +            CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
> +            Packet->SenseDataLength = (UINT8)SenseDataLen;
> +          } else {
> +            Packet->SenseDataLength = 0;
> +          }
>           }
>   
>           //
> 



      reply	other threads:[~2018-10-16  5:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15  6:38 [PATCH 00/11] Need to validate data from HW Ruiyu Ni
2018-10-15  6:38 ` [PATCH 01/11] MdeModulePkg/UsbMass: Merge UsbBoot(Read|Write)Blocks(16) Ruiyu Ni
2018-10-16  3:06   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 02/11] MdeModulePkg/UsbMass: Fix integer overflow when BlockSize is 1 Ruiyu Ni
2018-10-16  3:19   ` Zeng, Star
2018-10-16  3:32     ` Ni, Ruiyu
2018-10-15  6:38 ` [PATCH 03/11] MdeModulePkg/UsbBus: Fix out-of-bound read access to descriptors Ruiyu Ni
2018-10-16  3:38   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 04/11] MdeModulePkg/UsbBus: Reject descriptor whose length is bad Ruiyu Ni
2018-10-16  3:42   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 05/11] MdeModulePkg/Usb: Make sure data from HW is no more than expected Ruiyu Ni
2018-10-15 11:29   ` Wu, Hao A
2018-10-16  4:26   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 06/11] SourceLevelDebugPkg/Usb3: Make sure data from HW can fit in buffer Ruiyu Ni
2018-10-15 11:31   ` Wu, Hao A
2018-10-15  6:38 ` [PATCH 07/11] MdeModulePkg/UsbKb: Don't access key codes when length is wrong Ruiyu Ni
2018-10-16  4:52   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 08/11] MdeModulePkg/AbsPointer: " Ruiyu Ni
2018-10-16  5:01   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 09/11] MdeModulePkg/UsbMouse: " Ruiyu Ni
2018-10-16  5:03   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 10/11] MdeModulePkg/UsbBus: Deny when the string descriptor length is odd Ruiyu Ni
2018-10-16  5:11   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 11/11] MdeModulePkg/Bus/Ufs: Ensure device not return more data than expected Ruiyu Ni
2018-10-16  5:27   ` Zeng, Star [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=dd97aaaf-3458-1beb-e36d-161e63cac544@intel.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