From 42a61acefa8b3288ff2163fb55e934a3fee39974 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 3 Dec 2023 21:15:11 +0000 Subject: [PATCH] Collect .openbsd.syscalls sections into a new PT_OPENBSD_SYSCALLS segment. This will be used soon to pin system calls to designated call sites. ok deraadt@ --- gnu/llvm/lld/ELF/ScriptParser.cpp | 1 + gnu/llvm/lld/ELF/Writer.cpp | 5 +++++ gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h | 1 + gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp | 3 +++ gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp | 1 + 5 files changed, 11 insertions(+) diff --git a/gnu/llvm/lld/ELF/ScriptParser.cpp b/gnu/llvm/lld/ELF/ScriptParser.cpp index 7e706f16382..5ec932dc59d 100644 --- a/gnu/llvm/lld/ELF/ScriptParser.cpp +++ b/gnu/llvm/lld/ELF/ScriptParser.cpp @@ -1577,6 +1577,7 @@ unsigned ScriptParser::readPhdrType() { .Case("PT_GNU_RELRO", PT_GNU_RELRO) .Case("PT_OPENBSD_MUTABLE", PT_OPENBSD_MUTABLE) .Case("PT_OPENBSD_RANDOMIZE", PT_OPENBSD_RANDOMIZE) + .Case("PT_OPENBSD_SYSCALLS", PT_OPENBSD_SYSCALLS) .Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED) .Case("PT_OPENBSD_BOOTDATA", PT_OPENBSD_BOOTDATA) .Default(-1); diff --git a/gnu/llvm/lld/ELF/Writer.cpp b/gnu/llvm/lld/ELF/Writer.cpp index 76aea25913d..3bba1b62db4 100644 --- a/gnu/llvm/lld/ELF/Writer.cpp +++ b/gnu/llvm/lld/ELF/Writer.cpp @@ -2388,6 +2388,11 @@ SmallVector Writer::createPhdrs(Partition &part) { if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo)) addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd); + // PT_OPENBSD_SYSCALLS is an OpenBSD-specific feature. That makes + // the kernel and dynamic linker register system call sites. + if (OutputSection *cmd = findSection(".openbsd.syscalls", partNo)) + addHdr(PT_OPENBSD_SYSCALLS, cmd->getPhdrFlags())->add(cmd); + if (config->zGnustack != GnuStackKind::None) { // PT_GNU_STACK is a special section to tell the loader to make the // pages for the stack non-executable. If you really want an executable diff --git a/gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h b/gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h index fe04d898ae5..b1f4aa4b735 100644 --- a/gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h +++ b/gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h @@ -1405,6 +1405,7 @@ enum { PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data. PT_OPENBSD_WXNEEDED = 0x65a3dbe7, // Program does W^X violations. PT_OPENBSD_NOBTCFI = 0x65a3dbe8, // Do not enforce branch target CFI + PT_OPENBSD_SYSCALLS = 0x65a3dbe9, // System call sites. PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments. // ARM program header types. diff --git a/gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp b/gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp index a07e29874f9..f710ae499d6 100644 --- a/gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp +++ b/gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp @@ -259,6 +259,9 @@ static void printProgramHeaders(const ELFFile &Obj, StringRef FileName) { case ELF::PT_OPENBSD_RANDOMIZE: outs() << "OPENBSD_RANDOMIZE "; break; + case ELF::PT_OPENBSD_SYSCALLS: + outs() << "OPENBSD_SYSCALLS "; + break; case ELF::PT_OPENBSD_WXNEEDED: outs() << "OPENBSD_WXNEEDED "; break; diff --git a/gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp b/gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp index 1fc0583750d..af0f9d6f055 100644 --- a/gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1411,6 +1411,7 @@ static StringRef segmentTypeToString(unsigned Arch, unsigned Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_MUTABLE); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE); + LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_SYSCALLS); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_NOBTCFI); LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA); -- 2.20.1