В ядре Linux устранена следующая уязвимость: cgroup: сериализация миграций вновь разветвленных процессов С включенными favordynmods миграция cgroup.procs принимает cgroup_threadgroup_rwsem целевой threadgroup для записи. Вилка процесса удерживает семафор группы потоков для чтения. Это разные семафоры, когда вилка создает новый процесс. copy_process() публикует детский PID до того, как cgroup_post_fork() связывает ребенка со своим css_set.
Писатель может найти ребенка в этом интервале, взять его несвернутый семафор и перенести его, в то время как child->cgroups по-прежнему указывает на init_css_set, а child->cg_list пуст. Миграция связывает узел с init_css_set.mg_tasks. cgroup_post_fork() затем добавляет тот же узел к предполагаемому css_set, как если бы он был не связан, повреждая как списки задач, так и их владение css_set. Это регрессирует форк/миграционная гонка, зафиксированная коммитом b12b533fa523 («группы: добавить блокировку для child->cgroups в cgroup_post_fork()») и восстановленная снова в 2012 году после того, как блокировка была удалена.
Старая защита task_lock была позже заменена глобальной блокировкой css_set и cgroup threadgroup. Изменение, идентифицированное тегом Fixes, сузило только сторону миграции до блокировки каждой группы, восстановив отказ исключения другого процесса. Возьмите семафор новой группы потоков для чтения до того, как ребенок станет видимым, и удерживайте его через cgroup_post_fork().
Используйте вложенный подкласс замка, потому что вилка уже содержит родительский семафор. Дети CLONE_THREAD разделяют родительский signal_struct и остаются покрытыми существующей блокировкой. Миграции несвязанных, полностью инициализированных групп потоков остаются одновременными.
Для определения и воспроизведения регрессии, а также для разработки и тестирования этого исправления использовался помощник по кодированию AI.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: cgroup: serialize migrations of newly forked processes With favordynmods enabled, a cgroup.procs migration takes the target threadgroup's cgroup_threadgroup_rwsem for writing. A process fork holds the forking threadgroup's semaphore for reading. These are different semaphores when fork creates a new process. copy_process() publishes the child's PID before cgroup_post_fork() links the child to its css_set. A writer can find the child in that interval, take its uncontended semaphore, and migrate it while child->cgroups still points to init_css_set and child->cg_list is empty. Migration links the node into init_css_set.mg_tasks. cgroup_post_fork() then adds the same node to the intended css_set as though it were unlinked, corrupting both task lists and their css_set ownership. This regresses the fork/migration race fixed by commit b12b533fa523 ("cgroups: add lock for child->cgroups in cgroup_post_fork()") and restored again in 2012 after the lock had been removed. The old task_lock protection was later superseded by global css_set and cgroup threadgroup locking. The change identified by the Fixes tag narrowed only the migration side back to a per-threadgroup lock, recreating the different-process exclusion failure. Take the new threadgroup's semaphore for reading before the child becomes visible and hold it through cgroup_post_fork(). Use a nested lock subclass because fork already holds the parent's semaphore. CLONE_THREAD children share the parent's signal_struct and remain covered by the existing lock. Migrations of unrelated, fully initialized threadgroups remain concurrent. An AI coding assistant was used to identify and reproduce the regression and to develop and test this fix.