public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Siyuan, Fu" <siyuan.fu@intel.com>
To: "michael.kubacki@outlook.com" <michael.kubacki@outlook.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>,
	"Wu, Jiaxin" <jiaxin.wu@intel.com>
Subject: Re: [PATCH v1 1/1] NetworkPkg/Ip6Dxe: Validate source data record length
Date: Thu, 9 Apr 2020 08:22:10 +0000	[thread overview]
Message-ID: <B1FF2E9001CE9041BD10B825821D5BC58B9F13A6@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <MWHPR07MB344068867E35502F08FDFCA6E9C00@MWHPR07MB3440.namprd07.prod.outlook.com>

Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>

> -----Original Message-----
> From: michael.kubacki@outlook.com <michael.kubacki@outlook.com>
> Sent: 2020年4月8日 13:47
> To: devel@edk2.groups.io
> Cc: Fu, Siyuan <siyuan.fu@intel.com>; Maciej Rabeda
> <maciej.rabeda@linux.intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [PATCH v1 1/1] NetworkPkg/Ip6Dxe: Validate source data record
> length
> 
> From: Michael Kubacki <michael.kubacki@microsoft.com>
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2273
> 
> Ip6ConfigReadConfigData() reads configuration data from a UEFI variable
> and copies the data to another buffer. This change checks that the length
> of the data record being copied does not exceed the size of the source
> UEFI variable data buffer.
> 
> If the size is exceeded, this change follows existing logic to treat the
> variable as corrupted and deletes the variable so it will be set again.
> 
> Cc: Siyuan Fu <siyuan.fu@intel.com>
> Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
> ---
>  NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c | 47 +++++++++++++-------
>  1 file changed, 30 insertions(+), 17 deletions(-)
> 
> diff --git a/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
> b/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
> index eb2a80b64f15..ab3801336912 100644
> --- a/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
> +++ b/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
> @@ -2,6 +2,7 @@
>    The implementation of EFI IPv6 Configuration Protocol.
> 
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) Microsoft Corporation.<BR>
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -390,24 +391,9 @@ Ip6ConfigReadConfigData (
>                      );
>      if (EFI_ERROR (Status) || (UINT16) (~NetblockChecksum ((UINT8 *)
> Variable, (UINT32) VarSize)) != 0) {
>        //
> -      // GetVariable still error or the variable is corrupted.
> -      // Fall back to the default value.
> +      // GetVariable error or the variable is corrupted.
>        //
> -      FreePool (Variable);
> -
> -      //
> -      // Remove the problematic variable and return EFI_NOT_FOUND, a new
> -      // variable will be set again.
> -      //
> -      gRT->SetVariable (
> -             VarName,
> -             &gEfiIp6ConfigProtocolGuid,
> -             IP6_CONFIG_VARIABLE_ATTRIBUTE,
> -             0,
> -             NULL
> -             );
> -
> -      return EFI_NOT_FOUND;
> +      goto Error;
>      }
> 
>      //
> @@ -432,7 +418,12 @@ Ip6ConfigReadConfigData (
>        if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {
>          //
>          // This data item has variable length data.
> +        // Check that the length is contained within the variable before
> allocating.
>          //
> +        if (DataRecord.DataSize > VarSize - DataRecord.Offset) {
> +          goto Error;
> +        }
> +
>          DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);
>          if (DataItem->Data.Ptr == NULL) {
>            //
> @@ -454,6 +445,28 @@ Ip6ConfigReadConfigData (
>    }
> 
>    return Status;
> +
> +Error:
> +  //
> +  // Fall back to the default value.
> +  //
> +  if (Variable != NULL) {
> +    FreePool (Variable);
> +  }
> +
> +  //
> +  // Remove the problematic variable and return EFI_NOT_FOUND, a new
> +  // variable will be set again.
> +  //
> +  gRT->SetVariable (
> +         VarName,
> +         &gEfiIp6ConfigProtocolGuid,
> +         IP6_CONFIG_VARIABLE_ATTRIBUTE,
> +         0,
> +         NULL
> +         );
> +
> +  return EFI_NOT_FOUND;
>  }
> 
>  /**
> --
> 2.16.3.windows.1


  reply	other threads:[~2020-04-09  8:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08  5:46 [PATCH v1 1/1] NetworkPkg/Ip6Dxe: Validate source data record length Michael Kubacki
2020-04-09  8:22 ` Siyuan, Fu [this message]
2020-04-17 15:44   ` [edk2-devel] " Maciej Rabeda

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=B1FF2E9001CE9041BD10B825821D5BC58B9F13A6@SHSMSX103.ccr.corp.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