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 , 14 years ago) |
---|
-
src/system/kernel/elf.cpp
1965 1965 size_t reservedSize; 1966 1966 status_t status; 1967 1967 ssize_t length; 1968 bool textSectionWritable = false; 1969 int executableHeaderCount = 0; 1968 1970 1969 1971 TRACE(("elf_load_kspace: entry path '%s'\n", path)); 1970 1972 … … 2066 2068 B_PAGE_SIZE); 2067 2069 if (end > reservedSize) 2068 2070 reservedSize = end; 2071 2072 if (programHeaders[i].IsExecutable()) 2073 executableHeaderCount ++; 2069 2074 } 2070 2075 2071 2076 // Check whether the segments have an unreasonable amount of unused space … … 2105 2110 } 2106 2111 2107 2112 // 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)) { 2109 2122 // this is the writable segment 2110 2123 if (image->data_region.size != 0) { 2111 2124 // we've already created this segment … … 2122 2135 } 2123 2136 region = &image->text_region; 2124 2137 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(); 2125 2141 snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName); 2126 2142 } else { 2127 2143 dprintf("%s: weird program header flags 0x%lx\n", fileName, … … 2191 2207 goto error5; 2192 2208 2193 2209 // 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. 2195 2213 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)); 2197 2216 2198 2217 // There might be a hole between the two segments, and we don't need to 2199 2218 // reserve this any longer -
headers/private/system/elf32.h
367 367 inline bool 368 368 Elf32_Phdr::IsExecutable() const 369 369 { 370 return (p_flags & PF_ PROTECTION_MASK) == (PF_READ | PF_EXECUTE);370 return (p_flags & PF_EXECUTE) != 0; 371 371 } 372 372 373 373