@@ -110,19 +110,19 @@ static struct linux_binfmt elf_format = {
110
110
111
111
#define BAD_ADDR (x ) (unlikely((unsigned long)(x) >= TASK_SIZE))
112
112
113
- /* We need to explicitly zero any fractional pages
114
- after the data section (i.e. bss). This would
115
- contain the junk from the file that should not
116
- be in memory
113
+ /*
114
+ * We need to explicitly zero any trailing portion of the page that follows
115
+ * p_filesz when it ends before the page ends (e.g. bss), otherwise this
116
+ * memory will contain the junk from the file that should not be present.
117
117
*/
118
- static int padzero (unsigned long elf_bss )
118
+ static int padzero (unsigned long address )
119
119
{
120
120
unsigned long nbyte ;
121
121
122
- nbyte = ELF_PAGEOFFSET (elf_bss );
122
+ nbyte = ELF_PAGEOFFSET (address );
123
123
if (nbyte ) {
124
124
nbyte = ELF_MIN_ALIGN - nbyte ;
125
- if (clear_user ((void __user * ) elf_bss , nbyte ))
125
+ if (clear_user ((void __user * )address , nbyte ))
126
126
return - EFAULT ;
127
127
}
128
128
return 0 ;
@@ -348,6 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,
348
348
return 0 ;
349
349
}
350
350
351
+ /*
352
+ * Map "eppnt->p_filesz" bytes from "filep" offset "eppnt->p_offset"
353
+ * into memory at "addr". (Note that p_filesz is rounded up to the
354
+ * next page, so any extra bytes from the file must be wiped.)
355
+ */
351
356
static unsigned long elf_map (struct file * filep , unsigned long addr ,
352
357
const struct elf_phdr * eppnt , int prot , int type ,
353
358
unsigned long total_size )
@@ -387,6 +392,11 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
387
392
return (map_addr );
388
393
}
389
394
395
+ /*
396
+ * Map "eppnt->p_filesz" bytes from "filep" offset "eppnt->p_offset"
397
+ * into memory at "addr". Memory from "p_filesz" through "p_memsz"
398
+ * rounded up to the next page is zeroed.
399
+ */
390
400
static unsigned long elf_load (struct file * filep , unsigned long addr ,
391
401
const struct elf_phdr * eppnt , int prot , int type ,
392
402
unsigned long total_size )
@@ -404,8 +414,12 @@ static unsigned long elf_load(struct file *filep, unsigned long addr,
404
414
zero_end = map_addr + ELF_PAGEOFFSET (eppnt -> p_vaddr ) +
405
415
eppnt -> p_memsz ;
406
416
407
- /* Zero the end of the last mapped page */
408
- padzero (zero_start );
417
+ /*
418
+ * Zero the end of the last mapped page but ignore
419
+ * any errors if the segment isn't writable.
420
+ */
421
+ if (padzero (zero_start ) && (prot & PROT_WRITE ))
422
+ return - EFAULT ;
409
423
}
410
424
} else {
411
425
map_addr = zero_start = ELF_PAGESTART (addr );
0 commit comments