[ELF][AArch64] Fix potentially corrupted section content for PAC
authorFangrui Song <i@maskray.me>
Sat, 6 Aug 2022 01:24:53 +0000 (18:24 -0700)
committerTom Stellard <tstellar@redhat.com>
Mon, 8 Aug 2022 19:53:26 +0000 (12:53 -0700)
D74537 introduced a bug: if `(config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_PAC) != 0`
with -z pac-plt unspecified, we incorrectly use AArch64BtiPac, whose writePlt will make
out-of-bounds write after the .plt section. This is often benign because the
output section after .plt will usually overwrite the content.

This is very difficult to test without D131247 (Parallelize writes of different OutputSections).

(cherry picked from commit d7cbfcf36ace575ec90434624279dd3ebce78c47)

lld/ELF/Arch/AArch64.cpp

index 1949169d6447be155fce40b9d96563d708ee6001..b23684819a23967127a1cf2e3f5fea57d9733731 100644 (file)
@@ -873,8 +873,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
 }
 
 static TargetInfo *getTargetInfo() {
-  if (config->andFeatures & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI |
-                             GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
+  if ((config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ||
+      config->zPacPlt) {
     static AArch64BtiPac t;
     return &t;
   }