public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics
@ 2021-08-15 20:11 Marvin Häuser
  2021-08-20  5:15 ` [edk2-devel] " Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: Marvin Häuser @ 2021-08-15 20:11 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Vitaly Cheptsov

Assignments of structure values cause the emission of memcpy()
intrinsics by the CLANG38 toolchain. Substitute the assignments with
calls to CopyMem() to mitigate the issue.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
---
 MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c              | 6 +++++-
 MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c | 6 +++++-
 MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c          | 6 +++++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
index 611b2de5d81f..e417f4870f3d 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
@@ -219,7 +219,11 @@ EdbCheckBreakpoint (
       //
       // If hit, record current breakpoint
       //
-      DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];
+      CopyMem (
+        &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],
+        &DebuggerPrivate->DebuggerBreakpointContext[Index],
+        sizeof (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])
+        );
       DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;
       //
       // Do not set Breakpoint flag. We record the address here just let it not patch breakpoint address when de-init.
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
index e0c797be247f..5d32c684066e 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
@@ -158,7 +158,11 @@ DebuggerBreakpointDel (
   // Delete this breakpoint
   //
   for (BpIndex = Index; BpIndex < DebuggerPrivate->DebuggerBreakpointCount - 1; BpIndex++) {
-    DebuggerPrivate->DebuggerBreakpointContext[BpIndex] = DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1];
+    CopyMem (
+      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
+      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1],
+      sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])
+      );
   }
   ZeroMem (
     &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
index 83257a2c25fe..1bfe5240c760 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
@@ -230,7 +230,11 @@ EbcDebuggerPushTraceDestEntry (
     //
     ASSERT (mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_TRACE_MAX].Type == Type);
     for (Index = 0; Index < EFI_DEBUGGER_TRACE_MAX; Index++) {
-      mDebuggerPrivate.TraceEntry[Index] = mDebuggerPrivate.TraceEntry[Index + 1];
+      CopyMem (
+        &mDebuggerPrivate.TraceEntry[Index],
+        &mDebuggerPrivate.TraceEntry[Index + 1],
+        sizeof (mDebuggerPrivate.TraceEntry[Index])
+        );
     }
     mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_CALLSTACK_MAX - 1].DestAddress = DestEntry;
     mDebuggerPrivate.TraceEntryCount = EFI_DEBUGGER_TRACE_MAX;
-- 
2.31.1


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

* Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics
  2021-08-15 20:11 [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics Marvin Häuser
@ 2021-08-20  5:15 ` Wu, Hao A
  2021-08-30  1:59   ` Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: Wu, Hao A @ 2021-08-20  5:15 UTC (permalink / raw)
  To: devel@edk2.groups.io, mhaeuser@posteo.de; +Cc: Wang, Jian J, Vitaly Cheptsov

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Marvin
> H?user
> Sent: Monday, August 16, 2021 4:12 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Vitaly Cheptsov <vit9696@protonmail.com>
> Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate
> memcpy intrinsics
> 
> Assignments of structure values cause the emission of memcpy()
> intrinsics by the CLANG38 toolchain. Substitute the assignments with
> calls to CopyMem() to mitigate the issue.


Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Will merge after the upcoming stable tag.

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Vitaly Cheptsov <vit9696@protonmail.com>
> Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
> ---
>  MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c              | 6 +++++-
>  MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c | 6
> +++++-
>  MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c          | 6 +++++-
>  3 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> index 611b2de5d81f..e417f4870f3d 100644
> --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> @@ -219,7 +219,11 @@ EdbCheckBreakpoint (
>        //
> 
>        // If hit, record current breakpoint
> 
>        //
> 
> -      DebuggerPrivate-
> >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] =
> DebuggerPrivate->DebuggerBreakpointContext[Index];
> 
> +      CopyMem (
> 
> +        &DebuggerPrivate-
> >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],
> 
> +        &DebuggerPrivate->DebuggerBreakpointContext[Index],
> 
> +        sizeof (DebuggerPrivate-
> >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])
> 
> +        );
> 
>        DebuggerPrivate-
> >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State =
> TRUE;
> 
>        //
> 
>        // Do not set Breakpoint flag. We record the address here just let it not
> patch breakpoint address when de-init.
> 
> diff --git
> a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> index e0c797be247f..5d32c684066e 100644
> --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> +++
> b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> @@ -158,7 +158,11 @@ DebuggerBreakpointDel (
>    // Delete this breakpoint
> 
>    //
> 
>    for (BpIndex = Index; BpIndex < DebuggerPrivate-
> >DebuggerBreakpointCount - 1; BpIndex++) {
> 
> -    DebuggerPrivate->DebuggerBreakpointContext[BpIndex] =
> DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1];
> 
> +    CopyMem (
> 
> +      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
> 
> +      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1],
> 
> +      sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])
> 
> +      );
> 
>    }
> 
>    ZeroMem (
> 
>      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
> 
> diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> index 83257a2c25fe..1bfe5240c760 100644
> --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> @@ -230,7 +230,11 @@ EbcDebuggerPushTraceDestEntry (
>      //
> 
>      ASSERT
> (mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_TRACE_MAX].Type == Type);
> 
>      for (Index = 0; Index < EFI_DEBUGGER_TRACE_MAX; Index++) {
> 
> -      mDebuggerPrivate.TraceEntry[Index] =
> mDebuggerPrivate.TraceEntry[Index + 1];
> 
> +      CopyMem (
> 
> +        &mDebuggerPrivate.TraceEntry[Index],
> 
> +        &mDebuggerPrivate.TraceEntry[Index + 1],
> 
> +        sizeof (mDebuggerPrivate.TraceEntry[Index])
> 
> +        );
> 
>      }
> 
>      mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_CALLSTACK_MAX -
> 1].DestAddress = DestEntry;
> 
>      mDebuggerPrivate.TraceEntryCount = EFI_DEBUGGER_TRACE_MAX;
> 
> --
> 2.31.1
> 
> 
> 
> 
> 


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

* Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics
  2021-08-20  5:15 ` [edk2-devel] " Wu, Hao A
