this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bug fix in libelfloader

+18 -4
+18 -4
src/libelfloader/loader.c
··· 292 292 uintptr_t off = phdr->p_offset - ELF_PAGEOFFSET(phdr->p_vaddr); 293 293 294 294 addr = ELF_PAGESTART(addr); 295 - size = ELF_PAGEALIGN(size); 295 + // size = ELF_PAGEALIGN(size); 296 296 297 297 if (phdr->p_flags & PF_X) 298 298 prot |= PROT_EXEC; ··· 301 301 if (phdr->p_flags & PF_R) 302 302 prot |= PROT_READ; 303 303 304 - if (phdr->p_flags & PF_W) 304 + //if (phdr->p_flags & PF_W) 305 305 flags |= MAP_PRIVATE; 306 - else 307 - flags |= MAP_SHARED; 306 + //else 307 + // flags |= MAP_SHARED; 308 + 309 + bool needszeroing = size != ELF_PAGEALIGN(size); 308 310 311 + if (needszeroing) 312 + prot |= PROT_WRITE; 309 313 if (mprotect((void*) (addr), memsize, prot) == -1) 310 314 { 311 315 perror("mprotect"); ··· 316 320 { 317 321 perror("mmap"); 318 322 goto out; 323 + } 324 + 325 + // Based on experiments, when we provide a size that is less than a multiple of page size 326 + // mmap() will map up to the whole page of file data anyway. Many ELF files, including ld.so, 327 + // however rely on the rest of the page being zeroed out. 328 + if (needszeroing) 329 + { 330 + memset((void*)(addr + size), 0, ELF_PAGEALIGN(size) - size); 331 + if (!(phdr->p_flags & PF_W)) 332 + mprotect((void*) (addr), memsize, prot & ~PROT_WRITE); 319 333 } 320 334 321 335 /*