]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
arm64 pmap: Fix a buffer overrun initializing per-superpage locks.
authorJohn Baldwin <jhb@FreeBSD.org>
Mon, 13 Feb 2023 21:19:03 +0000 (13:19 -0800)
committerJohn Baldwin <jhb@FreeBSD.org>
Mon, 13 Feb 2023 21:19:03 +0000 (13:19 -0800)
commit18bb97b76b269f38407b5c48d53ceaf6447450f1
treee1cd6574995ab765e517741c3c8d5f24d15fd627
parent3dfd18a769dfee663cd3d5e6eba05bfe8c1d0e2e
arm64 pmap: Fix a buffer overrun initializing per-superpage locks.

pmap_init_pv_table makes a first pass over the memory segments to
compute the amount of address space needed to allocate per-superpage
locks.  It then makes a second pass over each segment allocating
domain-local memory to back the pages for the locks belonging to each
segment.  This second pass rounds each segment's allocation up to a
page size since the domain-local allocation has to be a multiple of
pages.  However, the first pass was only doing a single round of the
total page counts up at the end not accounting for the padding present
in each segment.  To fix, apply the rounding in each segment in the
first pass instead of just at the end.

While here, tidy the second pass a bit by trimming some
not-quite-right logic copied from amd64.  In particular, compute pages
directly at the start of the loop iteration to more closely match the
first loop.  Then, drop an always-false condition as 'end' was
computed as 'start + pages' where 'start == highest + 1'.  Thus, the
actual condition being tested was 'if (highest >= highest + 1 +
pages)'.  Finally, remove 'highest' entirely by keep the result of the
'pvd' increment in the existing loop.

Reported by: CHERI (overflow)
Reviewed by: markj
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D38377
sys/arm64/arm64/pmap.c