public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Hao A" <hao.a.wu@intel.com>
To: "Zeng, Star" <star.zeng@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Gao, Liming" <liming.gao@intel.com>,
	"Wang, Jian J" <jian.j.wang@intel.com>
Subject: Re: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer
Date: Wed, 7 Aug 2019 00:07:14 +0000	[thread overview]
Message-ID: <B80AF82E9BFB8E4FBD8C89DA810C6A093C916BA6@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483104038E284@shsmsx102.ccr.corp.intel.com>

> -----Original Message-----
> From: Zeng, Star
> Sent: Tuesday, August 06, 2019 10:56 PM
> To: devel@edk2.groups.io; Wu, Hao A
> Cc: Gao, Liming; Wang, Jian J; Zeng, Star
> Subject: RE: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe:
> Not copy SMM pointers in comm buffer
> 
> The DstInfoEntry is better to have identifer [out] instead of [in]?


Yes, good point.
I will update it and send out the V2 patch.

Best Regards,
Hao Wu


> 
> Thanks,
> Star
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Wu,
> > Hao A
> > Sent: Tuesday, August 6, 2019 3:19 PM
> > To: devel@edk2.groups.io
> > Cc: Wu, Hao A <hao.a.wu@intel.com>; Gao, Liming
> <liming.gao@intel.com>;
> > Wang, Jian J <jian.j.wang@intel.com>
> > Subject: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe:
> Not
> > copy SMM pointers in comm buffer
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2002
> >
> > This commit will update the logic in function SmmVariableGetStatistics() so
> > that the pointer fields ('Next' and 'Name') in structure
> > VARIABLE_INFO_ENTRY will not be copied into the SMM communication
> > buffer.
> >
> > Doing so will prevent SMM pointers address from being leaked into non-
> > SMM environment.
> >
> > Please note that newly introduced internal function CopyVarInfoEntry() will
> > not use CopyMem() to copy the whole VARIABLE_INFO_ENTRY structure
> and
> > then zero out the 'Next' and 'Name' fields. This is for preventing race
> > conditions where the pointers value might still be read.
> >
> > Cc: Liming Gao <liming.gao@intel.com>
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Signed-off-by: Hao A Wu <hao.a.wu@intel.com>
> > ---
> >  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 33
> > ++++++++++++++++++--
> >  1 file changed, 31 insertions(+), 2 deletions(-)
> >
> > diff --git
> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
> > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
> > index ec463d063e..81a9c9e849 100644
> > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
> > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
> > @@ -312,6 +312,35 @@ GetFvbCountAndBuffer (
> >
> >
> >  /**
> > +  Copy only the meaningful fields of the variable statistics
> > + information from  source buffer to the destination buffer. Other fields
> are
> > filled with zero.
> > +
> > +  @param[in]  DstInfoEntry    A pointer to the buffer of destination
> variable
> > +                              information entry.
> > +  @param[in]  SrcInfoEntry    A pointer to the buffer of source variable
> > +                              information entry.
> > +
> > +**/
> > +static
> > +VOID
> > +CopyVarInfoEntry (
> > +  IN VARIABLE_INFO_ENTRY    *DstInfoEntry,
> > +  IN VARIABLE_INFO_ENTRY    *SrcInfoEntry
> > +  )
> > +{
> > +  DstInfoEntry->Next = NULL;
> > +  DstInfoEntry->Name = NULL;
> > +
> > +  CopyGuid (&DstInfoEntry->VendorGuid, &SrcInfoEntry->VendorGuid);
> > +  DstInfoEntry->Attributes  = SrcInfoEntry->Attributes;
> > +  DstInfoEntry->ReadCount   = SrcInfoEntry->ReadCount;
> > +  DstInfoEntry->WriteCount  = SrcInfoEntry->WriteCount;
> > +  DstInfoEntry->DeleteCount = SrcInfoEntry->DeleteCount;
> > +  DstInfoEntry->CacheCount  = SrcInfoEntry->CacheCount;
> > +  DstInfoEntry->Volatile    = SrcInfoEntry->Volatile;
> > +}
> > +
> > +/**
> >    Get the variable statistics information from the information buffer
> pointed
> > by gVariableInfo.
> >
> >    Caution: This function may be invoked at SMM runtime.
> > @@ -373,7 +402,7 @@ SmmVariableGetStatistics (
> >        *InfoSize = StatisticsInfoSize;
> >        return EFI_BUFFER_TOO_SMALL;
> >      }
> > -    CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));
> > +    CopyVarInfoEntry (InfoEntry, VariableInfo);
> >      CopyMem (InfoName, VariableInfo->Name, NameSize);
> >      *InfoSize = StatisticsInfoSize;
> >      return EFI_SUCCESS;
> > @@ -413,7 +442,7 @@ SmmVariableGetStatistics (
> >      return EFI_BUFFER_TOO_SMALL;
> >    }
> >
> > -  CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));
> > +  CopyVarInfoEntry (InfoEntry, VariableInfo);
> >    CopyMem (InfoName, VariableInfo->Name, NameSize);
> >    *InfoSize = StatisticsInfoSize;
> >
> > --
> > 2.12.0.windows.1
> >
> >
> > 


      reply	other threads:[~2019-08-07  0:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06  7:18 [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer Wu, Hao A
2019-08-06 14:55 ` [edk2-devel] " Zeng, Star
2019-08-07  0:07   ` Wu, Hao A [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=B80AF82E9BFB8E4FBD8C89DA810C6A093C916BA6@SHSMSX104.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