Skip to content

Commit 05872f0

Browse files
konstantin-s-bogomgvisor-bot
authored andcommitted
Add helpful guiding messages to those who need to read them.
Explain some nuances about systrap in more detail. PiperOrigin-RevId: 900439001
1 parent bce271a commit 05872f0

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

pkg/sentry/platform/systrap/sysmsg/syshandler_amd64.S

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// This file contains the switch functionality of the systrap "syshandler" optimization.
16+
// It lets us avoid the signal frame setup overhead of the regular SIGSYS handler. These
17+
// switch routines save user state, and rely on having %gs point to this thread's sysmsg
18+
// state in order to have a region to actually save the state to.
19+
//
20+
// There are limitations to this optimization, and it can be disabled via the
21+
// systrap-disable-syscall-patching flag:
22+
// - If a user workload actually uses %gs and switches it (swapgs), this optimization will
23+
// not work. Note that this is not an issue for other subprocesses, because
24+
// gs overwrite will only affect the process doing it.
25+
// - If TF is set within RFLAGS (e.g. by debuggers), when the process enters
26+
// __export_syshandler TF will still remain set, and user regs RIP will be discarded.
27+
//
28+
// Despite these limitations the speed up is significant, so it's ON by default.
29+
1530
#include "sysmsg_offsets.h"
1631
#include "sysmsg_offsets_amd64.h"
1732

pkg/sentry/platform/systrap/sysmsg/sysmsg.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ const (
228228
// ThreadContext contains the current context of the sysmsg thread. The struct
229229
// facilitates switching contexts by allowing the sentry to switch pointers to
230230
// this struct as it needs to.
231+
//
232+
// N.B ThreadContexts are shared between all sysmsg threads within a subprocess,
233+
// and are necessarily writeable by any thread within the subprocess. If a
234+
// subprocess really wants to (i.e. sandbox break-out attempts) it can find
235+
// where the TC region is mapped and use other threads to manipulate this data
236+
// for a thread doing a context switch into the sentry.
237+
// This is OK because as a rule we do not trust this data; if any funny business
238+
// is going on the sentry simply kills the subprocess.
231239
type ThreadContext struct {
232240
// FPState is a region of memory where:
233241
// - syshandler saves FPU state to using xsave/fxsave

0 commit comments

Comments
 (0)