https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112470

            Bug ID: 112470
           Summary: [AARCH64]stack-protector vulnerability fixing solution
                    impact code size and performance.
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dongjianqiang2 at huawei dot com
  Target Milestone: ---

Hi, after the CVE-2023-4039 patch is installed, the code size and performance
are affected after stack protection is enabled. 
Refer to https://godbolt.org/z/7dWeYd5Kb
After analyzing the patch, I think we can add the following modification
solution: For functions that need to dynamically apply for stackframe, we can
change the stack distribution of local variables, in other cases, the original
stack distribution will be retained.

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 800a8b0e110..342bab89281 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -8538,7 +8538,7 @@ aarch64_save_regs_above_locals_p ()
      it would be possible for a carefully sized smash attack to change
      the saved registers (particularly LR and FP) without reaching the
      canary.  */
-  return crtl->stack_protect_guard;
+  return crtl->stack_protect_guard && cfun->calls_alloca;
 }

 /* Mark the registers that need to be saved by the callee and calculate


Please let me know if you have any comments

Reply via email to