git: fc6c898ec5f4 - stable/13 - Fix divide-by-zero panic when ASLR is enabled and superpages disabled

Jason A. Harmening jah at FreeBSD.org
Wed Feb 24 00:00:10 UTC 2021


The branch stable/13 has been updated by jah:

URL: https://cgit.FreeBSD.org/src/commit/?id=fc6c898ec5f46c730b8f2902c2692549de47d7d6

commit fc6c898ec5f46c730b8f2902c2692549de47d7d6
Author:     Jason A. Harmening <jah at FreeBSD.org>
AuthorDate: 2021-02-15 02:47:22 +0000
Commit:     Jason A. Harmening <jah at FreeBSD.org>
CommitDate: 2021-02-24 00:01:30 +0000

    Fix divide-by-zero panic when ASLR is enabled and superpages disabled
    
    When locating the anonymous memory region for a vm_map with ASLR
    enabled, we try to keep the slid base address aligned on a superpage
    boundary to minimize pagetable fragmentation and maximize the potential
    usage of superpage mappings.  We can't (portably) do this if superpages
    have been disabled by loader tunable and pagesizes[1] is 0, and it
    would be less beneficial in that case anyway.
    
    PR:             253511
    
    (cherry picked from commit 41032835dc2d489ec7841d7529f74f6389329cd3)
---
 sys/kern/imgact_elf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index dae11ab92a6c..245894926ee1 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1287,7 +1287,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 		maxv1 = maxv / 2 + addr / 2;
 		MPASS(maxv1 >= addr);	/* No overflow */
 		map->anon_loc = __CONCAT(rnd_, __elfN(base))(map, addr, maxv1,
-		    MAXPAGESIZES > 1 ? pagesizes[1] : pagesizes[0]);
+		    (MAXPAGESIZES > 1 && pagesizes[1] != 0) ?
+		    pagesizes[1] : pagesizes[0]);
 	} else {
 		map->anon_loc = addr;
 	}
@@ -1297,7 +1298,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
 	if (interp != NULL) {
 		VOP_UNLOCK(imgp->vp);
 		if ((map->flags & MAP_ASLR) != 0) {
-			/* Assume that interpeter fits into 1/4 of AS */
+			/* Assume that interpreter fits into 1/4 of AS */
 			maxv1 = maxv / 2 + addr / 2;
 			MPASS(maxv1 >= addr);	/* No overflow */
 			addr = __CONCAT(rnd_, __elfN(base))(map, addr,


More information about the dev-commits-src-all mailing list