kern_priv.c (170587) | kern_priv.c (170850) |
---|---|
1/*- 2 * Copyright (c) 2006 nCircle Network Security, Inc. 3 * All rights reserved. 4 * 5 * This software was developed by Robert N. M. Watson for the TrustedBSD 6 * Project under contract to nCircle Network Security, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2006 nCircle Network Security, Inc. 3 * All rights reserved. 4 * 5 * This software was developed by Robert N. M. Watson for the TrustedBSD 6 * Project under contract to nCircle Network Security, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/kern/kern_priv.c 170587 2007-06-12 00:12:01Z rwatson $ | 29 * $FreeBSD: head/sys/kern/kern_priv.c 170850 2007-06-16 23:41:43Z rwatson $ |
30 */ 31 32#include "opt_mac.h" 33 34#include <sys/param.h> 35#include <sys/jail.h> 36#include <sys/kernel.h> 37#include <sys/priv.h> --- 25 unchanged lines hidden (view full) --- 63int 64priv_check_cred(struct ucred *cred, int priv, int flags) 65{ 66 int error; 67 68 KASSERT(PRIV_VALID(priv), ("priv_check_cred: invalid privilege %d", 69 priv)); 70 | 30 */ 31 32#include "opt_mac.h" 33 34#include <sys/param.h> 35#include <sys/jail.h> 36#include <sys/kernel.h> 37#include <sys/priv.h> --- 25 unchanged lines hidden (view full) --- 63int 64priv_check_cred(struct ucred *cred, int priv, int flags) 65{ 66 int error; 67 68 KASSERT(PRIV_VALID(priv), ("priv_check_cred: invalid privilege %d", 69 priv)); 70 |
71 /* 72 * We first evaluate policies that may deny the granting of 73 * privilege unilaterally. 74 */ |
|
71#ifdef MAC 72 error = mac_priv_check(cred, priv); 73 if (error) 74 return (error); 75#endif 76 77 /* 78 * Jail policy will restrict certain privileges that may otherwise be 79 * be granted. 80 */ 81 error = prison_priv_check(cred, priv); 82 if (error) 83 return (error); 84 85 /* 86 * Having determined if privilege is restricted by various policies, | 75#ifdef MAC 76 error = mac_priv_check(cred, priv); 77 if (error) 78 return (error); 79#endif 80 81 /* 82 * Jail policy will restrict certain privileges that may otherwise be 83 * be granted. 84 */ 85 error = prison_priv_check(cred, priv); 86 if (error) 87 return (error); 88 89 /* 90 * Having determined if privilege is restricted by various policies, |
87 * now determine if privilege is granted. For now, we allow 88 * short-circuit boolean evaluation, so may not call all policies. 89 * Perhaps we should. | 91 * now determine if privilege is granted. At this point, any policy 92 * may grant privilege. For now, we allow short-circuit boolean 93 * evaluation, so may not call all policies. Perhaps we should. |
90 * 91 * Superuser policy grants privilege based on the effective (or in | 94 * 95 * Superuser policy grants privilege based on the effective (or in |
92 * certain edge cases, real) uid being 0. We allow the policy to be 93 * globally disabled, although this is currently of limited utility. | 96 * the case of specific privileges, real) uid being 0. We allow the 97 * superuser policy to be globally disabled, although this is 98 * currenty of limited utility. |
94 */ 95 if (suser_enabled) { | 99 */ 100 if (suser_enabled) { |
96 if (flags & SUSER_RUID) { | 101 switch (priv) { 102 case PRIV_MAXFILES: 103 case PRIV_MAXPROC: 104 case PRIV_PROC_LIMIT: |
97 if (cred->cr_ruid == 0) 98 return (0); | 105 if (cred->cr_ruid == 0) 106 return (0); |
99 } else { | 107 break; 108 109 default: |
100 if (cred->cr_uid == 0) 101 return (0); | 110 if (cred->cr_uid == 0) 111 return (0); |
112 break; |
|
102 } 103 } 104 105 /* 106 * Now check with MAC, if enabled, to see if a policy module grants 107 * privilege. 108 */ 109#ifdef MAC --- 35 unchanged lines hidden --- | 113 } 114 } 115 116 /* 117 * Now check with MAC, if enabled, to see if a policy module grants 118 * privilege. 119 */ 120#ifdef MAC --- 35 unchanged lines hidden --- |