Skip to content

Commit a2ad577

Browse files
nlacassegvisor-bot
authored andcommitted
Fix lock order inversion between taskMutex and kernfs.ancestryRWMutex.
Reported-by: [email protected] PiperOrigin-RevId: 776737878
1 parent ea79c92 commit a2ad577

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/sentry/kernel/task_cgroup.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,18 @@ type TaskCgroupEntry struct {
225225
// GetCgroupEntries generates the contents of /proc/<pid>/cgroup as
226226
// a TaskCgroupEntry array.
227227
func (t *Task) GetCgroupEntries() []TaskCgroupEntry {
228+
// Gather cgroups with t.mu held.
228229
t.mu.Lock()
229-
defer t.mu.Unlock()
230-
231-
cgEntries := make([]TaskCgroupEntry, 0, len(t.cgroups))
230+
cgroups := make([]Cgroup, 0, len(t.cgroups))
232231
for c := range t.cgroups {
232+
cgroups = append(cgroups, c)
233+
}
234+
t.mu.Unlock()
235+
236+
// Don't hold t.mu here as that can lead to lock inversion with
237+
// kernfs.ancestryRWMutex when calculating cgroup paths.
238+
cgEntries := make([]TaskCgroupEntry, 0, len(cgroups))
239+
for _, c := range cgroups {
233240
ctls := c.Controllers()
234241
ctlNames := make([]string, 0, len(ctls))
235242

0 commit comments

Comments
 (0)