In order to add Control-flow Enforcement Technology (CET) Shadow Stack (SHSTK) support, we need to parse the `PT_GNU_PROPERTY` program header and the corresponding section to evaluate if the binary being started was compiled with the necessary support. PS: This is my first PR to llvm-libc, I might have made obvious styling mistakes so I'd appreciate any feedback or suggestions to improve it. I have a prototype branch using this change to enable SHSTK support: https://github.com/jakos-sec/llvm-project/tree/add-shstk-support
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
//===-- Header file of gnu_property_section -------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef LLVM_LIBC_STARTUP_LINUX_GNU_PROPERTY_SECTION_H
|
|
#define LLVM_LIBC_STARTUP_LINUX_GNU_PROPERTY_SECTION_H
|
|
|
|
#include "hdr/elf_proxy.h"
|
|
#include "hdr/link_macros.h"
|
|
#include "src/__support/macros/attributes.h"
|
|
#include "src/__support/macros/config.h"
|
|
|
|
namespace LIBC_NAMESPACE_DECL {
|
|
|
|
struct GnuPropertyFeatures {
|
|
// Set if the binary was compiled with SHSTK enabled and declares support.
|
|
bool shstk_supported = false;
|
|
};
|
|
|
|
// This class parses the .note.gnu.property section within the ELF binary.
|
|
// Currently it only extracts the bit representing SHSTK support but can easily
|
|
// be expanded to other features included in it.
|
|
// The layout of the .note.gnu.property section and the program property is
|
|
// described in "System V Application Binary Interface - Linux Extensions"
|
|
// (https://github.com/hjl-tools/linux-abi/wiki).
|
|
class GnuPropertySection {
|
|
private:
|
|
[[maybe_unused]] GnuPropertyFeatures features_;
|
|
|
|
public:
|
|
LIBC_INLINE GnuPropertySection() = default;
|
|
|
|
bool parse(const ElfW(Phdr) * gnu_property_phdr, const ElfW(Addr) base);
|
|
|
|
LIBC_INLINE bool is_shstk_supported() const {
|
|
return features_.shstk_supported;
|
|
}
|
|
};
|
|
|
|
} // namespace LIBC_NAMESPACE_DECL
|
|
|
|
#endif // LLVM_LIBC_STARTUP_LINUX_GNU_PROPERTY_SECTION_H
|