File tree Expand file tree Collapse file tree
pkg/sentry/platform/systrap/sysmsg Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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.
231239type ThreadContext struct {
232240 // FPState is a region of memory where:
233241 // - syshandler saves FPU state to using xsave/fxsave
You can’t perform that action at this time.
0 commit comments