Skip to content

Commit ebc0f65

Browse files
committed
runc exec: setupRlimits after syscall.rlimit.init() completed
Issue: opencontainers#4195 Since https://go-review.googlesource.com/c/go/+/476097, there is a get/set race between runc exec and syscall.rlimit.init, so we need to call setupRlimits after syscall.rlimit.init() completed. Signed-off-by: lifubang <[email protected]> (cherry picked from commit a853a82) Signed-off-by: lifubang <[email protected]>
1 parent 0c136fc commit ebc0f65

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

libcontainer/process_linux.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,22 @@ func (p *setnsProcess) start() (retErr error) {
152152
}
153153
}
154154
}
155-
// set rlimits, this has to be done here because we lose permissions
156-
// to raise the limits once we enter a user-namespace
157-
if err := setupRlimits(p.config.Rlimits, p.pid()); err != nil {
158-
return fmt.Errorf("error setting rlimits for process: %w", err)
159-
}
155+
160156
if err := utils.WriteJSON(p.messageSockPair.parent, p.config); err != nil {
161157
return fmt.Errorf("error writing config to pipe: %w", err)
162158
}
163159

164160
ierr := parseSync(p.messageSockPair.parent, func(sync *syncT) error {
165161
switch sync.Type {
166162
case procReady:
167-
// This shouldn't happen.
168-
panic("unexpected procReady in setns")
163+
// Set rlimits, this has to be done here because we lose permissions
164+
// to raise the limits once we enter a user-namespace
165+
if err := setupRlimits(p.config.Rlimits, p.pid()); err != nil {
166+
return fmt.Errorf("error setting rlimits for ready process: %w", err)
167+
}
168+
169+
// Sync with child.
170+
return writeSync(p.messageSockPair.parent, procRun)
169171
case procHooks:
170172
// This shouldn't happen.
171173
panic("unexpected procHooks in setns")
@@ -495,7 +497,7 @@ func (p *initProcess) start() (retErr error) {
495497
return err
496498
}
497499
case procReady:
498-
// set rlimits, this has to be done here because we lose permissions
500+
// Set rlimits, this has to be done here because we lose permissions
499501
// to raise the limits once we enter a user-namespace
500502
if err := setupRlimits(p.config.Rlimits, p.pid()); err != nil {
501503
return fmt.Errorf("error setting rlimits for ready process: %w", err)

libcontainer/setns_init_linux.go

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ func (l *linuxSetnsInit) Init() error {
6161
return err
6262
}
6363
}
64+
65+
// Tell our parent that we're ready to exec. This must be done before the
66+
// Seccomp rules have been applied, because we need to be able to read and
67+
// write to a socket.
68+
if err := syncParentReady(l.pipe); err != nil {
69+
return fmt.Errorf("sync ready: %w", err)
70+
}
71+
6472
if err := selinux.SetExecLabel(l.config.ProcessLabel); err != nil {
6573
return err
6674
}

0 commit comments

Comments
 (0)