FreeBSD/src f87beb9 (r332816)sys/kern kern_prot.c kern_jail.c

call racct_proc_ucred_changed() under the proc lock

The lock is required to ensure that the switch to the new credentials
and the transfer of the process's accounting data from the old
credentials to the new ones is done atomically.  Otherwise, some updates
may be applied to the new credentials and then additionally transferred
from the old credentials if the updates happen after proc_set_cred() and
before racct_proc_ucred_changed().

The problem is especially pronounced for RACCT_RSS because
- there is a strict accounting for this resource (it's reclaimable)
- it's updated asynchronously by the vm daemon
- it's updated by setting an absolute value instead of applying a delta

I had to remove a call to rctl_proc_ucred_changed() from
racct_proc_ucred_changed() and make all callers of latter call the
former as well.  The reason is that rctl_proc_ucred_changed, as it is
implemented now, cannot be called while holding the proc lock, so the
lock is dropped after calling racct_proc_ucred_changed.  Additionally,
I've added calls to crhold / crfree around the rctl call, because
without the proc lock there is no gurantee that the new credentials,
owned by the process, will stay stable.  That does not eliminate a
possibility that the credentials passed to the rctl will get stale.
Ideally, rctl_proc_ucred_changed should be able to work under the proc
lock.

Many thanks to kib for pointing out the above problems.

PR:             222027
Discussed with: kib
No comment:     trasz
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D15048
DeltaFile
+19-3sys/kern/kern_prot.c
+10-2sys/kern/kern_jail.c
+7-1sys/kern/kern_loginclass.c
+5-2sys/kern/kern_rctl.c
+1-5sys/kern/kern_racct.c
+42-135 files

UnifiedSplitRaw