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 , 14 years ago) |
---|
-
src/system/kernel/elf.cpp
1959 1959 size_t reservedSize; 1960 1960 status_t status; 1961 1961 ssize_t length; 1962 bool textSectionWrittable = false; 1962 1963 1963 1964 TRACE(("elf_load_kspace: entry path '%s'\n", path)); 1964 1965 … … 2099 2100 } 2100 2101 2101 2102 // 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()) { 2103 2117 // this is the writable segment 2104 2118 if (image->data_region.size != 0) { 2105 2119 // we've already created this segment … … 2108 2122 region = &image->data_region; 2109 2123 2110 2124 snprintf(regionName, B_OS_NAME_LENGTH, "%s_data", fileName); 2111 } else if (programHeaders[i].IsExecutable()) {2112 // this is the non-writable segment2113 if (image->text_region.size != 0) {2114 // we've already created this segment2115 continue;2116 }2117 region = &image->text_region;2118 2119 snprintf(regionName, B_OS_NAME_LENGTH, "%s_text", fileName);2120 2125 } else { 2121 2126 dprintf("%s: weird program header flags 0x%lx\n", fileName, 2122 2127 programHeaders[i].p_flags); … … 2185 2190 goto error5; 2186 2191 2187 2192 // 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. 2189 2196 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)); 2191 2199 2192 2200 // There might be a hole between the two segments, and we don't need to 2193 2201 // 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