public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
	Hao A Wu <hao.a.wu@intel.com>,
	Vitaly Cheptsov <vit9696@protonmail.com>
Subject: [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics
Date: Sun, 15 Aug 2021 20:11:56 +0000	[thread overview]
Message-ID: <b7940825f202b4bbabc844f7ab57f6260a118ad2.1629057819.git.mhaeuser@posteo.de> (raw)

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


             reply	other threads:[~2021-08-15 20:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-15 20:11 Marvin Häuser [this message]
2021-08-20  5:15 ` [edk2-devel] [PATCH 1/1] MdeModulePkg/EbcDxe: Mitigate memcpy intrinsics Wu, Hao A
2021-08-30  1:59   ` Wu, Hao A

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=b7940825f202b4bbabc844f7ab57f6260a118ad2.1629057819.git.mhaeuser@posteo.de \
    --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