Skip to content

Commit 2998bca

Browse files
nixprimeshentubot
authored andcommitted
Inherit parent in clone(CLONE_THREAD) under TaskSet.mu.
PiperOrigin-RevId: 203849534
1 parent 728ba9f commit 2998bca

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pkg/sentry/kernel/task_clone.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,15 @@ func (t *Task) Clone(opts *CloneOptions) (ThreadID, *SyscallControl, error) {
220220
pidns = pidns.NewChild(userns)
221221
}
222222
tg := t.tg
223-
parent := t.parent
224223
if opts.NewThreadGroup {
225224
sh := t.tg.signalHandlers
226225
if opts.NewSignalHandlers {
227226
sh = sh.Fork()
228227
}
229228
tg = NewThreadGroup(pidns, sh, opts.TerminationSignal, tg.limits.GetCopy(), t.k.monotonicClock)
230-
parent = t
231229
}
232230
cfg := &TaskConfig{
233231
Kernel: t.k,
234-
Parent: parent,
235232
ThreadGroup: tg,
236233
TaskContext: tc,
237234
TaskResources: t.tr.Fork(!opts.NewFiles, !opts.NewFSContext),
@@ -242,6 +239,11 @@ func (t *Task) Clone(opts *CloneOptions) (ThreadID, *SyscallControl, error) {
242239
UTSNamespace: utsns,
243240
IPCNamespace: ipcns,
244241
}
242+
if opts.NewThreadGroup {
243+
cfg.Parent = t
244+
} else {
245+
cfg.InheritParent = t
246+
}
245247
if opts.NewNetworkNamespace {
246248
cfg.NetworkNamespaced = true
247249
}

pkg/sentry/kernel/task_start.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type TaskConfig struct {
3131
// Parent is the new task's parent. Parent may be nil.
3232
Parent *Task
3333

34+
// If InheritParent is not nil, use InheritParent's parent as the new
35+
// task's parent.
36+
InheritParent *Task
37+
3438
// ThreadGroup is the ThreadGroup the new task belongs to.
3539
*ThreadGroup
3640

@@ -133,6 +137,9 @@ func (ts *TaskSet) newTask(cfg *TaskConfig) (*Task, error) {
133137
// IDs).
134138
t.updateLogPrefixLocked()
135139

140+
if cfg.InheritParent != nil {
141+
t.parent = cfg.InheritParent.parent
142+
}
136143
if t.parent != nil {
137144
t.parent.children[t] = struct{}{}
138145
}

0 commit comments

Comments
 (0)