Date: Mon, 7 Sep 2020 21:37:16 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365433 - head/sys/kern Message-ID: <202009072137.087LbGU5003736@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Mon Sep 7 21:37:16 2020 New Revision: 365433 URL: https://svnweb.freebsd.org/changeset/base/365433 Log: imgact_elf.c: unify check for phdr fitting into the first page. Similar to the userspace rtld check. Reviewed by: dim, emaste (previous versions) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D26339 Modified: head/sys/kern/imgact_elf.c Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Mon Sep 7 21:32:27 2020 (r365432) +++ head/sys/kern/imgact_elf.c Mon Sep 7 21:37:16 2020 (r365433) @@ -448,6 +448,13 @@ __elfN(get_brandinfo)(struct image_params *imgp, const return (NULL); } +static bool +__elfN(phdr_in_zero_page)(const Elf_Ehdr *hdr) +{ + return (hdr->e_phoff <= PAGE_SIZE && + (u_int)hdr->e_phentsize * hdr->e_phnum <= PAGE_SIZE - hdr->e_phoff); +} + static int __elfN(check_header)(const Elf_Ehdr *hdr) { @@ -811,8 +818,7 @@ __elfN(load_file)(struct proc *p, const char *file, u_ } /* Only support headers that fit within first page for now */ - if ((hdr->e_phoff > PAGE_SIZE) || - (u_int)hdr->e_phentsize * hdr->e_phnum > PAGE_SIZE - hdr->e_phoff) { + if (!__elfN(phdr_in_zero_page)(hdr)) { error = ENOEXEC; goto fail; } @@ -1088,9 +1094,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *i * detected an ELF file. */ - if ((hdr->e_phoff > PAGE_SIZE) || - (u_int)hdr->e_phentsize * hdr->e_phnum > PAGE_SIZE - hdr->e_phoff) { - /* Only support headers in first page for now */ + if (!__elfN(phdr_in_zero_page)(hdr)) { uprintf("Program headers not in the first page\n"); return (ENOEXEC); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009072137.087LbGU5003736>