Skip to content

Commit f98d200

Browse files
Kenta TadaKenta Tada
authored andcommitted
Add --allow-speculation option to disable IBPB/STIBP mitigation
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]>
1 parent 1f737ee commit f98d200

File tree

7 files changed

+28
-8
lines changed

7 files changed

+28
-8
lines changed

create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
5050
Name: "preserve-fds",
5151
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
5252
},
53+
cli.BoolFlag{
54+
Name: "allow-speculation",
55+
Usage: "disable spectre mitigations",
56+
},
5357
},
5458
Action: func(context *cli.Context) error {
5559
if err := checkArgs(context, 1, exactArgs); err != nil {

libcontainer/configs/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type Config struct {
8585
// This is a common option when the container is running in ramdisk
8686
NoPivotRoot bool `json:"no_pivot_root"`
8787

88+
// AllowSpeculation will disable IBPB/STIBP mitigation.
89+
AllowSpeculation bool `json:"allow_speculation"`
90+
8891
// ParentDeathSignal specifies the signal that is sent to the container's process in the case
8992
// that the parent process dies.
9093
ParentDeathSignal int `json:"parent_death_signal"`

libcontainer/init_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type initConfig struct {
5555
ProcessLabel string `json:"process_label"`
5656
AppArmorProfile string `json:"apparmor_profile"`
5757
NoNewPrivileges bool `json:"no_new_privileges"`
58+
AllowSpeculation bool `json:"allow_speculation"`
5859
User string `json:"user"`
5960
AdditionalGroups []string `json:"additional_groups"`
6061
Config *configs.Config `json:"config"`

libcontainer/specconv/spec_linux.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ type CreateOpts struct {
197197
UseSystemdCgroup bool
198198
NoPivotRoot bool
199199
NoNewKeyring bool
200+
AllowSpeculation bool
200201
Spec *specs.Spec
201202
RootlessEUID bool
202203
RootlessCgroups bool
@@ -227,14 +228,15 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
227228
labels = append(labels, fmt.Sprintf("%s=%s", k, v))
228229
}
229230
config := &configs.Config{
230-
Rootfs: rootfsPath,
231-
NoPivotRoot: opts.NoPivotRoot,
232-
Readonlyfs: spec.Root.Readonly,
233-
Hostname: spec.Hostname,
234-
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
235-
NoNewKeyring: opts.NoNewKeyring,
236-
RootlessEUID: opts.RootlessEUID,
237-
RootlessCgroups: opts.RootlessCgroups,
231+
Rootfs: rootfsPath,
232+
NoPivotRoot: opts.NoPivotRoot,
233+
AllowSpeculation: opts.AllowSpeculation,
234+
Readonlyfs: spec.Root.Readonly,
235+
Hostname: spec.Hostname,
236+
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
237+
NoNewKeyring: opts.NoNewKeyring,
238+
RootlessEUID: opts.RootlessEUID,
239+
RootlessCgroups: opts.RootlessCgroups,
238240
}
239241

240242
exists := false

libcontainer/standard_init_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func (l *linuxStandardInit) Init() error {
207207
return newSystemErrorWithCause(err, "init seccomp")
208208
}
209209
}
210+
if l.config.Config.AllowSpeculation {
211+
if err := unix.Prctl(unix.PR_SET_SPECULATION_CTRL, unix.PR_SPEC_INDIRECT_BRANCH, unix.PR_SPEC_ENABLE, 0, 0); err != nil {
212+
return errors.Wrap(err, "disable IBPB/STIBP mitigation")
213+
}
214+
}
210215
if err := unix.Exec(name, l.config.Args[0:], os.Environ()); err != nil {
211216
return newSystemErrorWithCause(err, "exec user process")
212217
}

run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
6161
Name: "preserve-fds",
6262
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
6363
},
64+
cli.BoolFlag{
65+
Name: "allow-speculation",
66+
Usage: "disable spectre mitigations",
67+
},
6468
},
6569
Action: func(context *cli.Context) error {
6670
if err := checkArgs(context, 1, exactArgs); err != nil {

utils_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcont
236236
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
237237
NoPivotRoot: context.Bool("no-pivot"),
238238
NoNewKeyring: context.Bool("no-new-keyring"),
239+
AllowSpeculation: context.Bool("allow-speculation"),
239240
Spec: spec,
240241
RootlessEUID: os.Geteuid() != 0,
241242
RootlessCgroups: rootlessCg,

0 commit comments

Comments
 (0)