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

File elf-support-for-images-with-a-single-rwx-PT_LOAD-pro.patch, 2.6 KB (added by lucian, 14 years ago)

[fixed] elf support for images with a single rwx PT_LOAD program header

  • src/system/kernel/elf.cpp

     
    19591959    size_t reservedSize;
    19601960    status_t status;
    19611961    ssize_t length;
     1962    bool textSectionWrittable = false;
    19621963
    19631964    TRACE(("elf_load_kspace: entry path '%s'\n", path));
    19641965
     
    20992100        }
    21002101
    21012102        // we're here, so it must be a PT_LOAD segment
    2102         if (programHeaders[i].IsReadWrite()) {
     2103        if (programHeaders[i].IsExecutable()) {
     2104            // this is the non-writable segment
     2105            if (image->text_region.size != 0) {
     2106                // we've already created this segment
     2107                continue;
     2108            }
     2109            region = &image->text_region;
     2110
     2111            // some programs may have .text and .data concatenated in a
     2112            // single PT_LOAD section which is readable/writtable/executable
     2113            textSectionWrittable = programHeaders[i].IsReadWrite();
     2114
     2115            snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName);
     2116        } else if (programHeaders[i].IsReadWrite()) {
    21032117            // this is the writable segment
    21042118            if (image->data_region.size != 0) {
    21052119                // we've already created this segment
     
    21082122            region = &image->data_region;
    21092123
    21102124            snprintf(regionName, B_OS_NAME_LENGTH, "%s_data", fileName);
    2111         } else if (programHeaders[i].IsExecutable()) {
    2112             // this is the non-writable segment
    2113             if (image->text_region.size != 0) {
    2114                 // we've already created this segment
    2115                 continue;
    2116             }
    2117             region = &image->text_region;
    2118 
    2119             snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName);
    21202125        } else {
    21212126            dprintf("%s: weird program header flags 0x%lx\n", fileName,
    21222127                programHeaders[i].p_flags);
     
    21852190        goto error5;
    21862191
    21872192    // We needed to read in the contents of the "text" area, but
    2188     // now we can protect it read-only/execute
     2193    // now we can protect it read-only/execute, unless this is a
     2194    // special image with concatenated .text and .data, when it
     2195    // will also nead write access.
    21892196    set_area_protection(image->text_region.id,
    2190         B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA);
     2197        B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA |
     2198        (textSectionWrittable ? B_KERNEL_WRITE_AREA : 0));
    21912199
    21922200    // There might be a hole between the two segments, and we don't need to
    21932201    // 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;
    371371}
    372372
    373373