| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Process number limiting controller for cgroups. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 25 | 26 | * a superset of parent/child/pids.current. |
|---|
| 26 | 27 | * |
|---|
| 27 | 28 | * Copyright (C) 2015 Aleksa Sarai <cyphar@cyphar.com> |
|---|
| 28 | | - * |
|---|
| 29 | | - * This file is subject to the terms and conditions of version 2 of the GNU |
|---|
| 30 | | - * General Public License. See the file COPYING in the main directory of the |
|---|
| 31 | | - * Linux distribution for more details. |
|---|
| 32 | 29 | */ |
|---|
| 33 | 30 | |
|---|
| 34 | 31 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 36 | 33 | #include <linux/atomic.h> |
|---|
| 37 | 34 | #include <linux/cgroup.h> |
|---|
| 38 | 35 | #include <linux/slab.h> |
|---|
| 36 | +#include <linux/sched/task.h> |
|---|
| 39 | 37 | |
|---|
| 40 | 38 | #define PIDS_MAX (PID_MAX_LIMIT + 1ULL) |
|---|
| 41 | 39 | #define PIDS_MAX_STR "max" |
|---|
| .. | .. |
|---|
| 217 | 215 | * task_css_check(true) in pids_can_fork() and pids_cancel_fork() relies |
|---|
| 218 | 216 | * on cgroup_threadgroup_change_begin() held by the copy_process(). |
|---|
| 219 | 217 | */ |
|---|
| 220 | | -static int pids_can_fork(struct task_struct *task) |
|---|
| 218 | +static int pids_can_fork(struct task_struct *task, struct css_set *cset) |
|---|
| 221 | 219 | { |
|---|
| 222 | 220 | struct cgroup_subsys_state *css; |
|---|
| 223 | 221 | struct pids_cgroup *pids; |
|---|
| 224 | 222 | int err; |
|---|
| 225 | 223 | |
|---|
| 226 | | - css = task_css_check(current, pids_cgrp_id, true); |
|---|
| 224 | + if (cset) |
|---|
| 225 | + css = cset->subsys[pids_cgrp_id]; |
|---|
| 226 | + else |
|---|
| 227 | + css = task_css_check(current, pids_cgrp_id, true); |
|---|
| 227 | 228 | pids = css_pids(css); |
|---|
| 228 | 229 | err = pids_try_charge(pids, 1); |
|---|
| 229 | 230 | if (err) { |
|---|
| .. | .. |
|---|
| 238 | 239 | return err; |
|---|
| 239 | 240 | } |
|---|
| 240 | 241 | |
|---|
| 241 | | -static void pids_cancel_fork(struct task_struct *task) |
|---|
| 242 | +static void pids_cancel_fork(struct task_struct *task, struct css_set *cset) |
|---|
| 242 | 243 | { |
|---|
| 243 | 244 | struct cgroup_subsys_state *css; |
|---|
| 244 | 245 | struct pids_cgroup *pids; |
|---|
| 245 | 246 | |
|---|
| 246 | | - css = task_css_check(current, pids_cgrp_id, true); |
|---|
| 247 | + if (cset) |
|---|
| 248 | + css = cset->subsys[pids_cgrp_id]; |
|---|
| 249 | + else |
|---|
| 250 | + css = task_css_check(current, pids_cgrp_id, true); |
|---|
| 247 | 251 | pids = css_pids(css); |
|---|
| 248 | 252 | pids_uncharge(pids, 1); |
|---|
| 249 | 253 | } |
|---|