Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

platform: allow to expand COW-break on executable VMAs. #10298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/sentry/mm/pma.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ func (mm *MemoryManager) getVecPMAsLocked(ctx context.Context, ars hostarch.Addr
return ars, nil
}

func (mm *MemoryManager) expandCOWBreakOnExec() bool {
if mm.as == nil {
return false
}
return mm.as.ExpandCOWBreakOnExec()
}

// getPMAsInternalLocked is equivalent to getPMAsLocked, with the following
// exceptions:
//
Expand Down Expand Up @@ -333,7 +340,7 @@ func (mm *MemoryManager) getPMAsInternalLocked(ctx context.Context, vseg vmaIter
}
}
var copyAR hostarch.AddrRange
if vma := vseg.ValuePtr(); vma.effectivePerms.Execute {
if vma := vseg.ValuePtr(); vma.effectivePerms.Execute && !mm.expandCOWBreakOnExec() {
// The majority of copy-on-write breaks on executable
// pages come from:
//
Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/platform/kvm/address_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,6 @@ func (as *addressSpace) PreFork() {}

// PostFork implements platform.AddressSpace.PostFork.
func (as *addressSpace) PostFork() {}

// ExpandCOWBreakOnExec implements platform.AddressSpace.ExpandCOWBreakOnExec.
func (as *addressSpace) ExpandCOWBreakOnExec() bool { return false }
6 changes: 6 additions & 0 deletions pkg/sentry/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ type AddressSpace interface {
// Platform.SupportsAddressSpaceIO() == true. AddressSpaces for which this
// does not hold may panic if AddressSpaceIO methods are invoked.
AddressSpaceIO

// ExpandCOWBreakOnExec returns true if MemoryManager needs to treat
// executable VMA-s like regular ones. It can be useful if a platform
// needs to modify executable vma-s. Look at
// MemoryManager.getPMAInternalMappingsLocked for more details.
ExpandCOWBreakOnExec() bool
}

// AddressSpaceIO supports IO through the memory mappings installed in an
Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/platform/ptrace/subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ func (s *subprocess) Unmap(addr hostarch.Addr, length uint64) {
}
}

// ExpandCOWBreakOnExec implements platform.AddressSpace.ExpandCOWBreakOnExec
func (s *subprocess) ExpandCOWBreakOnExec() bool { return false }

// PreFork implements platform.AddressSpace.PreFork.
func (s *subprocess) PreFork() {}

Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/platform/systrap/subprocess_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func (s *subprocess) resetSysemuRegs(regs *arch.Registers) {
regs.Gs = s.sysmsgInitRegs.Gs
}

// ExpandCOWBreakOnExec implements platform.AddressSpace.ExpandCOWBreakOnExec.
func (s *subprocess) ExpandCOWBreakOnExec() bool { return true }

// createSyscallRegs sets up syscall registers.
//
// This should be called to generate registers for a system call.
Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/platform/systrap/subprocess_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
func (s *subprocess) resetSysemuRegs(regs *arch.Registers) {
}

// ExpandCOWBreakOnExec implements platform.AddressSpace.ExpandCOWBreakOnExec.
func (s *subprocess) ExpandCOWBreakOnExec() bool { return false }

// createSyscallRegs sets up syscall registers.
//
// This should be called to generate registers for a system call.
Expand Down
Loading