Date: Sun, 2 Aug 2009 12:12:42 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 166923 for review Message-ID: <200908021212.n72CCgxM087723@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=166923 Change 166923 by trasz@trasz_anger on 2009/08/02 12:12:15 Add some more error checking. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#37 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#17 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#37 (text+ko) ==== @@ -112,6 +112,7 @@ static void hrl_compute_available(struct proc *p, int64_t (*availablep)[], struct hrl_rule *(*rulesp)[]); static struct sbuf *hrl_rules_to_sbuf(struct hrl_rule *usage, int nrules); +static int hrl_rule_fully_specified(const struct hrl_rule *rule); MALLOC_DEFINE(M_HRL, "hrl", "Hierarchical Resource Limits"); @@ -670,6 +671,8 @@ { struct hrl_limit *limit; + KASSERT(hrl_rule_fully_specified(rule), ("rule not fully specified")); + hrl_rule_acquire(rule); limit = uma_zalloc(hrl_limit_zone, M_WAITOK); limit->hl_rule = rule; @@ -781,6 +784,26 @@ uma_zfree(hrl_rule_zone, rule); } +static int +hrl_rule_fully_specified(const struct hrl_rule *rule) +{ + + if (rule->hr_subject == HRL_SUBJECT_UNDEFINED) + return (0); + if (rule->hr_subject_id == HRL_SUBJECT_ID_UNDEFINED) + return (0); + if (rule->hr_resource == HRL_RESOURCE_UNDEFINED) + return (0); + if (rule->hr_action == HRL_ACTION_UNDEFINED) + return (0); + if (rule->hr_amount < 0) + return (0); + if (rule->hr_per == HRL_SUBJECT_UNDEFINED) + return (0); + + return (1); +} + /* * Link a rule with subjects to which it applies. */ @@ -794,6 +817,8 @@ struct prison *pr; struct loginclass *lc; + KASSERT(hrl_rule_fully_specified(rule), ("rule not fully specified")); + /* * Make sure there are no duplicated rules. */ @@ -1347,24 +1372,10 @@ if (error) goto out; - if (rule->hr_subject == HRL_SUBJECT_UNDEFINED) + if (!hrl_rule_fully_specified(rule)) { error = EINVAL; goto out; - if (rule->hr_subject_id == HRL_SUBJECT_ID_UNDEFINED) - error = EINVAL; - goto out; - if (rule->hr_resource == HRL_RESOURCE_UNDEFINED) - error = EINVAL; - goto out; - if (rule->hr_action == HRL_ACTION_UNDEFINED) - error = EINVAL; - goto out; - if (rule->hr_amount < 0) - error = EINVAL; - goto out; - if (rule->hr_per == HRL_SUBJECT_UNDEFINED) - error = EINVAL; - goto out; + } error = hrl_rule_add(rule); ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#17 (text+ko) ==== @@ -652,6 +652,7 @@ static void hrl_handle_setrlimit(u_int which, struct rlimit *lim, struct thread *td) { + int error; struct hrl_rule *rule, *rule2; rule = hrl_rule_alloc(); @@ -729,14 +730,16 @@ if (lim->rlim_cur != RLIM_INFINITY) { rule2->hr_amount = lim->rlim_cur; - hrl_rule_add(rule2); + error = hrl_rule_add(rule2); + KASSERT(error == 0, ("hrl_rule_add failed")); } hrl_rule_release(rule2); } if (lim->rlim_cur != RLIM_INFINITY) { rule->hr_amount = lim->rlim_cur; - hrl_rule_add(rule); + error = hrl_rule_add(rule); + KASSERT(error == 0, ("hrl_rule_add failed")); } hrl_rule_release(rule); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908021212.n72CCgxM087723>