Skip to content

Commit 90f75e2

Browse files
avagingvisor-bot
authored andcommitted
systrap: seal stub mappings
mseal() protects the VMAs modifications. Sealled mappings can't be modified or over-mapped. PiperOrigin-RevId: 764834122
1 parent c175360 commit 90f75e2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/sentry/platform/systrap/stub_unsafe.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func stubInit() {
196196
stubSysmsgStart = mapLen
197197
stubSysmsgLen := len(sysmsg.SighandlerBlob)
198198
mapLen, _ = hostarch.PageRoundUp(mapLen + uintptr(stubSysmsgLen))
199+
stubExecMapEnd := mapLen
199200

200201
stubSysmsgRules = mapLen
201202
stubSysmsgRulesLen = hostarch.PageSize * 2
@@ -279,6 +280,7 @@ func stubInit() {
279280
stubSysmsgStart += stubStart
280281
stubSysmsgStack += stubStart
281282
stubROMapEnd += stubStart
283+
stubExecMapEnd += stubStart
282284
stubContextQueueRegion += stubStart
283285
stubSpinningThreadQueueAddr += stubStart
284286
stubContextRegion += stubStart
@@ -319,10 +321,24 @@ func stubInit() {
319321
if errno := hostsyscall.RawSyscallErrno(
320322
unix.SYS_MPROTECT,
321323
stubStart,
322-
stubROMapEnd-stubStart,
324+
stubExecMapEnd-stubStart,
323325
unix.PROT_EXEC|unix.PROT_READ); errno != 0 {
324326
panic("mprotect failed: " + errno.Error())
325327
}
328+
if errno := hostsyscall.RawSyscallErrno(
329+
unix.SYS_MPROTECT,
330+
stubExecMapEnd,
331+
stubROMapEnd-stubExecMapEnd,
332+
unix.PROT_READ); errno != 0 {
333+
panic("mprotect failed: " + errno.Error())
334+
}
335+
if errno := hostsyscall.RawSyscallErrno(
336+
unix.SYS_MSEAL,
337+
stubStart,
338+
stubROMapEnd-stubStart,
339+
0); errno != 0 && errno != unix.ENOSYS {
340+
panic("mseal failed: " + errno.Error())
341+
}
326342

327343
// Set the end.
328344
stubEnd = stubStart + mapLen + uintptr(gap)

0 commit comments

Comments
 (0)