hooks.c (2e33405785d3eaec303c54b4a10afdebf3729da7) | hooks.c (602a8dd6ea6abd463bc26310c4a1b44919f88e68) |
---|---|
1/* 2 * NSA Security-Enhanced Linux (SELinux) security module 3 * 4 * This file contains the SELinux hook function implementations. 5 * 6 * Authors: Stephen Smalley, <sds@epoch.ncsc.mil> 7 * Chris Vance, <cvance@nai.com> 8 * Wayne Salamon, <wsalamon@nai.com> --- 1474 unchanged lines hidden (view full) --- 1483 return 0; 1484 1485 sid = cred_sid(cred); 1486 isec = inode->i_security; 1487 1488 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags); 1489} 1490 | 1/* 2 * NSA Security-Enhanced Linux (SELinux) security module 3 * 4 * This file contains the SELinux hook function implementations. 5 * 6 * Authors: Stephen Smalley, <sds@epoch.ncsc.mil> 7 * Chris Vance, <cvance@nai.com> 8 * Wayne Salamon, <wsalamon@nai.com> --- 1474 unchanged lines hidden (view full) --- 1483 return 0; 1484 1485 sid = cred_sid(cred); 1486 isec = inode->i_security; 1487 1488 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags); 1489} 1490 |
1491static int inode_has_perm_noadp(const struct cred *cred, 1492 struct inode *inode, 1493 u32 perms, 1494 unsigned flags) 1495{ 1496 struct common_audit_data ad; 1497 struct selinux_audit_data sad = {0,}; 1498 1499 COMMON_AUDIT_DATA_INIT(&ad, INODE); 1500 ad.u.inode = inode; 1501 ad.selinux_audit_data = &sad; 1502 return inode_has_perm(cred, inode, perms, &ad, flags); 1503} 1504 | |
1505/* Same as inode_has_perm, but pass explicit audit data containing 1506 the dentry to help the auditing code to more easily generate the 1507 pathname if needed. */ 1508static inline int dentry_has_perm(const struct cred *cred, 1509 struct dentry *dentry, 1510 u32 av) 1511{ 1512 struct inode *inode = dentry->d_inode; --- 610 unchanged lines hidden (view full) --- 2123 long j = -1; 2124 int drop_tty = 0; 2125 2126 tty = get_current_tty(); 2127 if (tty) { 2128 spin_lock(&tty_files_lock); 2129 if (!list_empty(&tty->tty_files)) { 2130 struct tty_file_private *file_priv; | 1491/* Same as inode_has_perm, but pass explicit audit data containing 1492 the dentry to help the auditing code to more easily generate the 1493 pathname if needed. */ 1494static inline int dentry_has_perm(const struct cred *cred, 1495 struct dentry *dentry, 1496 u32 av) 1497{ 1498 struct inode *inode = dentry->d_inode; --- 610 unchanged lines hidden (view full) --- 2109 long j = -1; 2110 int drop_tty = 0; 2111 2112 tty = get_current_tty(); 2113 if (tty) { 2114 spin_lock(&tty_files_lock); 2115 if (!list_empty(&tty->tty_files)) { 2116 struct tty_file_private *file_priv; |
2131 struct inode *inode; | |
2132 2133 /* Revalidate access to controlling tty. | 2117 2118 /* Revalidate access to controlling tty. |
2134 Use inode_has_perm on the tty inode directly rather | 2119 Use path_has_perm on the tty path directly rather |
2135 than using file_has_perm, as this particular open 2136 file may belong to another process and we are only 2137 interested in the inode-based check here. */ 2138 file_priv = list_first_entry(&tty->tty_files, 2139 struct tty_file_private, list); 2140 file = file_priv->file; | 2120 than using file_has_perm, as this particular open 2121 file may belong to another process and we are only 2122 interested in the inode-based check here. */ 2123 file_priv = list_first_entry(&tty->tty_files, 2124 struct tty_file_private, list); 2125 file = file_priv->file; |
2141 inode = file->f_path.dentry->d_inode; 2142 if (inode_has_perm_noadp(cred, inode, 2143 FILE__READ | FILE__WRITE, 0)) { | 2126 if (path_has_perm(cred, &file->f_path, FILE__READ | FILE__WRITE)) |
2144 drop_tty = 1; | 2127 drop_tty = 1; |
2145 } | |
2146 } 2147 spin_unlock(&tty_files_lock); 2148 tty_kref_put(tty); 2149 } 2150 /* Reset controlling tty. */ 2151 if (drop_tty) 2152 no_tty(); 2153 --- 1117 unchanged lines hidden (view full) --- 3271 const struct cred *cred = current_cred(); 3272 3273 return file_has_perm(cred, file, file_to_av(file)); 3274} 3275 3276static int selinux_file_open(struct file *file, const struct cred *cred) 3277{ 3278 struct file_security_struct *fsec; | 2128 } 2129 spin_unlock(&tty_files_lock); 2130 tty_kref_put(tty); 2131 } 2132 /* Reset controlling tty. */ 2133 if (drop_tty) 2134 no_tty(); 2135 --- 1117 unchanged lines hidden (view full) --- 3253 const struct cred *cred = current_cred(); 3254 3255 return file_has_perm(cred, file, file_to_av(file)); 3256} 3257 3258static int selinux_file_open(struct file *file, const struct cred *cred) 3259{ 3260 struct file_security_struct *fsec; |
3279 struct inode *inode; | |
3280 struct inode_security_struct *isec; 3281 | 3261 struct inode_security_struct *isec; 3262 |
3282 inode = file->f_path.dentry->d_inode; | |
3283 fsec = file->f_security; | 3263 fsec = file->f_security; |
3284 isec = inode->i_security; | 3264 isec = file->f_path.dentry->d_inode->i_security; |
3285 /* 3286 * Save inode label and policy sequence number 3287 * at open-time so that selinux_file_permission 3288 * can determine whether revalidation is necessary. 3289 * Task label is already saved in the file security 3290 * struct as its SID. 3291 */ 3292 fsec->isid = isec->sid; 3293 fsec->pseqno = avc_policy_seqno(); 3294 /* 3295 * Since the inode label or policy seqno may have changed 3296 * between the selinux_inode_permission check and the saving 3297 * of state above, recheck that access is still permitted. 3298 * Otherwise, access might never be revalidated against the 3299 * new inode label or new policy. 3300 * This check is not redundant - do not remove. 3301 */ | 3265 /* 3266 * Save inode label and policy sequence number 3267 * at open-time so that selinux_file_permission 3268 * can determine whether revalidation is necessary. 3269 * Task label is already saved in the file security 3270 * struct as its SID. 3271 */ 3272 fsec->isid = isec->sid; 3273 fsec->pseqno = avc_policy_seqno(); 3274 /* 3275 * Since the inode label or policy seqno may have changed 3276 * between the selinux_inode_permission check and the saving 3277 * of state above, recheck that access is still permitted. 3278 * Otherwise, access might never be revalidated against the 3279 * new inode label or new policy. 3280 * This check is not redundant - do not remove. 3281 */ |
3302 return inode_has_perm_noadp(cred, inode, open_file_to_av(file), 0); | 3282 return path_has_perm(cred, &file->f_path, open_file_to_av(file)); |
3303} 3304 3305/* task security operations */ 3306 3307static int selinux_task_create(unsigned long clone_flags) 3308{ 3309 return current_has_perm(current, PROCESS__FORK); 3310} --- 2648 unchanged lines hidden --- | 3283} 3284 3285/* task security operations */ 3286 3287static int selinux_task_create(unsigned long clone_flags) 3288{ 3289 return current_has_perm(current, PROCESS__FORK); 3290} --- 2648 unchanged lines hidden --- |