From owner-p4-projects@FreeBSD.ORG Sun Aug 2 12:12:43 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6EFF210656C2; Sun, 2 Aug 2009 12:12:43 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2E7DA10656C7 for ; Sun, 2 Aug 2009 12:12:43 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 1CAD08FC1B for ; Sun, 2 Aug 2009 12:12:43 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n72CCgbq087725 for ; Sun, 2 Aug 2009 12:12:43 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n72CCgxM087723 for perforce@freebsd.org; Sun, 2 Aug 2009 12:12:42 GMT (envelope-from trasz@freebsd.org) Date: Sun, 2 Aug 2009 12:12:42 GMT Message-Id: <200908021212.n72CCgxM087723@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Cc: Subject: PERFORCE change 166923 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Aug 2009 12:12:44 -0000 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); }