Star64_linux/kernel
Eric W. Biederman feed145964 ucounts: Enforce RLIMIT_NPROC not RLIMIT_NPROC+1
commit 8f2f9c4d82 upstream.

Michal Koutný <mkoutny@suse.com> wrote:

> It was reported that v5.14 behaves differently when enforcing
> RLIMIT_NPROC limit, namely, it allows one more task than previously.
> This is consequence of the commit 21d1c5e386 ("Reimplement
> RLIMIT_NPROC on top of ucounts") that missed the sharpness of
> equality in the forking path.

This can be fixed either by fixing the test or by moving the increment
to be before the test.  Fix it my moving copy_creds which contains
the increment before is_ucounts_overlimit.

In the case of CLONE_NEWUSER the ucounts in the task_cred changes.
The function is_ucounts_overlimit needs to use the final version of
the ucounts for the new process.  Which means moving the
is_ucounts_overlimit test after copy_creds is necessary.

Both the test in fork and the test in set_user were semantically
changed when the code moved to ucounts.  The change of the test in
fork was bad because it was before the increment.  The test in
set_user was wrong and the change to ucounts fixed it.  So this
fix only restores the old behavior in one lcation not two.

Link: https://lkml.kernel.org/r/20220204181144.24462-1-mkoutny@suse.com
Link: https://lkml.kernel.org/r/20220216155832.680775-2-ebiederm@xmission.com
Cc: stable@vger.kernel.org
Reported-by: Michal Koutný <mkoutny@suse.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Fixes: 21d1c5e386 ("Reimplement RLIMIT_NPROC on top of ucounts")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-19 17:45:35 +08:00
..
bpf bpf: Use VM_MAP instead of VM_ALLOC for ringbuf 2023-04-19 17:45:07 +08:00
cgroup cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning 2023-04-19 17:45:09 +08:00
configs
debug
dma dma/pool: create dma atomic pool only if dma zone has managed pages 2023-04-19 17:43:49 +08:00
entry
events perf: Fix list corruption in perf_cgroup_switch() 2023-04-19 17:45:22 +08:00
gcov
irq
kcsan
livepatch
locking
power PM: s2idle: ACPI: Fix wakeup interrupts handling 2023-04-19 17:45:15 +08:00
printk
rcu rcu: Tighten rcu_advance_cbs_nowake() checks 2023-04-19 17:44:46 +08:00
sched sched: Avoid double preemption in __cond_resched_*lock*() 2023-04-19 17:45:13 +08:00
time clocksource: Avoid accidental unstable marking of clocksources 2023-04-19 17:44:12 +08:00
trace tracing: Fix tp_printk option related with tp_printk_stop_on_boot 2023-04-19 17:45:34 +08:00
.gitignore
acct.c
async.c Revert "module, async: async_synchronize_full() on module init iff async is used" 2023-04-19 17:45:26 +08:00
audit.c audit: improve audit queue handling when "audit=1" on cmdline 2023-04-19 17:45:01 +08:00
audit.h
audit_fsnotify.c
audit_tree.c
audit_watch.c
auditfilter.c
auditsc.c
backtracetest.c
bounds.c
capability.c
cfi.c
compat.c
configs.c
context_tracking.c
cpu.c
cpu_pm.c
crash_core.c kernel/crash_core: suppress unknown crashkernel parameter warning 2023-04-19 17:43:23 +08:00
crash_dump.c
cred.c ucounts: Base set_cred_ucounts changes on the real user 2023-04-19 17:45:35 +08:00
delayacct.c
dma.c
exec_domain.c
exit.c
extable.c
fail_function.c
fork.c ucounts: Enforce RLIMIT_NPROC not RLIMIT_NPROC+1 2023-04-19 17:45:35 +08:00
freezer.c
futex.c
gen_kheaders.sh
groups.c
hung_task.c
iomem.c
irq_work.c
jump_label.c
kallsyms.c
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
kcov.c
kexec.c
kexec_core.c
kexec_elf.c
kexec_file.c
kexec_internal.h
kheaders.c
kmod.c
kprobes.c
ksysfs.c
kthread.c
latencytop.c
Makefile
module-internal.h
module.c Revert "module, async: async_synchronize_full() on module init iff async is used" 2023-04-19 17:45:26 +08:00
module_signature.c
module_signing.c
notifier.c
nsproxy.c
padata.c
panic.c
params.c
pid.c
pid_namespace.c
profile.c
ptrace.c
range.c
reboot.c
regset.c
relay.c
resource.c
resource_kunit.c
rseq.c
scftorture.c
scs.c
seccomp.c seccomp: Invalidate seccomp mode to catch death failures 2023-04-19 17:45:21 +08:00
signal.c signal: HANDLER_EXIT should clear SIGNAL_UNKILLABLE 2023-04-19 17:45:21 +08:00
smp.c
smpboot.c
smpboot.h
softirq.c
stackleak.c gcc-plugins/stackleak: Use noinstr in favor of notrace 2023-04-19 17:45:26 +08:00
stacktrace.c
static_call.c
stop_machine.c
sys.c
sys_ni.c
sysctl-test.c
sysctl.c
task_work.c
taskstats.c
test_kprobes.c
torture.c
tracepoint.c
tsacct.c taskstats: Cleanup the use of task->exit_code 2023-04-19 17:44:42 +08:00
ucount.c ucounts: Handle wrapping in is_ucounts_overlimit 2023-04-19 17:45:35 +08:00
uid16.c
uid16.h
umh.c
up.c
user-return-notifier.c
user.c
user_namespace.c
usermode_driver.c
utsname.c
utsname_sysctl.c
watch_queue.c
watchdog.c
watchdog_hld.c
workqueue.c workqueue: Fix unbind_workers() VS wq_worker_running() race 2023-04-19 17:43:39 +08:00
workqueue_internal.h