git: 0ce7909cd0ba - main - vm_phys: add essential segment bounds check

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Wed, 19 Jan 2022 06:46:46 UTC
The branch main has been updated by dougm:

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

commit 0ce7909cd0ba35148bddd8309534cb96e9e20f48
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2022-01-19 06:42:39 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2022-01-19 06:42:39 +0000

    vm_phys: add essential segment bounds check
    
    A lower-bound segment check is necessary in vm_phys_alloc_seg_contig.
    Add one.
    
    Reported by:    jenkins
    Reviewed by:    alc
    Fixes:  da92ecbc0d8f vm_phys: fix seg->end test in alloc_seg_contig
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D33945
---
 sys/vm/vm_phys.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c
index a880b7abd324..7ca3f5fbc0c5 100644
--- a/sys/vm/vm_phys.c
+++ b/sys/vm/vm_phys.c
@@ -1451,7 +1451,8 @@ vm_phys_alloc_seg_contig(struct vm_phys_seg *seg, u_long npages,
 				 * (without overflow in pa_end calculation)
 				 * and fits within the segment.
 				 */
-				if (pa_end < pa || pa_end > seg->end)
+				if (pa_end < pa ||
+				    pa < seg->start || seg->end < pa_end)
 					continue;
 
 				/*