@ 2021-08-30  1:59   ` Wu, Hao A
  0 siblings, 0 replies; 3+ messages in thread
From: Wu, Hao A @ 2021-08-30  1:59 UTC (permalink / raw)
  To: devel@edk2.groups.io, Wu, Hao A, mhaeuser@posteo.de
  Cc: Wang, Jian J, Vitaly Cheptsov

Pushed via:
PR - https://github.com/tianocore/edk2/pull/1928
Commit - https://github.com/tianocore/edk2/commit/b04453d36bd87735aadd29adbefce8d147f18a35

Best Regards,
Hao Wu

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
> A
> Sent: Friday, August 20, 2021 1:15 PM
> To: devel@edk2.groups.io; mhaeuser@posteo.de
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Vitaly Cheptsov
> <vit9696@protonmail.com>
> Subject: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate
> memcpy intrinsics
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> Marvin
> > H?user
> > Sent: Monday, August 16, 2021 4:12 AM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
> > <hao.a.wu@intel.com>; Vitaly Cheptsov <vit9696@protonmail.com>
> > Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate
> memcpy
> > intrinsics
> >
> > Assignments of structure values cause the emission of memcpy()
> > intrinsics by the CLANG38 toolchain. Substitute the assignments with
> > calls to CopyMem() to mitigate the issue.
> 
> 
> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Will merge after the
> upcoming stable tag.
> 
> Best Regards,
> Hao Wu
> 
> 
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Vitaly Cheptsov <vit9696@protonmail.com>
> > Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
> > ---
> >  MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c              | 6 +++++-
> >  MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c | 6
> > +++++-
> >  MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c          | 6
> +++++-
> >  3 files changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> > b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> > index 611b2de5d81f..e417f4870f3d 100644
> > --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> > +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
> > @@ -219,7 +219,11 @@ EdbCheckBreakpoint (
> >        //
> >
> >        // If hit, record current breakpoint
> >
> >        //
> >
> > -      DebuggerPrivate-
> > >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] =
> > DebuggerPrivate->DebuggerBreakpointContext[Index];
> >
> > +      CopyMem (
> >
> > +        &DebuggerPrivate-
> > >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],
> >
> > +        &DebuggerPrivate->DebuggerBreakpointContext[Index],
> >
> > +        sizeof (DebuggerPrivate-
> > >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])
> >
> > +        );
> >
> >        DebuggerPrivate-
> > >DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State
> =
> > TRUE;
> >
> >        //
> >
> >        // Do not set Breakpoint flag. We record the address here just
> > let it not patch breakpoint address when de-init.
> >
> > diff --git
> > a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> > b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> > index e0c797be247f..5d32c684066e 100644
> > ---
> a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> > +++
> > b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
> > @@ -158,7 +158,11 @@ DebuggerBreakpointDel (
> >    // Delete this breakpoint
> >
> >    //
> >
> >    for (BpIndex = Index; BpIndex < DebuggerPrivate-
> > >DebuggerBreakpointCount - 1; BpIndex++) {
> >
> > -    DebuggerPrivate->DebuggerBreakpointContext[BpIndex] =
> > DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1];
> >
> > +    CopyMem (
> >
> > +      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
> >
> > +      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1],
> >
> > +      sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])
> >
> > +      );
> >
> >    }
> >
> >    ZeroMem (
> >
> >      &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
> >
> > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> > b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> > index 83257a2c25fe..1bfe5240c760 100644
> > --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> > +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
> > @@ -230,7 +230,11 @@ EbcDebuggerPushTraceDestEntry (
> >      //
> >
> >      ASSERT
> > (mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_TRACE_MAX].Type ==
> Type);
> >
> >      for (Index = 0; Index < EFI_DEBUGGER_TRACE_MAX; Index++) {
> >
> > -      mDebuggerPrivate.TraceEntry[Index] =
> > mDebuggerPrivate.TraceEntry[Index + 1];
> >
> > +      CopyMem (
> >
> > +        &mDebuggerPrivate.TraceEntry[Index],
> >
> > +        &mDebuggerPrivate.TraceEntry[Index + 1],
> >
> > +        sizeof (mDebuggerPrivate.TraceEntry[Index])
> >
> > +        );
> >
> >      }
> >
> >      mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_CALLSTACK_MAX -
> > 1].DestAddress = DestEntry;
> >
> >      mDebuggerPrivate.TraceEntryCount = EFI_DEBUGGER_TRACE_MAX;
> >
> > --
> > 2.31.1
> >
> >
> >
> >
> >
> 
> 
> 
> 
> 


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

end of thread, other threads:[~2021-08-30  1:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-15 20:11 [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics Marvin Häuser
2021-08-20  5:15 ` [edk2-devel] " Wu, Hao A
2021-08-30  1:59   ` Wu, Hao A

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