MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rctl_proc_ucred_changed

Function rctl_proc_ucred_changed

freebsd/kern/kern_rctl.c:1958–2104  ·  view source on GitHub ↗

* Update RCTL rule list after credential change. */

Source from the content-addressed store, hash-verified

1956 * Update RCTL rule list after credential change.
1957 */
1958void
1959rctl_proc_ucred_changed(struct proc *p, struct ucred *newcred)
1960{
1961 LIST_HEAD(, rctl_rule_link) newrules;
1962 struct rctl_rule_link *link, *newlink;
1963 struct uidinfo *newuip;
1964 struct loginclass *newlc;
1965 struct prison_racct *newprr;
1966 int rulecnt, i;
1967
1968 if (!racct_enable)
1969 return;
1970
1971 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
1972
1973 newuip = newcred->cr_ruidinfo;
1974 newlc = newcred->cr_loginclass;
1975 newprr = newcred->cr_prison->pr_prison_racct;
1976
1977 LIST_INIT(&newrules);
1978
1979again:
1980 /*
1981 * First, count the rules that apply to the process with new
1982 * credentials.
1983 */
1984 rulecnt = 0;
1985 RACCT_LOCK();
1986 LIST_FOREACH(link, &p->p_racct->r_rule_links, rrl_next) {
1987 if (link->rrl_rule->rr_subject_type ==
1988 RCTL_SUBJECT_TYPE_PROCESS)
1989 rulecnt++;
1990 }
1991 LIST_FOREACH(link, &newuip->ui_racct->r_rule_links, rrl_next)
1992 rulecnt++;
1993 LIST_FOREACH(link, &newlc->lc_racct->r_rule_links, rrl_next)
1994 rulecnt++;
1995 LIST_FOREACH(link, &newprr->prr_racct->r_rule_links, rrl_next)
1996 rulecnt++;
1997 RACCT_UNLOCK();
1998
1999 /*
2000 * Create temporary list. We've dropped the rctl_lock in order
2001 * to use M_WAITOK.
2002 */
2003 for (i = 0; i < rulecnt; i++) {
2004 newlink = uma_zalloc(rctl_rule_link_zone, M_WAITOK);
2005 newlink->rrl_rule = NULL;
2006 newlink->rrl_exceeded = 0;
2007 LIST_INSERT_HEAD(&newrules, newlink, rrl_next);
2008 }
2009
2010 newlink = LIST_FIRST(&newrules);
2011
2012 /*
2013 * Assign rules to the newly allocated list entries.
2014 */
2015 RACCT_LOCK();

Callers 6

do_jail_attachFunction · 0.85
prison_racct_modifyFunction · 0.85
sys_setloginclassFunction · 0.85
kern_prot.cFile · 0.85
sys_setreuidFunction · 0.85
sys_setresuidFunction · 0.85

Calls 4

rctl_rule_acquireFunction · 0.85
rctl_rule_releaseFunction · 0.85
uma_zallocFunction · 0.50
uma_zfreeFunction · 0.50

Tested by

no test coverage detected