Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Sep 2020 11:01:47 +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-12@freebsd.org
Subject:   svn commit: r365715 - stable/12/sys/kern
Message-ID:  <202009141101.08EB1lPh056585@repo.freebsd.org>

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

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

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

Modified: stable/12/sys/kern/imgact_elf.c
==============================================================================
--- stable/12/sys/kern/imgact_elf.c	Mon Sep 14 10:49:38 2020	(r365714)
+++ stable/12/sys/kern/imgact_elf.c	Mon Sep 14 11:01:46 2020	(r365715)
@@ -438,6 +438,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)
 {
@@ -803,8 +810,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;
 	}
@@ -1080,9 +1086,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?202009141101.08EB1lPh056585>