diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-22 14:18:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-22 14:18:20 -0400 |
commit | dd6ccfe64dad4ea498392805b477308abef43a4c (patch) | |
tree | ed632bc216ddfe893946587ecc523acade66f9a6 | |
parent | dc79747019b43c28d1f50aad69b8039f8d8db301 (diff) | |
parent | 4259fa01a2d2aa3e589b34ba7624080232d9c1ff (diff) |
Merge branch 'audit.b39' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current
* 'audit.b39' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current:
[PATCH] get rid of AVC_PATH postponed treatment
[PATCH] allow audit filtering on bit & operations
[PATCH] audit: fix broken class-based syscall audit
[PATCH] Make IPC mode consistent
-rw-r--r-- | include/linux/audit.h | 32 | ||||
-rw-r--r-- | kernel/auditfilter.c | 13 | ||||
-rw-r--r-- | kernel/auditsc.c | 51 | ||||
-rw-r--r-- | security/selinux/avc.c | 15 |
4 files changed, 39 insertions, 72 deletions
diff --git a/include/linux/audit.h b/include/linux/audit.h index 8ca7ca0b47f0..4bbd8601b8f0 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h | |||
@@ -161,7 +161,7 @@ | |||
161 | * are currently used in an audit field constant understood by the kernel. | 161 | * are currently used in an audit field constant understood by the kernel. |
162 | * If you are adding a new #define AUDIT_<whatever>, please ensure that | 162 | * If you are adding a new #define AUDIT_<whatever>, please ensure that |
163 | * AUDIT_UNUSED_BITS is updated if need be. */ | 163 | * AUDIT_UNUSED_BITS is updated if need be. */ |
164 | #define AUDIT_UNUSED_BITS 0x0FFFFC00 | 164 | #define AUDIT_UNUSED_BITS 0x07FFFC00 |
165 | 165 | ||
166 | 166 | ||
167 | /* Rule fields */ | 167 | /* Rule fields */ |
@@ -213,25 +213,29 @@ | |||
213 | #define AUDIT_NEGATE 0x80000000 | 213 | #define AUDIT_NEGATE 0x80000000 |
214 | 214 | ||
215 | /* These are the supported operators. | 215 | /* These are the supported operators. |
216 | * 4 2 1 | 216 | * 4 2 1 8 |
217 | * = > < | 217 | * = > < ? |
218 | * ------- | 218 | * ---------- |
219 | * 0 0 0 0 nonsense | 219 | * 0 0 0 0 00 nonsense |
220 | * 0 0 1 1 < | 220 | * 0 0 0 1 08 & bit mask |
221 | * 0 1 0 2 > | 221 | * 0 0 1 0 10 < |
222 | * 0 1 1 3 != | 222 | * 0 1 0 0 20 > |
223 | * 1 0 0 4 = | 223 | * 0 1 1 0 30 != |
224 | * 1 0 1 5 <= | 224 | * 1 0 0 0 40 = |
225 | * 1 1 0 6 >= | 225 | * 1 0 0 1 48 &= bit test |
226 | * 1 1 1 7 all operators | 226 | * 1 0 1 0 50 <= |
227 | * 1 1 0 0 60 >= | ||
228 | * 1 1 1 1 78 all operators | ||
227 | */ | 229 | */ |
230 | #define AUDIT_BIT_MASK 0x08000000 | ||
228 | #define AUDIT_LESS_THAN 0x10000000 | 231 | #define AUDIT_LESS_THAN 0x10000000 |
229 | #define AUDIT_GREATER_THAN 0x20000000 | 232 | #define AUDIT_GREATER_THAN 0x20000000 |
230 | #define AUDIT_NOT_EQUAL 0x30000000 | 233 | #define AUDIT_NOT_EQUAL 0x30000000 |
231 | #define AUDIT_EQUAL 0x40000000 | 234 | #define AUDIT_EQUAL 0x40000000 |
235 | #define AUDIT_BIT_TEST (AUDIT_BIT_MASK|AUDIT_EQUAL) | ||
232 | #define AUDIT_LESS_THAN_OR_EQUAL (AUDIT_LESS_THAN|AUDIT_EQUAL) | 236 | #define AUDIT_LESS_THAN_OR_EQUAL (AUDIT_LESS_THAN|AUDIT_EQUAL) |
233 | #define AUDIT_GREATER_THAN_OR_EQUAL (AUDIT_GREATER_THAN|AUDIT_EQUAL) | 237 | #define AUDIT_GREATER_THAN_OR_EQUAL (AUDIT_GREATER_THAN|AUDIT_EQUAL) |
234 | #define AUDIT_OPERATORS (AUDIT_EQUAL|AUDIT_NOT_EQUAL) | 238 | #define AUDIT_OPERATORS (AUDIT_EQUAL|AUDIT_NOT_EQUAL|AUDIT_BIT_MASK) |
235 | 239 | ||
236 | /* Status symbols */ | 240 | /* Status symbols */ |
237 | /* Mask values */ | 241 | /* Mask values */ |
@@ -407,7 +411,6 @@ extern int audit_bprm(struct linux_binprm *bprm); | |||
407 | extern int audit_socketcall(int nargs, unsigned long *args); | 411 | extern int audit_socketcall(int nargs, unsigned long *args); |
408 | extern int audit_sockaddr(int len, void *addr); | 412 | extern int audit_sockaddr(int len, void *addr); |
409 | extern int __audit_fd_pair(int fd1, int fd2); | 413 | extern int __audit_fd_pair(int fd1, int fd2); |
410 | extern int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt); | ||
411 | extern int audit_set_macxattr(const char *name); | 414 | extern int audit_set_macxattr(const char *name); |
412 | extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr); | 415 | extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr); |
413 | extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout); | 416 | extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout); |
@@ -487,7 +490,6 @@ extern int audit_signals; | |||
487 | #define audit_socketcall(n,a) ({ 0; }) | 490 | #define audit_socketcall(n,a) ({ 0; }) |
488 | #define audit_fd_pair(n,a) ({ 0; }) | 491 | #define audit_fd_pair(n,a) ({ 0; }) |
489 | #define audit_sockaddr(len, addr) ({ 0; }) | 492 | #define audit_sockaddr(len, addr) ({ 0; }) |
490 | #define audit_avc_path(dentry, mnt) ({ 0; }) | ||
491 | #define audit_set_macxattr(n) do { ; } while (0) | 493 | #define audit_set_macxattr(n) do { ; } while (0) |
492 | #define audit_mq_open(o,m,a) ({ 0; }) | 494 | #define audit_mq_open(o,m,a) ({ 0; }) |
493 | #define audit_mq_timedsend(d,l,p,t) ({ 0; }) | 495 | #define audit_mq_timedsend(d,l,p,t) ({ 0; }) |
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 1bf093dcffe0..359645cff5b2 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -304,7 +304,7 @@ int __init audit_register_class(int class, unsigned *list) | |||
304 | 304 | ||
305 | int audit_match_class(int class, unsigned syscall) | 305 | int audit_match_class(int class, unsigned syscall) |
306 | { | 306 | { |
307 | if (unlikely(syscall >= AUDIT_BITMASK_SIZE * sizeof(__u32))) | 307 | if (unlikely(syscall >= AUDIT_BITMASK_SIZE * 32)) |
308 | return 0; | 308 | return 0; |
309 | if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class])) | 309 | if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class])) |
310 | return 0; | 310 | return 0; |
@@ -456,6 +456,13 @@ static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule) | |||
456 | case AUDIT_DEVMINOR: | 456 | case AUDIT_DEVMINOR: |
457 | case AUDIT_EXIT: | 457 | case AUDIT_EXIT: |
458 | case AUDIT_SUCCESS: | 458 | case AUDIT_SUCCESS: |
459 | /* bit ops are only useful on syscall args */ | ||
460 | if (f->op == AUDIT_BIT_MASK || | ||
461 | f->op == AUDIT_BIT_TEST) { | ||
462 | err = -EINVAL; | ||
463 | goto exit_free; | ||
464 | } | ||
465 | break; | ||
459 | case AUDIT_ARG0: | 466 | case AUDIT_ARG0: |
460 | case AUDIT_ARG1: | 467 | case AUDIT_ARG1: |
461 | case AUDIT_ARG2: | 468 | case AUDIT_ARG2: |
@@ -1566,6 +1573,10 @@ int audit_comparator(const u32 left, const u32 op, const u32 right) | |||
1566 | return (left > right); | 1573 | return (left > right); |
1567 | case AUDIT_GREATER_THAN_OR_EQUAL: | 1574 | case AUDIT_GREATER_THAN_OR_EQUAL: |
1568 | return (left >= right); | 1575 | return (left >= right); |
1576 | case AUDIT_BIT_MASK: | ||
1577 | return (left & right); | ||
1578 | case AUDIT_BIT_TEST: | ||
1579 | return ((left & right) == right); | ||
1569 | } | 1580 | } |
1570 | BUG(); | 1581 | BUG(); |
1571 | return 0; | 1582 | return 0; |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 145cbb79c4b9..bde1124d5908 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -173,12 +173,6 @@ struct audit_aux_data_fd_pair { | |||
173 | int fd[2]; | 173 | int fd[2]; |
174 | }; | 174 | }; |
175 | 175 | ||
176 | struct audit_aux_data_path { | ||
177 | struct audit_aux_data d; | ||
178 | struct dentry *dentry; | ||
179 | struct vfsmount *mnt; | ||
180 | }; | ||
181 | |||
182 | struct audit_aux_data_pids { | 176 | struct audit_aux_data_pids { |
183 | struct audit_aux_data d; | 177 | struct audit_aux_data d; |
184 | pid_t target_pid[AUDIT_AUX_PIDS]; | 178 | pid_t target_pid[AUDIT_AUX_PIDS]; |
@@ -654,12 +648,6 @@ static inline void audit_free_aux(struct audit_context *context) | |||
654 | struct audit_aux_data *aux; | 648 | struct audit_aux_data *aux; |
655 | 649 | ||
656 | while ((aux = context->aux)) { | 650 | while ((aux = context->aux)) { |
657 | if (aux->type == AUDIT_AVC_PATH) { | ||
658 | struct audit_aux_data_path *axi = (void *)aux; | ||
659 | dput(axi->dentry); | ||
660 | mntput(axi->mnt); | ||
661 | } | ||
662 | |||
663 | context->aux = aux->next; | 651 | context->aux = aux->next; |
664 | kfree(aux); | 652 | kfree(aux); |
665 | } | 653 | } |
@@ -995,7 +983,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
995 | case AUDIT_IPC: { | 983 | case AUDIT_IPC: { |
996 | struct audit_aux_data_ipcctl *axi = (void *)aux; | 984 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
997 | audit_log_format(ab, | 985 | audit_log_format(ab, |
998 | "ouid=%u ogid=%u mode=%x", | 986 | "ouid=%u ogid=%u mode=%#o", |
999 | axi->uid, axi->gid, axi->mode); | 987 | axi->uid, axi->gid, axi->mode); |
1000 | if (axi->osid != 0) { | 988 | if (axi->osid != 0) { |
1001 | char *ctx = NULL; | 989 | char *ctx = NULL; |
@@ -1014,7 +1002,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1014 | case AUDIT_IPC_SET_PERM: { | 1002 | case AUDIT_IPC_SET_PERM: { |
1015 | struct audit_aux_data_ipcctl *axi = (void *)aux; | 1003 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
1016 | audit_log_format(ab, | 1004 | audit_log_format(ab, |
1017 | "qbytes=%lx ouid=%u ogid=%u mode=%x", | 1005 | "qbytes=%lx ouid=%u ogid=%u mode=%#o", |
1018 | axi->qbytes, axi->uid, axi->gid, axi->mode); | 1006 | axi->qbytes, axi->uid, axi->gid, axi->mode); |
1019 | break; } | 1007 | break; } |
1020 | 1008 | ||
@@ -1038,11 +1026,6 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1038 | audit_log_hex(ab, axs->a, axs->len); | 1026 | audit_log_hex(ab, axs->a, axs->len); |
1039 | break; } | 1027 | break; } |
1040 | 1028 | ||
1041 | case AUDIT_AVC_PATH: { | ||
1042 | struct audit_aux_data_path *axi = (void *)aux; | ||
1043 | audit_log_d_path(ab, "path=", axi->dentry, axi->mnt); | ||
1044 | break; } | ||
1045 | |||
1046 | case AUDIT_FD_PAIR: { | 1029 | case AUDIT_FD_PAIR: { |
1047 | struct audit_aux_data_fd_pair *axs = (void *)aux; | 1030 | struct audit_aux_data_fd_pair *axs = (void *)aux; |
1048 | audit_log_format(ab, "fd0=%d fd1=%d", axs->fd[0], axs->fd[1]); | 1031 | audit_log_format(ab, "fd0=%d fd1=%d", axs->fd[0], axs->fd[1]); |
@@ -1991,36 +1974,6 @@ void __audit_ptrace(struct task_struct *t) | |||
1991 | } | 1974 | } |
1992 | 1975 | ||
1993 | /** | 1976 | /** |
1994 | * audit_avc_path - record the granting or denial of permissions | ||
1995 | * @dentry: dentry to record | ||
1996 | * @mnt: mnt to record | ||
1997 | * | ||
1998 | * Returns 0 for success or NULL context or < 0 on error. | ||
1999 | * | ||
2000 | * Called from security/selinux/avc.c::avc_audit() | ||
2001 | */ | ||
2002 | int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt) | ||
2003 | { | ||
2004 | struct audit_aux_data_path *ax; | ||
2005 | struct audit_context *context = current->audit_context; | ||
2006 | |||
2007 | if (likely(!context)) | ||
2008 | return 0; | ||
2009 | |||
2010 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); | ||
2011 | if (!ax) | ||
2012 | return -ENOMEM; | ||
2013 | |||
2014 | ax->dentry = dget(dentry); | ||
2015 | ax->mnt = mntget(mnt); | ||
2016 | |||
2017 | ax->d.type = AUDIT_AVC_PATH; | ||
2018 | ax->d.next = context->aux; | ||
2019 | context->aux = (void *)ax; | ||
2020 | return 0; | ||
2021 | } | ||
2022 | |||
2023 | /** | ||
2024 | * audit_signal_info - record signal info for shutting down audit subsystem | 1977 | * audit_signal_info - record signal info for shutting down audit subsystem |
2025 | * @sig: signal value | 1978 | * @sig: signal value |
2026 | * @t: task being signaled | 1979 | * @t: task being signaled |
diff --git a/security/selinux/avc.c b/security/selinux/avc.c index ecd067384531..0e69adf63bdb 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c | |||
@@ -570,10 +570,12 @@ void avc_audit(u32 ssid, u32 tsid, | |||
570 | case AVC_AUDIT_DATA_FS: | 570 | case AVC_AUDIT_DATA_FS: |
571 | if (a->u.fs.dentry) { | 571 | if (a->u.fs.dentry) { |
572 | struct dentry *dentry = a->u.fs.dentry; | 572 | struct dentry *dentry = a->u.fs.dentry; |
573 | if (a->u.fs.mnt) | 573 | if (a->u.fs.mnt) { |
574 | audit_avc_path(dentry, a->u.fs.mnt); | 574 | audit_log_d_path(ab, "path=", dentry, a->u.fs.mnt); |
575 | audit_log_format(ab, " name="); | 575 | } else { |
576 | audit_log_untrustedstring(ab, dentry->d_name.name); | 576 | audit_log_format(ab, " name="); |
577 | audit_log_untrustedstring(ab, dentry->d_name.name); | ||
578 | } | ||
577 | inode = dentry->d_inode; | 579 | inode = dentry->d_inode; |
578 | } else if (a->u.fs.inode) { | 580 | } else if (a->u.fs.inode) { |
579 | struct dentry *dentry; | 581 | struct dentry *dentry; |
@@ -624,9 +626,8 @@ void avc_audit(u32 ssid, u32 tsid, | |||
624 | case AF_UNIX: | 626 | case AF_UNIX: |
625 | u = unix_sk(sk); | 627 | u = unix_sk(sk); |
626 | if (u->dentry) { | 628 | if (u->dentry) { |
627 | audit_avc_path(u->dentry, u->mnt); | 629 | audit_log_d_path(ab, "path=", |
628 | audit_log_format(ab, " name="); | 630 | u->dentry, u->mnt); |
629 | audit_log_untrustedstring(ab, u->dentry->d_name.name); | ||
630 | break; | 631 | break; |
631 | } | 632 | } |
632 | if (!u->addr) | 633 | if (!u->addr) |