Skip to content

Commit 5859a2b

Browse files
committed
Merge branch 'ucount-rlimit-fixes-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull ucounts fix from Eric Biederman: "Etienne Dechamps recently found a regression caused by enforcing RLIMIT_NPROC for root where the rlimit was not previously enforced. Michal Koutný had previously pointed out the inconsistency in enforcing the RLIMIT_NPROC that had been on the root owned process after the root user creates a user namespace. Which makes the fix for the regression simply removing the inconsistency" * 'ucount-rlimit-fixes-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: ucounts: Fix systemd LimitNPROC with private users regression
2 parents 7e3d761 + 0ac983f commit 5859a2b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

kernel/user_namespace.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)
5858
cred->user_ns = user_ns;
5959
}
6060

61+
static unsigned long enforced_nproc_rlimit(void)
62+
{
63+
unsigned long limit = RLIM_INFINITY;
64+
65+
/* Is RLIMIT_NPROC currently enforced? */
66+
if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) ||
67+
(current_user_ns() != &init_user_ns))
68+
limit = rlimit(RLIMIT_NPROC);
69+
70+
return limit;
71+
}
72+
6173
/*
6274
* Create a new user namespace, deriving the creator from the user in the
6375
* passed credentials, and replacing that user with the new root user for the
@@ -122,7 +134,7 @@ int create_user_ns(struct cred *new)
122134
for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++) {
123135
ns->ucount_max[i] = INT_MAX;
124136
}
125-
set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC));
137+
set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_NPROC, enforced_nproc_rlimit());
126138
set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MSGQUEUE, rlimit(RLIMIT_MSGQUEUE));
127139
set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_SIGPENDING, rlimit(RLIMIT_SIGPENDING));
128140
set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK));

0 commit comments

Comments
 (0)