kvm: handle errors of applyVirtualRegions

PiperOrigin-RevId: 487845220
This commit is contained in:
Andrei Vagin
2022-11-11 09:38:41 -08:00
committed by gVisor bot
parent 8756ebc3b4
commit 4b63ff222d
3 changed files with 13 additions and 6 deletions
+4 -2
View File
@@ -445,7 +445,7 @@ func (c *vCPU) SwitchToUser(switchOpts ring0.SwitchOpts, info *linux.SignalInfo)
func (m *machine) mapUpperHalf(pageTable *pagetables.PageTables) {
// Map all the executable regions so that all the entry functions
// are mapped in the upper half.
applyVirtualRegions(func(vr virtualRegion) {
if err := applyVirtualRegions(func(vr virtualRegion) {
if excludeVirtualRegion(vr) || vr.filename == "[vsyscall]" {
return
}
@@ -462,7 +462,9 @@ func (m *machine) mapUpperHalf(pageTable *pagetables.PageTables) {
pagetables.MapOpts{AccessType: hostarch.Execute, Global: true},
physical)
}
})
}); err != nil {
panic(fmt.Sprintf("error parsing /proc/self/maps: %v", err))
}
for start, end := range m.kernel.EntryRegions() {
regionLen := end - start
physical, length, ok := translateToPhysical(start)
+5 -2
View File
@@ -18,6 +18,7 @@
package kvm
import (
"fmt"
"runtime"
"golang.org/x/sys/unix"
@@ -65,7 +66,7 @@ func (m *machine) mapUpperHalf(pageTable *pagetables.PageTables) {
// physical regions form them.
func archPhysicalRegions(physicalRegions []physicalRegion) []physicalRegion {
rdRegions := []virtualRegion{}
applyVirtualRegions(func(vr virtualRegion) {
if err := applyVirtualRegions(func(vr virtualRegion) {
if excludeVirtualRegion(vr) {
return // skip region.
}
@@ -74,7 +75,9 @@ func archPhysicalRegions(physicalRegions []physicalRegion) []physicalRegion {
if !vr.accessType.Write && vr.accessType.Read {
rdRegions = append(rdRegions, vr)
}
})
}); err != nil {
panic(fmt.Sprintf("error parsing /proc/self/maps: %v", err))
}
// Add an unreachable region.
rdRegions = append(rdRegions, virtualRegion{
+4 -2
View File
@@ -60,13 +60,15 @@ func fillAddressSpace() (excludedRegions []region) {
pSize -= reservedMemory
// Add specifically excluded regions; see excludeVirtualRegion.
applyVirtualRegions(func(vr virtualRegion) {
if err := applyVirtualRegions(func(vr virtualRegion) {
if excludeVirtualRegion(vr) {
excludedRegions = append(excludedRegions, vr.region)
vSize -= vr.length
log.Infof("excluded: virtual [%x,%x)", vr.virtual, vr.virtual+vr.length)
}
})
}); err != nil {
panic(fmt.Sprintf("error parsing /proc/self/maps: %v", err))
}
// Do we need any more work?
if vSize < pSize {