Ticket #6271: elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header-v4.patch

File elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header-v4.patch, 2.6 KB (added by lucian, 14 years ago)
  • src/system/kernel/elf.cpp

     
    19651965    size_t reservedSize;
    19661966    status_t status;
    19671967    ssize_t length;
     1968    bool textSectionWritable = false;
     1969    int executableHeaderCount = 0;
    19681970
    19691971    TRACE(("elf_load_kspace: entry path '%s'\n", path));
    19701972
     
    20662068            B_PAGE_SIZE);
    20672069        if (end > reservedSize)
    20682070            reservedSize = end;
     2071
     2072        if (programHeaders[i].IsExecutable())
     2073            executableHeaderCount ++;
    20692074    }
    20702075
    20712076    // Check whether the segments have an unreasonable amount of unused space
     
    21052110        }
    21062111
    21072112        // we're here, so it must be a PT_LOAD segment
    2108         if (programHeaders[i].IsReadWrite()) {
     2113
     2114        // Usually add-ons have two PT_LOAD headers: one for .data one or .text.
     2115        // x86 and PPC may differ in permission bits for .data's PT_LOAD header
     2116        // x86 is usually RW, PPC is RWE
     2117
     2118        // Some add-ons may have .text and .data concatenated in a single
     2119        // PT_LOAD RWE header and we must map that to .text.
     2120        if (programHeaders[i].IsReadWrite() &&
     2121            (!programHeaders[i].IsExecutable() || executableHeaderCount > 1)) {
    21092122            // this is the writable segment
    21102123            if (image->data_region.size != 0) {
    21112124                // we've already created this segment
     
    21222135            }
    21232136            region = &image->text_region;
    21242137
     2138            // some programs may have .text and .data concatenated in a
     2139            // single PT_LOAD section which is readable/writable/executable
     2140            textSectionWritable = programHeaders[i].IsReadWrite();
    21252141            snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName);
    21262142        } else {
    21272143            dprintf("%s: weird program header flags 0x%lx\n", fileName,
     
    21912207        goto error5;
    21922208
    21932209    // We needed to read in the contents of the "text" area, but
    2194     // now we can protect it read-only/execute
     2210    // now we can protect it read-only/execute, unless this is a
     2211    // special image with concatenated .text and .data, when it
     2212    // will also need write access.
    21952213    set_area_protection(image->text_region.id,
    2196         B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA);
     2214        B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA |
     2215        (textSectionWritable ? B_KERNEL_WRITE_AREA : 0));
    21972216
    21982217    // There might be a hole between the two segments, and we don't need to
    21992218    // reserve this any longer
  • headers/private/system/elf32.h

     
    367367inline bool
    368368Elf32_Phdr::IsExecutable() const
    369369{
    370     return (p_flags & PF_PROTECTION_MASK) == (PF_READ | PF_EXECUTE);
     370    return (p_flags & PF_EXECUTE) != 0;
    371371}
    372372
    373373