Ticket #6271: 0003-elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header.patch
File 0003-elf-support-for-images-with-a-single-rwx-PT_LOAD-program-header.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 countExecutableHeaders = 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 countExecutableHeaders += programHeaders[i].IsExecutable(); 2069 2072 } 2070 2073 2071 2074 // Check whether the segments have an unreasonable amount of unused space … … 2105 2108 } 2106 2109 2107 2110 // we're here, so it must be a PT_LOAD segment 2108 if (programHeaders[i].IsReadWrite()) { 2111 2112 // Usually add-ons have two PT_LOAD headers: one for .data one or .text. 2113 // x86 and PPC may differ in permission bits for .data's PT_LOAD header 2114 // x86 is usually RW, PPC is RWE 2115 2116 // Some add-ons may have .text and .data concatenated in a single 2117 // PT_LOAD RWE header and we must map that to .text. 2118 if (programHeaders[i].IsReadWrite() && (countExecutableHeaders > 1)) { 2109 2119 // this is the writable segment 2110 2120 if (image->data_region.size != 0) { 2111 2121 // we've already created this segment … … 2122 2132 } 2123 2133 region = &image->text_region; 2124 2134 2135 // some programs may have .text and .data concatenated in a 2136 // single PT_LOAD section which is readable/writtable/executable 2137 textSectionWritable = programHeaders[i].IsReadWrite(); 2138 2125 2139 snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName); 2126 2140 } else { 2127 2141 dprintf("%s: weird program header flags 0x%lx\n", fileName, … … 2191 2205 goto error5; 2192 2206 2193 2207 // We needed to read in the contents of the "text" area, but 2194 // now we can protect it read-only/execute 2208 // now we can protect it read-only/execute, unless this is a 2209 // special image with concatenated .text and .data, when it 2210 // will also nead write access. 2195 2211 set_area_protection(image->text_region.id, 2196 B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA); 2212 B_KERNEL_READ_AREA | B_KERNEL_EXECUTE_AREA | 2213 (textSectionWritable ? B_KERNEL_WRITE_AREA : 0)); 2197 2214 2198 2215 // There might be a hole between the two segments, and we don't need to 2199 2216 // 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); 371 371 } 372 372 373 373