Bug 253511 - vm.pmap.pg_ps_enabled=0 and kern.elf64.aslr.enable=1 panics with integer divide by zero
Summary: vm.pmap.pg_ps_enabled=0 and kern.elf64.aslr.enable=1 panics with integer divi...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.2-STABLE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-14 16:32 UTC by jo
Modified: 2021-02-24 00:03 UTC (History)
1 user (show)

See Also:


Attachments
proposed patch (961 bytes, patch)
2021-02-15 03:05 UTC, Jason A. Harmening
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jo 2021-02-14 16:32:20 UTC
I was hacking away at other stuff and disabled pg_ps_enabled for testing, but left aslr enabled. On boot the machine panics with integer division by zero.
Happens when starting init.
In a function called something like rnd_elf64_imgact, or similar. It's gone too quickly to read, machine just reboots instantly.
Comment 1 Jason A. Harmening freebsd_committer freebsd_triage 2021-02-15 03:05:58 UTC
Created attachment 222451 [details]
proposed patch
Comment 2 jo 2021-02-15 17:55:54 UTC
thanks, that patch works for me!
(and i see how it fixes the problem by avoiding the zero-divide in rnd_elf64_base() in roundup())

btw, for me sysctl hw.pagesizes always comes up empty (prints nothing, except its description).
Comment 3 Jason A. Harmening freebsd_committer freebsd_triage 2021-02-15 18:24:45 UTC
(In reply to johannes from comment #2)

I think you might need this for `sysctl hw.pagesizes` to work:

https://cgit.freebsd.org/src/commit/sys/kern/kern_mib.c?id=a0efcf6400788d856b8b89dfff7ef63007896d90

the sysctl works for me on recent HEAD, but not 12-STABLE.
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-02-15 18:38:09 UTC
A commit in branch main references this bug:

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

commit 41032835dc2d489ec7841d7529f74f6389329cd3
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2021-02-15 02:47:22 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2021-02-15 18:38:04 +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
    Reported by:    johannes@jo-t.de
    MFC after:      1 week
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D28678

 sys/kern/imgact_elf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-02-24 00:00:14 UTC
A commit in branch stable/13 references this bug:

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

commit fc6c898ec5f46c730b8f2902c2692549de47d7d6
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2021-02-15 02:47:22 +0000
Commit:     Jason A. Harmening <jah@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(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2021-02-24 00:02:16 UTC
A commit in branch stable/12 references this bug:

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

commit 941747f63cfa127248e6c7246f75c5ac5e142fcc
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2021-02-15 02:47:22 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2021-02-24 00:04:00 +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(-)