fs/binfmt_elf: disallow e_phnum that equals zero
Subsystems (2)
PATCH 1/1 fs/binfmt_elf: disallow e_phnum that equals zero
The elf_ex.e_phnum field can be set to zero.
If elf_ex.e_phnum is set to zero, then a redundant kmalloc with the size zero is called and a following kfree. Check if elf_ex.e_phnum equals zero, and prevent the redundant kmalloc and kfree.
Signed-off-by Itay Ie <[email protected]>
--- fs/binfmt_elf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +3 -2
@@ -1348,7 +1348,8 @@ static int load_elf_library(struct file *file)/* First of all, some simple consistency checks */ if (elf_ex.e_type !=ET_EXEC || elf_ex.e_phnum >2 || - !elf_check_arch (&elf_ex) || !file->f_op->mmap) + elf_ex.e_phnum ==0 || !elf_check_arch (&elf_ex) || + !file->f_op->mmap) goto out;if (elf_check_fdpic (&elf_ex)) goto out;
@@ -1356,7 +1357,7 @@ static int load_elf_library(struct file *file)/* Now read in all of the header information */ j =sizeof (struct elf_phdr ) * elf_ex.e_phnum; -/* j < ELF_MIN_ALIGN because elf_ex.e_phnum <= 2 */ +/* j < ELF_MIN_ALIGN because elf_ex.e_phnum is 1 or 2 */ error = -ENOMEM ; elf_phdata =kmalloc (j,GFP_KERNEL );
--
2.32.0