Skip to content

Commit

Permalink
Add --allow-speculation option to disable IBPB/STIBP mitigation
Browse files Browse the repository at this point in the history
This flag disables IBPB/STIBP mitigation for container.
It is needed to improve the performance of bytecode interpreters
when users do not need IBPB/STIBP mitigation.

Signed-off-by: Kenta Tada <[email protected]>
  • Loading branch information
Kenta Tada authored and Kenta Tada committed May 27, 2020
1 parent a891fee commit 36d6f59
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions contrib/completions/bash/runc
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ _runc_run() {
--no-subreaper
--no-pivot
--no-new-keyring
--allow-speculation
"

local options_with_args="
Expand Down Expand Up @@ -563,6 +564,7 @@ _runc_create() {
--help
--no-pivot
--no-new-keyring
--allow-speculation
"

local options_with_args="
Expand Down
4 changes: 4 additions & 0 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
Name: "preserve-fds",
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
},
cli.BoolFlag{
Name: "allow-speculation",
Usage: "disable spectre mitigations",
},
},
Action: func(context *cli.Context) error {
if err := checkArgs(context, 1, exactArgs); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions libcontainer/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ type Config struct {
// This is a common option when the container is running in ramdisk
NoPivotRoot bool `json:"no_pivot_root"`

// AllowSpeculation will disable IBPB/STIBP mitigation.
AllowSpeculation bool `json:"allow_speculation"`

// ParentDeathSignal specifies the signal that is sent to the container's process in the case
// that the parent process dies.
ParentDeathSignal int `json:"parent_death_signal"`
Expand Down
1 change: 1 addition & 0 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type initConfig struct {
ProcessLabel string `json:"process_label"`
AppArmorProfile string `json:"apparmor_profile"`
NoNewPrivileges bool `json:"no_new_privileges"`
AllowSpeculation bool `json:"allow_speculation"`
User string `json:"user"`
AdditionalGroups []string `json:"additional_groups"`
Config *configs.Config `json:"config"`
Expand Down
18 changes: 10 additions & 8 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ type CreateOpts struct {
UseSystemdCgroup bool
NoPivotRoot bool
NoNewKeyring bool
AllowSpeculation bool
Spec *specs.Spec
RootlessEUID bool
RootlessCgroups bool
Expand Down Expand Up @@ -227,14 +228,15 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
labels = append(labels, fmt.Sprintf("%s=%s", k, v))
}
config := &configs.Config{
Rootfs: rootfsPath,
NoPivotRoot: opts.NoPivotRoot,
Readonlyfs: spec.Root.Readonly,
Hostname: spec.Hostname,
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
NoNewKeyring: opts.NoNewKeyring,
RootlessEUID: opts.RootlessEUID,
RootlessCgroups: opts.RootlessCgroups,
Rootfs: rootfsPath,
NoPivotRoot: opts.NoPivotRoot,
AllowSpeculation: opts.AllowSpeculation,
Readonlyfs: spec.Root.Readonly,
Hostname: spec.Hostname,
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
NoNewKeyring: opts.NoNewKeyring,
RootlessEUID: opts.RootlessEUID,
RootlessCgroups: opts.RootlessCgroups,
}

exists := false
Expand Down
5 changes: 5 additions & 0 deletions libcontainer/standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func (l *linuxStandardInit) Init() error {
return newSystemErrorWithCause(err, "init seccomp")
}
}
if l.config.Config.AllowSpeculation {
if err := unix.Prctl(unix.PR_SET_SPECULATION_CTRL, unix.PR_SPEC_INDIRECT_BRANCH, unix.PR_SPEC_ENABLE, 0, 0); err != nil {
return errors.Wrap(err, "disable IBPB/STIBP mitigation")
}
}
if err := unix.Exec(name, l.config.Args[0:], os.Environ()); err != nil {
return newSystemErrorWithCause(err, "exec user process")
}
Expand Down
1 change: 1 addition & 0 deletions man/runc-create.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ command(s) that get executed on start, edit the args parameter of the spec. See
--no-pivot do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk
--no-new-keyring do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key
--preserve-fds value Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total) (default: 0)
--allow-speculation disable spectre mitigations
1 change: 1 addition & 0 deletions man/runc-run.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ command(s) that get executed on start, edit the args parameter of the spec. See
--no-pivot do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk
--no-new-keyring do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key
--preserve-fds value Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total) (default: 0)
--allow-speculation disable spectre mitigations
4 changes: 4 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
Name: "preserve-fds",
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
},
cli.BoolFlag{
Name: "allow-speculation",
Usage: "disable spectre mitigations",
},
},
Action: func(context *cli.Context) error {
if err := checkArgs(context, 1, exactArgs); err != nil {
Expand Down
1 change: 1 addition & 0 deletions utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcont
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
NoPivotRoot: context.Bool("no-pivot"),
NoNewKeyring: context.Bool("no-new-keyring"),
AllowSpeculation: context.Bool("allow-speculation"),
Spec: spec,
RootlessEUID: os.Geteuid() != 0,
RootlessCgroups: rootlessCg,
Expand Down

0 comments on commit 36d6f59

Please sign in to comment.