const ElfW(NhdrGNUProperty)* GnuPropertySection::FindSegment(const ElfW(Phdr)* phdr,
size_t phdr_count, const ElfW(Addr) load_bias, constchar* name) const { // According to Linux gABI extension this segment should contain // .note.gnu.property section only. if (phdr != nullptr) { for (size_t i = 0; i < phdr_count; ++i) { if (phdr[i].p_type != PT_GNU_PROPERTY) { continue;
}
LD_DEBUG(props, "\"%s\" PT_GNU_PROPERTY: found at segment index %zu", name, i);
// Check segment size. if (phdr[i].p_memsz < sizeof(ElfW(NhdrGNUProperty))) {
DL_ERR_AND_LOG( "\"%s\" PT_GNU_PROPERTY segment is too small. Segment " "size is %zu, minimum is %zu.",
name, static_cast<size_t>(phdr[i].p_memsz), sizeof(ElfW(NhdrGNUProperty))); return nullptr;
}
// PT_GNU_PROPERTY contains .note.gnu.property which has SHF_ALLOC // attribute, therefore it is loaded. auto note_nhdr = reinterpret_cast<ElfW(NhdrGNUProperty)*>(load_bias + phdr[i].p_vaddr);
// Check that the n_descsz <= p_memsz if ((phdr[i].p_memsz - sizeof(ElfW(NhdrGNUProperty))) < note_nhdr->nhdr.n_descsz) {
DL_ERR_AND_LOG( "\"%s\" PT_GNU_PROPERTY segment p_memsz (%zu) is too small for note n_descsz (%zu).",
name, static_cast<size_t>(phdr[i].p_memsz), static_cast<size_t>(note_nhdr->nhdr.n_descsz)); return nullptr;
}
return note_nhdr;
}
}
LD_DEBUG(props, "\"%s\" PT_GNU_PROPERTY: not found", name); return nullptr;
}
bool GnuPropertySection::Parse(const ElfW(NhdrGNUProperty)* note_nhdr, constchar* name) { // The total length of the program property array is in _bytes_.
ElfW(Word) offset = 0; while (offset < note_nhdr->nhdr.n_descsz) {
LD_DEBUG(props, "\"%s\" .note.gnu.property: processing at offset 0x%x", name, offset);
// At least the "header" part must fit. // The ABI doesn't say that pr_datasz can't be 0. if ((note_nhdr->nhdr.n_descsz - offset) < sizeof(ElfW(Prop))) {
DL_ERR_AND_LOG( "\"%s\" .note.gnu.property: no more space left for a " "Program Property Note header.",
name); returnfalse;
}
// Loop on program property array. const ElfW(Prop)* property = reinterpret_cast<const ElfW(Prop)*>(¬e_nhdr->n_desc[offset]); const ElfW(Word) property_size =
__builtin_align_up(sizeof(ElfW(Prop)) + property->pr_datasz, sizeof(ElfW(Addr))); if ((note_nhdr->nhdr.n_descsz - offset) < property_size) {
DL_ERR_AND_LOG( "\"%s\" .note.gnu.property: property descriptor size is " "invalid. Expected at least %u bytes, got %u.",
name, property_size, note_nhdr->nhdr.n_descsz - offset); returnfalse;
}
// Cache found properties. switch (property->pr_type) { #ifdefined(__aarch64__) case GNU_PROPERTY_AARCH64_FEATURE_1_AND: { if (property->pr_datasz != 4) {
DL_ERR_AND_LOG( "\"%s\" .note.gnu.property: property descriptor size is " "invalid. Expected %u bytes for GNU_PROPERTY_AARCH64_FEATURE_1_AND, got %u.",
name, 4, property->pr_datasz); returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.