Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Sep 2020 11:03:18 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r365717 - stable/11/sys/kern
Message-ID:  <202009141103.08EB3III057519@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Sep 14 11:03:18 2020
New Revision: 365717
URL: https://svnweb.freebsd.org/changeset/base/365717

Log:
  MFC r365433:
  imgact_elf.c: unify check for phdr fitting into the first page.

Modified:
  stable/11/sys/kern/imgact_elf.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/imgact_elf.c
==============================================================================
--- stable/11/sys/kern/imgact_elf.c	Mon Sep 14 11:02:41 2020	(r365716)
+++ stable/11/sys/kern/imgact_elf.c	Mon Sep 14 11:03:18 2020	(r365717)
@@ -389,6 +389,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)
 {
@@ -728,8 +735,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;
 	}
@@ -809,9 +815,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?202009141103.08EB3III057519>