| 85c8721 | 2005-04-29 16:23:29 +0100 | [diff] [blame] | 1 | /* auditsc.c -- System-call auditing support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Handles all system-call specific auditing features. |
| 3 | * |
| 4 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 5 | * Copyright 2005 Hewlett-Packard Development Company, L.P. |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 6 | * Copyright (C) 2005, 2006 IBM Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * All Rights Reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> |
| 24 | * |
| 25 | * Many of the ideas implemented here are from Stephen C. Tweedie, |
| 26 | * especially the idea of avoiding a copy by using getname. |
| 27 | * |
| 28 | * The method for actual interception of syscall entry and exit (not in |
| 29 | * this file -- see entry.S) is based on a GPL'd patch written by |
| 30 | * okir@suse.de and Copyright 2003 SuSE Linux AG. |
| 31 | * |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 32 | * POSIX message queue support added by George Wilson <ltcgcw@us.ibm.com>, |
| 33 | * 2006. |
| 34 | * |
Dustin Kirkland | b63862f | 2005-11-03 15:41:46 +0000 | [diff] [blame] | 35 | * The support of additional filter rules compares (>, <, >=, <=) was |
| 36 | * added by Dustin Kirkland <dustin.kirkland@us.ibm.com>, 2005. |
| 37 | * |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 38 | * Modified by Amy Griffis <amy.griffis@hp.com> to collect additional |
| 39 | * filesystem information. |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 40 | * |
| 41 | * Subject and object context labeling support added by <danjones@us.ibm.com> |
| 42 | * and <dustin.kirkland@us.ibm.com> for LSPP certification compliance. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | */ |
| 44 | |
| 45 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/types.h> |
Alan Cox | 715b49e | 2006-01-18 17:44:07 -0800 | [diff] [blame] | 47 | #include <asm/atomic.h> |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 48 | #include <linux/fs.h> |
| 49 | #include <linux/namei.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/mm.h> |
| 51 | #include <linux/module.h> |
Stephen Smalley | 0111610 | 2005-05-21 00:15:52 +0100 | [diff] [blame] | 52 | #include <linux/mount.h> |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 53 | #include <linux/socket.h> |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 54 | #include <linux/mqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <linux/audit.h> |
| 56 | #include <linux/personality.h> |
| 57 | #include <linux/time.h> |
David Woodhouse | 5bb289b | 2005-06-24 14:14:05 +0100 | [diff] [blame] | 58 | #include <linux/netlink.h> |
David Woodhouse | f556196 | 2005-07-13 22:47:07 +0100 | [diff] [blame] | 59 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <asm/unistd.h> |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 61 | #include <linux/security.h> |
David Woodhouse | fe7752b | 2005-12-15 18:33:52 +0000 | [diff] [blame] | 62 | #include <linux/list.h> |
Steve Grubb | a6c043a | 2006-01-01 14:07:00 -0500 | [diff] [blame] | 63 | #include <linux/tty.h> |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 64 | #include <linux/binfmts.h> |
Al Viro | a1f8e7f7 | 2006-10-19 16:08:53 -0400 | [diff] [blame] | 65 | #include <linux/highmem.h> |
Al Viro | f46038f | 2006-05-06 08:22:52 -0400 | [diff] [blame] | 66 | #include <linux/syscalls.h> |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 67 | #include <linux/inotify.h> |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 68 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
David Woodhouse | fe7752b | 2005-12-15 18:33:52 +0000 | [diff] [blame] | 70 | #include "audit.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* AUDIT_NAMES is the number of slots we reserve in the audit_context |
| 73 | * for saving names from getname(). */ |
| 74 | #define AUDIT_NAMES 20 |
| 75 | |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 76 | /* Indicates that audit should log the full pathname. */ |
| 77 | #define AUDIT_NAME_FULL -1 |
| 78 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 79 | /* no execve audit message should be longer than this (userspace limits) */ |
| 80 | #define MAX_EXECVE_AUDIT_LEN 7500 |
| 81 | |
Al Viro | 471a5c7 | 2006-07-10 08:29:24 -0400 | [diff] [blame] | 82 | /* number of audit rules */ |
| 83 | int audit_n_rules; |
| 84 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 85 | /* determines whether we collect data for signals sent */ |
| 86 | int audit_signals; |
| 87 | |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 88 | struct audit_cap_data { |
| 89 | kernel_cap_t permitted; |
| 90 | kernel_cap_t inheritable; |
| 91 | union { |
| 92 | unsigned int fE; /* effective bit of a file capability */ |
| 93 | kernel_cap_t effective; /* effective set of a process */ |
| 94 | }; |
| 95 | }; |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* When fs/namei.c:getname() is called, we store the pointer in name and |
| 98 | * we don't let putname() free it (instead we free all of the saved |
| 99 | * pointers at syscall exit time). |
| 100 | * |
| 101 | * Further, in fs/namei.c:path_lookup() we store the inode and device. */ |
| 102 | struct audit_names { |
| 103 | const char *name; |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 104 | int name_len; /* number of name's characters to log */ |
| 105 | unsigned name_put; /* call __putname() for this name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | unsigned long ino; |
| 107 | dev_t dev; |
| 108 | umode_t mode; |
| 109 | uid_t uid; |
| 110 | gid_t gid; |
| 111 | dev_t rdev; |
Steve Grubb | 1b50eed | 2006-04-03 14:06:13 -0400 | [diff] [blame] | 112 | u32 osid; |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 113 | struct audit_cap_data fcap; |
| 114 | unsigned int fcap_ver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | struct audit_aux_data { |
| 118 | struct audit_aux_data *next; |
| 119 | int type; |
| 120 | }; |
| 121 | |
| 122 | #define AUDIT_AUX_IPCPERM 0 |
| 123 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 124 | /* Number of target pids per aux struct. */ |
| 125 | #define AUDIT_AUX_PIDS 16 |
| 126 | |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 127 | struct audit_aux_data_mq_open { |
| 128 | struct audit_aux_data d; |
| 129 | int oflag; |
| 130 | mode_t mode; |
| 131 | struct mq_attr attr; |
| 132 | }; |
| 133 | |
| 134 | struct audit_aux_data_mq_sendrecv { |
| 135 | struct audit_aux_data d; |
| 136 | mqd_t mqdes; |
| 137 | size_t msg_len; |
| 138 | unsigned int msg_prio; |
| 139 | struct timespec abs_timeout; |
| 140 | }; |
| 141 | |
| 142 | struct audit_aux_data_mq_notify { |
| 143 | struct audit_aux_data d; |
| 144 | mqd_t mqdes; |
| 145 | struct sigevent notification; |
| 146 | }; |
| 147 | |
| 148 | struct audit_aux_data_mq_getsetattr { |
| 149 | struct audit_aux_data d; |
| 150 | mqd_t mqdes; |
| 151 | struct mq_attr mqstat; |
| 152 | }; |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | struct audit_aux_data_ipcctl { |
| 155 | struct audit_aux_data d; |
| 156 | struct ipc_perm p; |
| 157 | unsigned long qbytes; |
| 158 | uid_t uid; |
| 159 | gid_t gid; |
| 160 | mode_t mode; |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 161 | u32 osid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 164 | struct audit_aux_data_execve { |
| 165 | struct audit_aux_data d; |
| 166 | int argc; |
| 167 | int envc; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 168 | struct mm_struct *mm; |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 169 | }; |
| 170 | |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 171 | struct audit_aux_data_socketcall { |
| 172 | struct audit_aux_data d; |
| 173 | int nargs; |
| 174 | unsigned long args[0]; |
| 175 | }; |
| 176 | |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 177 | struct audit_aux_data_fd_pair { |
| 178 | struct audit_aux_data d; |
| 179 | int fd[2]; |
| 180 | }; |
| 181 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 182 | struct audit_aux_data_pids { |
| 183 | struct audit_aux_data d; |
| 184 | pid_t target_pid[AUDIT_AUX_PIDS]; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 185 | uid_t target_auid[AUDIT_AUX_PIDS]; |
| 186 | uid_t target_uid[AUDIT_AUX_PIDS]; |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 187 | unsigned int target_sessionid[AUDIT_AUX_PIDS]; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 188 | u32 target_sid[AUDIT_AUX_PIDS]; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 189 | char target_comm[AUDIT_AUX_PIDS][TASK_COMM_LEN]; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 190 | int pid_count; |
| 191 | }; |
| 192 | |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 193 | struct audit_aux_data_bprm_fcaps { |
| 194 | struct audit_aux_data d; |
| 195 | struct audit_cap_data fcap; |
| 196 | unsigned int fcap_ver; |
| 197 | struct audit_cap_data old_pcap; |
| 198 | struct audit_cap_data new_pcap; |
| 199 | }; |
| 200 | |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 201 | struct audit_aux_data_capset { |
| 202 | struct audit_aux_data d; |
| 203 | pid_t pid; |
| 204 | struct audit_cap_data cap; |
| 205 | }; |
| 206 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 207 | struct audit_tree_refs { |
| 208 | struct audit_tree_refs *next; |
| 209 | struct audit_chunk *c[31]; |
| 210 | }; |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* The per-task audit context. */ |
| 213 | struct audit_context { |
Al Viro | d51374a | 2006-08-03 10:59:26 -0400 | [diff] [blame] | 214 | int dummy; /* must be the first element */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | int in_syscall; /* 1 if task is in a syscall */ |
| 216 | enum audit_state state; |
| 217 | unsigned int serial; /* serial number for record */ |
| 218 | struct timespec ctime; /* time of syscall entry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | int major; /* syscall number */ |
| 220 | unsigned long argv[4]; /* syscall arguments */ |
| 221 | int return_valid; /* return code is valid */ |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 222 | long return_code;/* syscall return code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | int auditable; /* 1 if record should be written */ |
| 224 | int name_count; |
| 225 | struct audit_names names[AUDIT_NAMES]; |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 226 | char * filterkey; /* key for rule that triggered record */ |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 227 | struct path pwd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | struct audit_context *previous; /* For nested syscalls */ |
| 229 | struct audit_aux_data *aux; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 230 | struct audit_aux_data *aux_pids; |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 231 | struct sockaddr_storage *sockaddr; |
| 232 | size_t sockaddr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* Save things to print about task_struct */ |
Al Viro | f46038f | 2006-05-06 08:22:52 -0400 | [diff] [blame] | 234 | pid_t pid, ppid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | uid_t uid, euid, suid, fsuid; |
| 236 | gid_t gid, egid, sgid, fsgid; |
| 237 | unsigned long personality; |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 238 | int arch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 240 | pid_t target_pid; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 241 | uid_t target_auid; |
| 242 | uid_t target_uid; |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 243 | unsigned int target_sessionid; |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 244 | u32 target_sid; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 245 | char target_comm[TASK_COMM_LEN]; |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 246 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 247 | struct audit_tree_refs *trees, *first_trees; |
| 248 | int tree_count; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | #if AUDIT_DEBUG |
| 251 | int put_count; |
| 252 | int ino_count; |
| 253 | #endif |
| 254 | }; |
| 255 | |
Al Viro | 55669bf | 2006-08-31 19:26:40 -0400 | [diff] [blame] | 256 | #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE]) |
| 257 | static inline int open_arg(int flags, int mask) |
| 258 | { |
| 259 | int n = ACC_MODE(flags); |
| 260 | if (flags & (O_TRUNC | O_CREAT)) |
| 261 | n |= AUDIT_PERM_WRITE; |
| 262 | return n & mask; |
| 263 | } |
| 264 | |
| 265 | static int audit_match_perm(struct audit_context *ctx, int mask) |
| 266 | { |
Cordelia | c4bacef | 2008-08-18 09:45:51 -0700 | [diff] [blame] | 267 | unsigned n; |
zhangxiliang | 1a61c88 | 2008-08-02 10:56:37 +0800 | [diff] [blame] | 268 | if (unlikely(!ctx)) |
| 269 | return 0; |
Cordelia | c4bacef | 2008-08-18 09:45:51 -0700 | [diff] [blame] | 270 | n = ctx->major; |
Alan Cox | dbda4c0 | 2008-10-13 10:40:53 +0100 | [diff] [blame] | 271 | |
Al Viro | 55669bf | 2006-08-31 19:26:40 -0400 | [diff] [blame] | 272 | switch (audit_classify_syscall(ctx->arch, n)) { |
| 273 | case 0: /* native */ |
| 274 | if ((mask & AUDIT_PERM_WRITE) && |
| 275 | audit_match_class(AUDIT_CLASS_WRITE, n)) |
| 276 | return 1; |
| 277 | if ((mask & AUDIT_PERM_READ) && |
| 278 | audit_match_class(AUDIT_CLASS_READ, n)) |
| 279 | return 1; |
| 280 | if ((mask & AUDIT_PERM_ATTR) && |
| 281 | audit_match_class(AUDIT_CLASS_CHATTR, n)) |
| 282 | return 1; |
| 283 | return 0; |
| 284 | case 1: /* 32bit on biarch */ |
| 285 | if ((mask & AUDIT_PERM_WRITE) && |
| 286 | audit_match_class(AUDIT_CLASS_WRITE_32, n)) |
| 287 | return 1; |
| 288 | if ((mask & AUDIT_PERM_READ) && |
| 289 | audit_match_class(AUDIT_CLASS_READ_32, n)) |
| 290 | return 1; |
| 291 | if ((mask & AUDIT_PERM_ATTR) && |
| 292 | audit_match_class(AUDIT_CLASS_CHATTR_32, n)) |
| 293 | return 1; |
| 294 | return 0; |
| 295 | case 2: /* open */ |
| 296 | return mask & ACC_MODE(ctx->argv[1]); |
| 297 | case 3: /* openat */ |
| 298 | return mask & ACC_MODE(ctx->argv[2]); |
| 299 | case 4: /* socketcall */ |
| 300 | return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND); |
| 301 | case 5: /* execve */ |
| 302 | return mask & AUDIT_PERM_EXEC; |
| 303 | default: |
| 304 | return 0; |
| 305 | } |
| 306 | } |
| 307 | |
Al Viro | 8b67dca | 2008-04-28 04:15:49 -0400 | [diff] [blame] | 308 | static int audit_match_filetype(struct audit_context *ctx, int which) |
| 309 | { |
| 310 | unsigned index = which & ~S_IFMT; |
| 311 | mode_t mode = which & S_IFMT; |
zhangxiliang | 1a61c88 | 2008-08-02 10:56:37 +0800 | [diff] [blame] | 312 | |
| 313 | if (unlikely(!ctx)) |
| 314 | return 0; |
| 315 | |
Al Viro | 8b67dca | 2008-04-28 04:15:49 -0400 | [diff] [blame] | 316 | if (index >= ctx->name_count) |
| 317 | return 0; |
| 318 | if (ctx->names[index].ino == -1) |
| 319 | return 0; |
| 320 | if ((ctx->names[index].mode ^ mode) & S_IFMT) |
| 321 | return 0; |
| 322 | return 1; |
| 323 | } |
| 324 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 325 | /* |
| 326 | * We keep a linked list of fixed-sized (31 pointer) arrays of audit_chunk *; |
| 327 | * ->first_trees points to its beginning, ->trees - to the current end of data. |
| 328 | * ->tree_count is the number of free entries in array pointed to by ->trees. |
| 329 | * Original condition is (NULL, NULL, 0); as soon as it grows we never revert to NULL, |
| 330 | * "empty" becomes (p, p, 31) afterwards. We don't shrink the list (and seriously, |
| 331 | * it's going to remain 1-element for almost any setup) until we free context itself. |
| 332 | * References in it _are_ dropped - at the same time we free/drop aux stuff. |
| 333 | */ |
| 334 | |
| 335 | #ifdef CONFIG_AUDIT_TREE |
| 336 | static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) |
| 337 | { |
| 338 | struct audit_tree_refs *p = ctx->trees; |
| 339 | int left = ctx->tree_count; |
| 340 | if (likely(left)) { |
| 341 | p->c[--left] = chunk; |
| 342 | ctx->tree_count = left; |
| 343 | return 1; |
| 344 | } |
| 345 | if (!p) |
| 346 | return 0; |
| 347 | p = p->next; |
| 348 | if (p) { |
| 349 | p->c[30] = chunk; |
| 350 | ctx->trees = p; |
| 351 | ctx->tree_count = 30; |
| 352 | return 1; |
| 353 | } |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static int grow_tree_refs(struct audit_context *ctx) |
| 358 | { |
| 359 | struct audit_tree_refs *p = ctx->trees; |
| 360 | ctx->trees = kzalloc(sizeof(struct audit_tree_refs), GFP_KERNEL); |
| 361 | if (!ctx->trees) { |
| 362 | ctx->trees = p; |
| 363 | return 0; |
| 364 | } |
| 365 | if (p) |
| 366 | p->next = ctx->trees; |
| 367 | else |
| 368 | ctx->first_trees = ctx->trees; |
| 369 | ctx->tree_count = 31; |
| 370 | return 1; |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | static void unroll_tree_refs(struct audit_context *ctx, |
| 375 | struct audit_tree_refs *p, int count) |
| 376 | { |
| 377 | #ifdef CONFIG_AUDIT_TREE |
| 378 | struct audit_tree_refs *q; |
| 379 | int n; |
| 380 | if (!p) { |
| 381 | /* we started with empty chain */ |
| 382 | p = ctx->first_trees; |
| 383 | count = 31; |
| 384 | /* if the very first allocation has failed, nothing to do */ |
| 385 | if (!p) |
| 386 | return; |
| 387 | } |
| 388 | n = count; |
| 389 | for (q = p; q != ctx->trees; q = q->next, n = 31) { |
| 390 | while (n--) { |
| 391 | audit_put_chunk(q->c[n]); |
| 392 | q->c[n] = NULL; |
| 393 | } |
| 394 | } |
| 395 | while (n-- > ctx->tree_count) { |
| 396 | audit_put_chunk(q->c[n]); |
| 397 | q->c[n] = NULL; |
| 398 | } |
| 399 | ctx->trees = p; |
| 400 | ctx->tree_count = count; |
| 401 | #endif |
| 402 | } |
| 403 | |
| 404 | static void free_tree_refs(struct audit_context *ctx) |
| 405 | { |
| 406 | struct audit_tree_refs *p, *q; |
| 407 | for (p = ctx->first_trees; p; p = q) { |
| 408 | q = p->next; |
| 409 | kfree(p); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | static int match_tree_refs(struct audit_context *ctx, struct audit_tree *tree) |
| 414 | { |
| 415 | #ifdef CONFIG_AUDIT_TREE |
| 416 | struct audit_tree_refs *p; |
| 417 | int n; |
| 418 | if (!tree) |
| 419 | return 0; |
| 420 | /* full ones */ |
| 421 | for (p = ctx->first_trees; p != ctx->trees; p = p->next) { |
| 422 | for (n = 0; n < 31; n++) |
| 423 | if (audit_tree_match(p->c[n], tree)) |
| 424 | return 1; |
| 425 | } |
| 426 | /* partial */ |
| 427 | if (p) { |
| 428 | for (n = ctx->tree_count; n < 31; n++) |
| 429 | if (audit_tree_match(p->c[n], tree)) |
| 430 | return 1; |
| 431 | } |
| 432 | #endif |
| 433 | return 0; |
| 434 | } |
| 435 | |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 436 | /* Determine if any context name data matches a rule's watch data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | /* Compare a task_struct with an audit_rule. Return 1 on match, 0 |
| 438 | * otherwise. */ |
| 439 | static int audit_filter_rules(struct task_struct *tsk, |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 440 | struct audit_krule *rule, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | struct audit_context *ctx, |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 442 | struct audit_names *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | enum audit_state *state) |
| 444 | { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 445 | const struct cred *cred = get_task_cred(tsk); |
Steve Grubb | 2ad312d | 2006-04-11 08:50:56 -0400 | [diff] [blame] | 446 | int i, j, need_sid = 1; |
Darrel Goeddel | 3dc7e31 | 2006-03-10 18:14:06 -0600 | [diff] [blame] | 447 | u32 sid; |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | for (i = 0; i < rule->field_count; i++) { |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 450 | struct audit_field *f = &rule->fields[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | int result = 0; |
| 452 | |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 453 | switch (f->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | case AUDIT_PID: |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 455 | result = audit_comparator(tsk->pid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | break; |
Al Viro | 3c66251 | 2006-05-06 08:26:27 -0400 | [diff] [blame] | 457 | case AUDIT_PPID: |
Alexander Viro | 419c58f | 2006-09-29 00:08:50 -0400 | [diff] [blame] | 458 | if (ctx) { |
| 459 | if (!ctx->ppid) |
| 460 | ctx->ppid = sys_getppid(); |
Al Viro | 3c66251 | 2006-05-06 08:26:27 -0400 | [diff] [blame] | 461 | result = audit_comparator(ctx->ppid, f->op, f->val); |
Alexander Viro | 419c58f | 2006-09-29 00:08:50 -0400 | [diff] [blame] | 462 | } |
Al Viro | 3c66251 | 2006-05-06 08:26:27 -0400 | [diff] [blame] | 463 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | case AUDIT_UID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 465 | result = audit_comparator(cred->uid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | break; |
| 467 | case AUDIT_EUID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 468 | result = audit_comparator(cred->euid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | break; |
| 470 | case AUDIT_SUID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 471 | result = audit_comparator(cred->suid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | break; |
| 473 | case AUDIT_FSUID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 474 | result = audit_comparator(cred->fsuid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | break; |
| 476 | case AUDIT_GID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 477 | result = audit_comparator(cred->gid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | break; |
| 479 | case AUDIT_EGID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 480 | result = audit_comparator(cred->egid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | break; |
| 482 | case AUDIT_SGID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 483 | result = audit_comparator(cred->sgid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | break; |
| 485 | case AUDIT_FSGID: |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 486 | result = audit_comparator(cred->fsgid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | break; |
| 488 | case AUDIT_PERS: |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 489 | result = audit_comparator(tsk->personality, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | break; |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 491 | case AUDIT_ARCH: |
Daniel Walker | 9f8dbe9 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 492 | if (ctx) |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 493 | result = audit_comparator(ctx->arch, f->op, f->val); |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 494 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | case AUDIT_EXIT: |
| 497 | if (ctx && ctx->return_valid) |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 498 | result = audit_comparator(ctx->return_code, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | break; |
| 500 | case AUDIT_SUCCESS: |
David Woodhouse | b01f2cc | 2005-08-27 10:25:43 +0100 | [diff] [blame] | 501 | if (ctx && ctx->return_valid) { |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 502 | if (f->val) |
| 503 | result = audit_comparator(ctx->return_valid, f->op, AUDITSC_SUCCESS); |
David Woodhouse | b01f2cc | 2005-08-27 10:25:43 +0100 | [diff] [blame] | 504 | else |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 505 | result = audit_comparator(ctx->return_valid, f->op, AUDITSC_FAILURE); |
David Woodhouse | b01f2cc | 2005-08-27 10:25:43 +0100 | [diff] [blame] | 506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | break; |
| 508 | case AUDIT_DEVMAJOR: |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 509 | if (name) |
| 510 | result = audit_comparator(MAJOR(name->dev), |
| 511 | f->op, f->val); |
| 512 | else if (ctx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | for (j = 0; j < ctx->name_count; j++) { |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 514 | if (audit_comparator(MAJOR(ctx->names[j].dev), f->op, f->val)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | ++result; |
| 516 | break; |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | break; |
| 521 | case AUDIT_DEVMINOR: |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 522 | if (name) |
| 523 | result = audit_comparator(MINOR(name->dev), |
| 524 | f->op, f->val); |
| 525 | else if (ctx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | for (j = 0; j < ctx->name_count; j++) { |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 527 | if (audit_comparator(MINOR(ctx->names[j].dev), f->op, f->val)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | ++result; |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | break; |
| 534 | case AUDIT_INODE: |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 535 | if (name) |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 536 | result = (name->ino == f->val); |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 537 | else if (ctx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | for (j = 0; j < ctx->name_count; j++) { |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 539 | if (audit_comparator(ctx->names[j].ino, f->op, f->val)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | ++result; |
| 541 | break; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | break; |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 546 | case AUDIT_WATCH: |
| 547 | if (name && rule->watch->ino != (unsigned long)-1) |
| 548 | result = (name->dev == rule->watch->dev && |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 549 | name->ino == rule->watch->ino); |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 550 | break; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 551 | case AUDIT_DIR: |
| 552 | if (ctx) |
| 553 | result = match_tree_refs(ctx, rule->tree); |
| 554 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | case AUDIT_LOGINUID: |
| 556 | result = 0; |
| 557 | if (ctx) |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 558 | result = audit_comparator(tsk->loginuid, f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 560 | case AUDIT_SUBJ_USER: |
| 561 | case AUDIT_SUBJ_ROLE: |
| 562 | case AUDIT_SUBJ_TYPE: |
| 563 | case AUDIT_SUBJ_SEN: |
| 564 | case AUDIT_SUBJ_CLR: |
Darrel Goeddel | 3dc7e31 | 2006-03-10 18:14:06 -0600 | [diff] [blame] | 565 | /* NOTE: this may return negative values indicating |
| 566 | a temporary error. We simply treat this as a |
| 567 | match for now to avoid losing information that |
| 568 | may be wanted. An error message will also be |
| 569 | logged upon error */ |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 570 | if (f->lsm_rule) { |
Steve Grubb | 2ad312d | 2006-04-11 08:50:56 -0400 | [diff] [blame] | 571 | if (need_sid) { |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 572 | security_task_getsecid(tsk, &sid); |
Steve Grubb | 2ad312d | 2006-04-11 08:50:56 -0400 | [diff] [blame] | 573 | need_sid = 0; |
| 574 | } |
Ahmed S. Darwish | d7a96f3 | 2008-03-01 22:01:11 +0200 | [diff] [blame] | 575 | result = security_audit_rule_match(sid, f->type, |
Darrel Goeddel | 3dc7e31 | 2006-03-10 18:14:06 -0600 | [diff] [blame] | 576 | f->op, |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 577 | f->lsm_rule, |
Darrel Goeddel | 3dc7e31 | 2006-03-10 18:14:06 -0600 | [diff] [blame] | 578 | ctx); |
Steve Grubb | 2ad312d | 2006-04-11 08:50:56 -0400 | [diff] [blame] | 579 | } |
Darrel Goeddel | 3dc7e31 | 2006-03-10 18:14:06 -0600 | [diff] [blame] | 580 | break; |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 581 | case AUDIT_OBJ_USER: |
| 582 | case AUDIT_OBJ_ROLE: |
| 583 | case AUDIT_OBJ_TYPE: |
| 584 | case AUDIT_OBJ_LEV_LOW: |
| 585 | case AUDIT_OBJ_LEV_HIGH: |
| 586 | /* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR |
| 587 | also applies here */ |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 588 | if (f->lsm_rule) { |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 589 | /* Find files that match */ |
| 590 | if (name) { |
Ahmed S. Darwish | d7a96f3 | 2008-03-01 22:01:11 +0200 | [diff] [blame] | 591 | result = security_audit_rule_match( |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 592 | name->osid, f->type, f->op, |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 593 | f->lsm_rule, ctx); |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 594 | } else if (ctx) { |
| 595 | for (j = 0; j < ctx->name_count; j++) { |
Ahmed S. Darwish | d7a96f3 | 2008-03-01 22:01:11 +0200 | [diff] [blame] | 596 | if (security_audit_rule_match( |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 597 | ctx->names[j].osid, |
| 598 | f->type, f->op, |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 599 | f->lsm_rule, ctx)) { |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 600 | ++result; |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | /* Find ipc objects that match */ |
| 606 | if (ctx) { |
| 607 | struct audit_aux_data *aux; |
| 608 | for (aux = ctx->aux; aux; |
| 609 | aux = aux->next) { |
| 610 | if (aux->type == AUDIT_IPC) { |
| 611 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
Ahmed S. Darwish | 04305e4 | 2008-04-19 09:59:43 +1000 | [diff] [blame] | 612 | if (security_audit_rule_match(axi->osid, f->type, f->op, f->lsm_rule, ctx)) { |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 613 | ++result; |
| 614 | break; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | case AUDIT_ARG0: |
| 622 | case AUDIT_ARG1: |
| 623 | case AUDIT_ARG2: |
| 624 | case AUDIT_ARG3: |
| 625 | if (ctx) |
Amy Griffis | 93315ed | 2006-02-07 12:05:27 -0500 | [diff] [blame] | 626 | result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | break; |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 628 | case AUDIT_FILTERKEY: |
| 629 | /* ignore this field for filtering */ |
| 630 | result = 1; |
| 631 | break; |
Al Viro | 55669bf | 2006-08-31 19:26:40 -0400 | [diff] [blame] | 632 | case AUDIT_PERM: |
| 633 | result = audit_match_perm(ctx, f->val); |
| 634 | break; |
Al Viro | 8b67dca | 2008-04-28 04:15:49 -0400 | [diff] [blame] | 635 | case AUDIT_FILETYPE: |
| 636 | result = audit_match_filetype(ctx, f->val); |
| 637 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 640 | if (!result) { |
| 641 | put_cred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return 0; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
zhangxiliang | 980dfb0 | 2008-08-01 19:15:47 +0800 | [diff] [blame] | 645 | if (rule->filterkey && ctx) |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 646 | ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | switch (rule->action) { |
| 648 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break; |
| 650 | } |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 651 | put_cred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | return 1; |
| 653 | } |
| 654 | |
| 655 | /* At process creation time, we can determine if system-call auditing is |
| 656 | * completely disabled for this task. Since we only have the task |
| 657 | * structure at this point, we can only check uid and gid. |
| 658 | */ |
| 659 | static enum audit_state audit_filter_task(struct task_struct *tsk) |
| 660 | { |
| 661 | struct audit_entry *e; |
| 662 | enum audit_state state; |
| 663 | |
| 664 | rcu_read_lock(); |
David Woodhouse | 0f45aa1 | 2005-06-19 19:35:50 +0100 | [diff] [blame] | 665 | list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) { |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 666 | if (audit_filter_rules(tsk, &e->rule, NULL, NULL, &state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | rcu_read_unlock(); |
| 668 | return state; |
| 669 | } |
| 670 | } |
| 671 | rcu_read_unlock(); |
| 672 | return AUDIT_BUILD_CONTEXT; |
| 673 | } |
| 674 | |
| 675 | /* At syscall entry and exit time, this filter is called if the |
| 676 | * audit_state is not low enough that auditing cannot take place, but is |
Steve Grubb | 23f32d1 | 2005-05-13 18:35:15 +0100 | [diff] [blame] | 677 | * also not high enough that we already know we have to write an audit |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 678 | * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | */ |
| 680 | static enum audit_state audit_filter_syscall(struct task_struct *tsk, |
| 681 | struct audit_context *ctx, |
| 682 | struct list_head *list) |
| 683 | { |
| 684 | struct audit_entry *e; |
David Woodhouse | c389649 | 2005-08-17 14:49:57 +0100 | [diff] [blame] | 685 | enum audit_state state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
David Woodhouse | 351bb72 | 2005-07-14 14:40:06 +0100 | [diff] [blame] | 687 | if (audit_pid && tsk->tgid == audit_pid) |
David Woodhouse | f7056d6 | 2005-06-20 16:07:33 +0100 | [diff] [blame] | 688 | return AUDIT_DISABLED; |
| 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | rcu_read_lock(); |
David Woodhouse | c389649 | 2005-08-17 14:49:57 +0100 | [diff] [blame] | 691 | if (!list_empty(list)) { |
Dustin Kirkland | b63862f | 2005-11-03 15:41:46 +0000 | [diff] [blame] | 692 | int word = AUDIT_WORD(ctx->major); |
| 693 | int bit = AUDIT_BIT(ctx->major); |
David Woodhouse | c389649 | 2005-08-17 14:49:57 +0100 | [diff] [blame] | 694 | |
Dustin Kirkland | b63862f | 2005-11-03 15:41:46 +0000 | [diff] [blame] | 695 | list_for_each_entry_rcu(e, list, list) { |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 696 | if ((e->rule.mask[word] & bit) == bit && |
| 697 | audit_filter_rules(tsk, &e->rule, ctx, NULL, |
| 698 | &state)) { |
Dustin Kirkland | b63862f | 2005-11-03 15:41:46 +0000 | [diff] [blame] | 699 | rcu_read_unlock(); |
| 700 | return state; |
| 701 | } |
| 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | rcu_read_unlock(); |
| 705 | return AUDIT_BUILD_CONTEXT; |
| 706 | } |
| 707 | |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 708 | /* At syscall exit time, this filter is called if any audit_names[] have been |
| 709 | * collected during syscall processing. We only check rules in sublists at hash |
| 710 | * buckets applicable to the inode numbers in audit_names[]. |
| 711 | * Regarding audit_state, same rules apply as for audit_filter_syscall(). |
| 712 | */ |
| 713 | enum audit_state audit_filter_inodes(struct task_struct *tsk, |
| 714 | struct audit_context *ctx) |
| 715 | { |
| 716 | int i; |
| 717 | struct audit_entry *e; |
| 718 | enum audit_state state; |
| 719 | |
| 720 | if (audit_pid && tsk->tgid == audit_pid) |
| 721 | return AUDIT_DISABLED; |
| 722 | |
| 723 | rcu_read_lock(); |
| 724 | for (i = 0; i < ctx->name_count; i++) { |
| 725 | int word = AUDIT_WORD(ctx->major); |
| 726 | int bit = AUDIT_BIT(ctx->major); |
| 727 | struct audit_names *n = &ctx->names[i]; |
| 728 | int h = audit_hash_ino((u32)n->ino); |
| 729 | struct list_head *list = &audit_inode_hash[h]; |
| 730 | |
| 731 | if (list_empty(list)) |
| 732 | continue; |
| 733 | |
| 734 | list_for_each_entry_rcu(e, list, list) { |
| 735 | if ((e->rule.mask[word] & bit) == bit && |
| 736 | audit_filter_rules(tsk, &e->rule, ctx, n, &state)) { |
| 737 | rcu_read_unlock(); |
| 738 | return state; |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | rcu_read_unlock(); |
| 743 | return AUDIT_BUILD_CONTEXT; |
| 744 | } |
| 745 | |
| 746 | void audit_set_auditable(struct audit_context *ctx) |
| 747 | { |
| 748 | ctx->auditable = 1; |
| 749 | } |
| 750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | static inline struct audit_context *audit_get_context(struct task_struct *tsk, |
| 752 | int return_valid, |
| 753 | int return_code) |
| 754 | { |
| 755 | struct audit_context *context = tsk->audit_context; |
| 756 | |
| 757 | if (likely(!context)) |
| 758 | return NULL; |
| 759 | context->return_valid = return_valid; |
Eric Paris | f701b75 | 2008-01-07 13:34:51 -0500 | [diff] [blame] | 760 | |
| 761 | /* |
| 762 | * we need to fix up the return code in the audit logs if the actual |
| 763 | * return codes are later going to be fixed up by the arch specific |
| 764 | * signal handlers |
| 765 | * |
| 766 | * This is actually a test for: |
| 767 | * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) || |
| 768 | * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK) |
| 769 | * |
| 770 | * but is faster than a bunch of || |
| 771 | */ |
| 772 | if (unlikely(return_code <= -ERESTARTSYS) && |
| 773 | (return_code >= -ERESTART_RESTARTBLOCK) && |
| 774 | (return_code != -ENOIOCTLCMD)) |
| 775 | context->return_code = -EINTR; |
| 776 | else |
| 777 | context->return_code = return_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Al Viro | d51374a | 2006-08-03 10:59:26 -0400 | [diff] [blame] | 779 | if (context->in_syscall && !context->dummy && !context->auditable) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | enum audit_state state; |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 781 | |
David Woodhouse | 0f45aa1 | 2005-06-19 19:35:50 +0100 | [diff] [blame] | 782 | state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]); |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 783 | if (state == AUDIT_RECORD_CONTEXT) { |
| 784 | context->auditable = 1; |
| 785 | goto get_context; |
| 786 | } |
| 787 | |
| 788 | state = audit_filter_inodes(tsk, context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | if (state == AUDIT_RECORD_CONTEXT) |
| 790 | context->auditable = 1; |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 794 | get_context: |
Al Viro | 3f2792f | 2006-07-16 06:43:48 -0400 | [diff] [blame] | 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | tsk->audit_context = NULL; |
| 797 | return context; |
| 798 | } |
| 799 | |
| 800 | static inline void audit_free_names(struct audit_context *context) |
| 801 | { |
| 802 | int i; |
| 803 | |
| 804 | #if AUDIT_DEBUG == 2 |
| 805 | if (context->auditable |
| 806 | ||context->put_count + context->ino_count != context->name_count) { |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 807 | printk(KERN_ERR "%s:%d(:%d): major=%d in_syscall=%d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | " name_count=%d put_count=%d" |
| 809 | " ino_count=%d [NOT freeing]\n", |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 810 | __FILE__, __LINE__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | context->serial, context->major, context->in_syscall, |
| 812 | context->name_count, context->put_count, |
| 813 | context->ino_count); |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 814 | for (i = 0; i < context->name_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | printk(KERN_ERR "names[%d] = %p = %s\n", i, |
| 816 | context->names[i].name, |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 817 | context->names[i].name ?: "(null)"); |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | dump_stack(); |
| 820 | return; |
| 821 | } |
| 822 | #endif |
| 823 | #if AUDIT_DEBUG |
| 824 | context->put_count = 0; |
| 825 | context->ino_count = 0; |
| 826 | #endif |
| 827 | |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 828 | for (i = 0; i < context->name_count; i++) { |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 829 | if (context->names[i].name && context->names[i].name_put) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | __putname(context->names[i].name); |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | context->name_count = 0; |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 833 | path_put(&context->pwd); |
| 834 | context->pwd.dentry = NULL; |
| 835 | context->pwd.mnt = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static inline void audit_free_aux(struct audit_context *context) |
| 839 | { |
| 840 | struct audit_aux_data *aux; |
| 841 | |
| 842 | while ((aux = context->aux)) { |
| 843 | context->aux = aux->next; |
| 844 | kfree(aux); |
| 845 | } |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 846 | while ((aux = context->aux_pids)) { |
| 847 | context->aux_pids = aux->next; |
| 848 | kfree(aux); |
| 849 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static inline void audit_zero_context(struct audit_context *context, |
| 853 | enum audit_state state) |
| 854 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | memset(context, 0, sizeof(*context)); |
| 856 | context->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static inline struct audit_context *audit_alloc_context(enum audit_state state) |
| 860 | { |
| 861 | struct audit_context *context; |
| 862 | |
| 863 | if (!(context = kmalloc(sizeof(*context), GFP_KERNEL))) |
| 864 | return NULL; |
| 865 | audit_zero_context(context, state); |
| 866 | return context; |
| 867 | } |
| 868 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 869 | /** |
| 870 | * audit_alloc - allocate an audit context block for a task |
| 871 | * @tsk: task |
| 872 | * |
| 873 | * Filter on the task information and allocate a per-task audit context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | * if necessary. Doing so turns on system call auditing for the |
| 875 | * specified task. This is called from copy_process, so no lock is |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 876 | * needed. |
| 877 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | int audit_alloc(struct task_struct *tsk) |
| 879 | { |
| 880 | struct audit_context *context; |
| 881 | enum audit_state state; |
| 882 | |
Eric Paris | b593d38 | 2008-01-08 17:38:31 -0500 | [diff] [blame] | 883 | if (likely(!audit_ever_enabled)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return 0; /* Return if not auditing. */ |
| 885 | |
| 886 | state = audit_filter_task(tsk); |
| 887 | if (likely(state == AUDIT_DISABLED)) |
| 888 | return 0; |
| 889 | |
| 890 | if (!(context = audit_alloc_context(state))) { |
| 891 | audit_log_lost("out of memory in audit_alloc"); |
| 892 | return -ENOMEM; |
| 893 | } |
| 894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | tsk->audit_context = context; |
| 896 | set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT); |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static inline void audit_free_context(struct audit_context *context) |
| 901 | { |
| 902 | struct audit_context *previous; |
| 903 | int count = 0; |
| 904 | |
| 905 | do { |
| 906 | previous = context->previous; |
| 907 | if (previous || (count && count < 10)) { |
| 908 | ++count; |
| 909 | printk(KERN_ERR "audit(:%d): major=%d name_count=%d:" |
| 910 | " freeing multiple contexts (%d)\n", |
| 911 | context->serial, context->major, |
| 912 | context->name_count, count); |
| 913 | } |
| 914 | audit_free_names(context); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 915 | unroll_tree_refs(context, NULL, 0); |
| 916 | free_tree_refs(context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | audit_free_aux(context); |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 918 | kfree(context->filterkey); |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 919 | kfree(context->sockaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | kfree(context); |
| 921 | context = previous; |
| 922 | } while (context); |
| 923 | if (count >= 10) |
| 924 | printk(KERN_ERR "audit: freed %d contexts\n", count); |
| 925 | } |
| 926 | |
Joy Latten | 161a09e | 2006-11-27 13:11:54 -0600 | [diff] [blame] | 927 | void audit_log_task_context(struct audit_buffer *ab) |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 928 | { |
| 929 | char *ctx = NULL; |
Al Viro | c4823bc | 2007-03-12 16:17:42 +0000 | [diff] [blame] | 930 | unsigned len; |
| 931 | int error; |
| 932 | u32 sid; |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 933 | |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 934 | security_task_getsecid(current, &sid); |
Al Viro | c4823bc | 2007-03-12 16:17:42 +0000 | [diff] [blame] | 935 | if (!sid) |
| 936 | return; |
| 937 | |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 938 | error = security_secid_to_secctx(sid, &ctx, &len); |
Al Viro | c4823bc | 2007-03-12 16:17:42 +0000 | [diff] [blame] | 939 | if (error) { |
| 940 | if (error != -EINVAL) |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 941 | goto error_path; |
| 942 | return; |
| 943 | } |
| 944 | |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 945 | audit_log_format(ab, " subj=%s", ctx); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 946 | security_release_secctx(ctx, len); |
Dustin Kirkland | 7306a0b | 2005-11-16 15:53:13 +0000 | [diff] [blame] | 947 | return; |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 948 | |
| 949 | error_path: |
Dustin Kirkland | 7306a0b | 2005-11-16 15:53:13 +0000 | [diff] [blame] | 950 | audit_panic("error in audit_log_task_context"); |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 951 | return; |
| 952 | } |
| 953 | |
Joy Latten | 161a09e | 2006-11-27 13:11:54 -0600 | [diff] [blame] | 954 | EXPORT_SYMBOL(audit_log_task_context); |
| 955 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 956 | static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk) |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 957 | { |
Al Viro | 45d9bb0 | 2006-03-29 20:02:55 -0500 | [diff] [blame] | 958 | char name[sizeof(tsk->comm)]; |
| 959 | struct mm_struct *mm = tsk->mm; |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 960 | struct vm_area_struct *vma; |
| 961 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 962 | /* tsk == current */ |
| 963 | |
Al Viro | 45d9bb0 | 2006-03-29 20:02:55 -0500 | [diff] [blame] | 964 | get_task_comm(name, tsk); |
David Woodhouse | 99e45ee | 2005-05-23 21:57:41 +0100 | [diff] [blame] | 965 | audit_log_format(ab, " comm="); |
| 966 | audit_log_untrustedstring(ab, name); |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 967 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 968 | if (mm) { |
| 969 | down_read(&mm->mmap_sem); |
| 970 | vma = mm->mmap; |
| 971 | while (vma) { |
| 972 | if ((vma->vm_flags & VM_EXECUTABLE) && |
| 973 | vma->vm_file) { |
| 974 | audit_log_d_path(ab, "exe=", |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 975 | &vma->vm_file->f_path); |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 976 | break; |
| 977 | } |
| 978 | vma = vma->vm_next; |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 979 | } |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 980 | up_read(&mm->mmap_sem); |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 981 | } |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 982 | audit_log_task_context(ab); |
Stephen Smalley | 219f081 | 2005-04-18 10:47:35 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 985 | static int audit_log_pid_context(struct audit_context *context, pid_t pid, |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 986 | uid_t auid, uid_t uid, unsigned int sessionid, |
| 987 | u32 sid, char *comm) |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 988 | { |
| 989 | struct audit_buffer *ab; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 990 | char *ctx = NULL; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 991 | u32 len; |
| 992 | int rc = 0; |
| 993 | |
| 994 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID); |
| 995 | if (!ab) |
Eric Paris | 6246cca | 2008-01-07 14:01:18 -0500 | [diff] [blame] | 996 | return rc; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 997 | |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 998 | audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid, |
| 999 | uid, sessionid); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1000 | if (security_secid_to_secctx(sid, &ctx, &len)) { |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1001 | audit_log_format(ab, " obj=(none)"); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1002 | rc = 1; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1003 | } else { |
| 1004 | audit_log_format(ab, " obj=%s", ctx); |
| 1005 | security_release_secctx(ctx, len); |
| 1006 | } |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1007 | audit_log_format(ab, " ocomm="); |
| 1008 | audit_log_untrustedstring(ab, comm); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1009 | audit_log_end(ab); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1010 | |
| 1011 | return rc; |
| 1012 | } |
| 1013 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1014 | /* |
| 1015 | * to_send and len_sent accounting are very loose estimates. We aren't |
| 1016 | * really worried about a hard cap to MAX_EXECVE_AUDIT_LEN so much as being |
| 1017 | * within about 500 bytes (next page boundry) |
| 1018 | * |
| 1019 | * why snprintf? an int is up to 12 digits long. if we just assumed when |
| 1020 | * logging that a[%d]= was going to be 16 characters long we would be wasting |
| 1021 | * space in every audit message. In one 7500 byte message we can log up to |
| 1022 | * about 1000 min size arguments. That comes down to about 50% waste of space |
| 1023 | * if we didn't do the snprintf to find out how long arg_num_len was. |
| 1024 | */ |
| 1025 | static int audit_log_single_execve_arg(struct audit_context *context, |
| 1026 | struct audit_buffer **ab, |
| 1027 | int arg_num, |
| 1028 | size_t *len_sent, |
| 1029 | const char __user *p, |
| 1030 | char *buf) |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1031 | { |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1032 | char arg_num_len_buf[12]; |
| 1033 | const char __user *tmp_p = p; |
| 1034 | /* how many digits are in arg_num? 3 is the length of a=\n */ |
| 1035 | size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 3; |
| 1036 | size_t len, len_left, to_send; |
| 1037 | size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN; |
| 1038 | unsigned int i, has_cntl = 0, too_long = 0; |
| 1039 | int ret; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1040 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1041 | /* strnlen_user includes the null we don't want to send */ |
| 1042 | len_left = len = strnlen_user(p, MAX_ARG_STRLEN) - 1; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1043 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1044 | /* |
| 1045 | * We just created this mm, if we can't find the strings |
| 1046 | * we just copied into it something is _very_ wrong. Similar |
| 1047 | * for strings that are too long, we should not have created |
| 1048 | * any. |
| 1049 | */ |
Eric Paris | b0abcfc | 2008-02-18 18:23:16 -0500 | [diff] [blame] | 1050 | if (unlikely((len == -1) || len > MAX_ARG_STRLEN - 1)) { |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1051 | WARN_ON(1); |
| 1052 | send_sig(SIGKILL, current, 0); |
Eric Paris | b0abcfc | 2008-02-18 18:23:16 -0500 | [diff] [blame] | 1053 | return -1; |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1054 | } |
Peter Zijlstra | 040b3a2 | 2007-07-28 00:55:18 +0200 | [diff] [blame] | 1055 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1056 | /* walk the whole argument looking for non-ascii chars */ |
| 1057 | do { |
| 1058 | if (len_left > MAX_EXECVE_AUDIT_LEN) |
| 1059 | to_send = MAX_EXECVE_AUDIT_LEN; |
| 1060 | else |
| 1061 | to_send = len_left; |
| 1062 | ret = copy_from_user(buf, tmp_p, to_send); |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1063 | /* |
| 1064 | * There is no reason for this copy to be short. We just |
| 1065 | * copied them here, and the mm hasn't been exposed to user- |
| 1066 | * space yet. |
| 1067 | */ |
Peter Zijlstra | 040b3a2 | 2007-07-28 00:55:18 +0200 | [diff] [blame] | 1068 | if (ret) { |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1069 | WARN_ON(1); |
| 1070 | send_sig(SIGKILL, current, 0); |
Eric Paris | b0abcfc | 2008-02-18 18:23:16 -0500 | [diff] [blame] | 1071 | return -1; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1072 | } |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1073 | buf[to_send] = '\0'; |
| 1074 | has_cntl = audit_string_contains_control(buf, to_send); |
| 1075 | if (has_cntl) { |
| 1076 | /* |
| 1077 | * hex messages get logged as 2 bytes, so we can only |
| 1078 | * send half as much in each message |
| 1079 | */ |
| 1080 | max_execve_audit_len = MAX_EXECVE_AUDIT_LEN / 2; |
| 1081 | break; |
| 1082 | } |
| 1083 | len_left -= to_send; |
| 1084 | tmp_p += to_send; |
| 1085 | } while (len_left > 0); |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1086 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1087 | len_left = len; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1088 | |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1089 | if (len > max_execve_audit_len) |
| 1090 | too_long = 1; |
| 1091 | |
| 1092 | /* rewalk the argument actually logging the message */ |
| 1093 | for (i = 0; len_left > 0; i++) { |
| 1094 | int room_left; |
| 1095 | |
| 1096 | if (len_left > max_execve_audit_len) |
| 1097 | to_send = max_execve_audit_len; |
| 1098 | else |
| 1099 | to_send = len_left; |
| 1100 | |
| 1101 | /* do we have space left to send this argument in this ab? */ |
| 1102 | room_left = MAX_EXECVE_AUDIT_LEN - arg_num_len - *len_sent; |
| 1103 | if (has_cntl) |
| 1104 | room_left -= (to_send * 2); |
| 1105 | else |
| 1106 | room_left -= to_send; |
| 1107 | if (room_left < 0) { |
| 1108 | *len_sent = 0; |
| 1109 | audit_log_end(*ab); |
| 1110 | *ab = audit_log_start(context, GFP_KERNEL, AUDIT_EXECVE); |
| 1111 | if (!*ab) |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
| 1115 | /* |
| 1116 | * first record needs to say how long the original string was |
| 1117 | * so we can be sure nothing was lost. |
| 1118 | */ |
| 1119 | if ((i == 0) && (too_long)) |
Paul Moore | 422b03c | 2008-02-27 10:39:22 -0500 | [diff] [blame] | 1120 | audit_log_format(*ab, "a%d_len=%zu ", arg_num, |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1121 | has_cntl ? 2*len : len); |
| 1122 | |
| 1123 | /* |
| 1124 | * normally arguments are small enough to fit and we already |
| 1125 | * filled buf above when we checked for control characters |
| 1126 | * so don't bother with another copy_from_user |
| 1127 | */ |
| 1128 | if (len >= max_execve_audit_len) |
| 1129 | ret = copy_from_user(buf, p, to_send); |
| 1130 | else |
| 1131 | ret = 0; |
| 1132 | if (ret) { |
| 1133 | WARN_ON(1); |
| 1134 | send_sig(SIGKILL, current, 0); |
Eric Paris | b0abcfc | 2008-02-18 18:23:16 -0500 | [diff] [blame] | 1135 | return -1; |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1136 | } |
| 1137 | buf[to_send] = '\0'; |
| 1138 | |
| 1139 | /* actually log it */ |
| 1140 | audit_log_format(*ab, "a%d", arg_num); |
| 1141 | if (too_long) |
| 1142 | audit_log_format(*ab, "[%d]", i); |
| 1143 | audit_log_format(*ab, "="); |
| 1144 | if (has_cntl) |
Eric Paris | b556f8a | 2008-04-18 10:12:59 -0400 | [diff] [blame] | 1145 | audit_log_n_hex(*ab, buf, to_send); |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1146 | else |
| 1147 | audit_log_format(*ab, "\"%s\"", buf); |
| 1148 | audit_log_format(*ab, "\n"); |
| 1149 | |
| 1150 | p += to_send; |
| 1151 | len_left -= to_send; |
| 1152 | *len_sent += arg_num_len; |
| 1153 | if (has_cntl) |
| 1154 | *len_sent += to_send * 2; |
| 1155 | else |
| 1156 | *len_sent += to_send; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1157 | } |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1158 | /* include the null we didn't log */ |
| 1159 | return len + 1; |
| 1160 | } |
| 1161 | |
| 1162 | static void audit_log_execve_info(struct audit_context *context, |
| 1163 | struct audit_buffer **ab, |
| 1164 | struct audit_aux_data_execve *axi) |
| 1165 | { |
| 1166 | int i; |
| 1167 | size_t len, len_sent = 0; |
| 1168 | const char __user *p; |
| 1169 | char *buf; |
| 1170 | |
| 1171 | if (axi->mm != current->mm) |
| 1172 | return; /* execve failed, no additional info */ |
| 1173 | |
| 1174 | p = (const char __user *)axi->mm->arg_start; |
| 1175 | |
| 1176 | audit_log_format(*ab, "argc=%d ", axi->argc); |
| 1177 | |
| 1178 | /* |
| 1179 | * we need some kernel buffer to hold the userspace args. Just |
| 1180 | * allocate one big one rather than allocating one of the right size |
| 1181 | * for every single argument inside audit_log_single_execve_arg() |
| 1182 | * should be <8k allocation so should be pretty safe. |
| 1183 | */ |
| 1184 | buf = kmalloc(MAX_EXECVE_AUDIT_LEN + 1, GFP_KERNEL); |
| 1185 | if (!buf) { |
| 1186 | audit_panic("out of memory for argv string\n"); |
| 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | for (i = 0; i < axi->argc; i++) { |
| 1191 | len = audit_log_single_execve_arg(context, ab, i, |
| 1192 | &len_sent, p, buf); |
| 1193 | if (len <= 0) |
| 1194 | break; |
| 1195 | p += len; |
| 1196 | } |
| 1197 | kfree(buf); |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1200 | static void audit_log_cap(struct audit_buffer *ab, char *prefix, kernel_cap_t *cap) |
| 1201 | { |
| 1202 | int i; |
| 1203 | |
| 1204 | audit_log_format(ab, " %s=", prefix); |
| 1205 | CAP_FOR_EACH_U32(i) { |
| 1206 | audit_log_format(ab, "%08x", cap->cap[(_KERNEL_CAPABILITY_U32S-1) - i]); |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name) |
| 1211 | { |
| 1212 | kernel_cap_t *perm = &name->fcap.permitted; |
| 1213 | kernel_cap_t *inh = &name->fcap.inheritable; |
| 1214 | int log = 0; |
| 1215 | |
| 1216 | if (!cap_isclear(*perm)) { |
| 1217 | audit_log_cap(ab, "cap_fp", perm); |
| 1218 | log = 1; |
| 1219 | } |
| 1220 | if (!cap_isclear(*inh)) { |
| 1221 | audit_log_cap(ab, "cap_fi", inh); |
| 1222 | log = 1; |
| 1223 | } |
| 1224 | |
| 1225 | if (log) |
| 1226 | audit_log_format(ab, " cap_fe=%d cap_fver=%x", name->fcap.fE, name->fcap_ver); |
| 1227 | } |
| 1228 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1229 | static void audit_log_exit(struct audit_context *context, struct task_struct *tsk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1231 | const struct cred *cred; |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1232 | int i, call_panic = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | struct audit_buffer *ab; |
David Woodhouse | 7551ced | 2005-05-26 12:04:57 +0100 | [diff] [blame] | 1234 | struct audit_aux_data *aux; |
Steve Grubb | a6c043a | 2006-01-01 14:07:00 -0500 | [diff] [blame] | 1235 | const char *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1237 | /* tsk == current */ |
Al Viro | 3f2792f | 2006-07-16 06:43:48 -0400 | [diff] [blame] | 1238 | context->pid = tsk->pid; |
Alexander Viro | 419c58f | 2006-09-29 00:08:50 -0400 | [diff] [blame] | 1239 | if (!context->ppid) |
| 1240 | context->ppid = sys_getppid(); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1241 | cred = current_cred(); |
| 1242 | context->uid = cred->uid; |
| 1243 | context->gid = cred->gid; |
| 1244 | context->euid = cred->euid; |
| 1245 | context->suid = cred->suid; |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 1246 | context->fsuid = cred->fsuid; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1247 | context->egid = cred->egid; |
| 1248 | context->sgid = cred->sgid; |
David Howells | b6dff3e | 2008-11-14 10:39:16 +1100 | [diff] [blame] | 1249 | context->fsgid = cred->fsgid; |
Al Viro | 3f2792f | 2006-07-16 06:43:48 -0400 | [diff] [blame] | 1250 | context->personality = tsk->personality; |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1251 | |
| 1252 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | if (!ab) |
| 1254 | return; /* audit_panic has been called */ |
David Woodhouse | bccf6ae | 2005-05-23 21:35:28 +0100 | [diff] [blame] | 1255 | audit_log_format(ab, "arch=%x syscall=%d", |
| 1256 | context->arch, context->major); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | if (context->personality != PER_LINUX) |
| 1258 | audit_log_format(ab, " per=%lx", context->personality); |
| 1259 | if (context->return_valid) |
Daniel Walker | 9f8dbe9 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 1260 | audit_log_format(ab, " success=%s exit=%ld", |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 1261 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", |
| 1262 | context->return_code); |
Alan Cox | eb84a20 | 2006-09-29 02:01:41 -0700 | [diff] [blame] | 1263 | |
Alan Cox | dbda4c0 | 2008-10-13 10:40:53 +0100 | [diff] [blame] | 1264 | spin_lock_irq(&tsk->sighand->siglock); |
Al Viro | 45d9bb0 | 2006-03-29 20:02:55 -0500 | [diff] [blame] | 1265 | if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name) |
| 1266 | tty = tsk->signal->tty->name; |
Steve Grubb | a6c043a | 2006-01-01 14:07:00 -0500 | [diff] [blame] | 1267 | else |
| 1268 | tty = "(none)"; |
Alan Cox | dbda4c0 | 2008-10-13 10:40:53 +0100 | [diff] [blame] | 1269 | spin_unlock_irq(&tsk->sighand->siglock); |
| 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | audit_log_format(ab, |
| 1272 | " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" |
Al Viro | f46038f | 2006-05-06 08:22:52 -0400 | [diff] [blame] | 1273 | " ppid=%d pid=%d auid=%u uid=%u gid=%u" |
Steve Grubb | 326e9c8 | 2005-05-21 00:22:31 +0100 | [diff] [blame] | 1274 | " euid=%u suid=%u fsuid=%u" |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 1275 | " egid=%u sgid=%u fsgid=%u tty=%s ses=%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | context->argv[0], |
| 1277 | context->argv[1], |
| 1278 | context->argv[2], |
| 1279 | context->argv[3], |
| 1280 | context->name_count, |
Al Viro | f46038f | 2006-05-06 08:22:52 -0400 | [diff] [blame] | 1281 | context->ppid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | context->pid, |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 1283 | tsk->loginuid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | context->uid, |
| 1285 | context->gid, |
| 1286 | context->euid, context->suid, context->fsuid, |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 1287 | context->egid, context->sgid, context->fsgid, tty, |
| 1288 | tsk->sessionid); |
Alan Cox | eb84a20 | 2006-09-29 02:01:41 -0700 | [diff] [blame] | 1289 | |
Alan Cox | eb84a20 | 2006-09-29 02:01:41 -0700 | [diff] [blame] | 1290 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1291 | audit_log_task_info(ab, tsk); |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 1292 | if (context->filterkey) { |
| 1293 | audit_log_format(ab, " key="); |
| 1294 | audit_log_untrustedstring(ab, context->filterkey); |
| 1295 | } else |
| 1296 | audit_log_format(ab, " key=(null)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | audit_log_end(ab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
David Woodhouse | 7551ced | 2005-05-26 12:04:57 +0100 | [diff] [blame] | 1299 | for (aux = context->aux; aux; aux = aux->next) { |
Steve Grubb | c040499 | 2005-05-13 18:17:42 +0100 | [diff] [blame] | 1300 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1301 | ab = audit_log_start(context, GFP_KERNEL, aux->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | if (!ab) |
| 1303 | continue; /* audit_panic has been called */ |
| 1304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | switch (aux->type) { |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 1306 | case AUDIT_MQ_OPEN: { |
| 1307 | struct audit_aux_data_mq_open *axi = (void *)aux; |
| 1308 | audit_log_format(ab, |
| 1309 | "oflag=0x%x mode=%#o mq_flags=0x%lx mq_maxmsg=%ld " |
| 1310 | "mq_msgsize=%ld mq_curmsgs=%ld", |
| 1311 | axi->oflag, axi->mode, axi->attr.mq_flags, |
| 1312 | axi->attr.mq_maxmsg, axi->attr.mq_msgsize, |
| 1313 | axi->attr.mq_curmsgs); |
| 1314 | break; } |
| 1315 | |
| 1316 | case AUDIT_MQ_SENDRECV: { |
| 1317 | struct audit_aux_data_mq_sendrecv *axi = (void *)aux; |
| 1318 | audit_log_format(ab, |
| 1319 | "mqdes=%d msg_len=%zd msg_prio=%u " |
| 1320 | "abs_timeout_sec=%ld abs_timeout_nsec=%ld", |
| 1321 | axi->mqdes, axi->msg_len, axi->msg_prio, |
| 1322 | axi->abs_timeout.tv_sec, axi->abs_timeout.tv_nsec); |
| 1323 | break; } |
| 1324 | |
| 1325 | case AUDIT_MQ_NOTIFY: { |
| 1326 | struct audit_aux_data_mq_notify *axi = (void *)aux; |
| 1327 | audit_log_format(ab, |
| 1328 | "mqdes=%d sigev_signo=%d", |
| 1329 | axi->mqdes, |
| 1330 | axi->notification.sigev_signo); |
| 1331 | break; } |
| 1332 | |
| 1333 | case AUDIT_MQ_GETSETATTR: { |
| 1334 | struct audit_aux_data_mq_getsetattr *axi = (void *)aux; |
| 1335 | audit_log_format(ab, |
| 1336 | "mqdes=%d mq_flags=0x%lx mq_maxmsg=%ld mq_msgsize=%ld " |
| 1337 | "mq_curmsgs=%ld ", |
| 1338 | axi->mqdes, |
| 1339 | axi->mqstat.mq_flags, axi->mqstat.mq_maxmsg, |
| 1340 | axi->mqstat.mq_msgsize, axi->mqstat.mq_curmsgs); |
| 1341 | break; } |
| 1342 | |
Steve Grubb | c040499 | 2005-05-13 18:17:42 +0100 | [diff] [blame] | 1343 | case AUDIT_IPC: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
| 1345 | audit_log_format(ab, |
Steve Grubb | 5b9a426 | 2007-05-29 10:38:18 -0400 | [diff] [blame] | 1346 | "ouid=%u ogid=%u mode=%#o", |
Linda Knippers | ac03221 | 2006-05-16 22:03:48 -0400 | [diff] [blame] | 1347 | axi->uid, axi->gid, axi->mode); |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1348 | if (axi->osid != 0) { |
| 1349 | char *ctx = NULL; |
| 1350 | u32 len; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1351 | if (security_secid_to_secctx( |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1352 | axi->osid, &ctx, &len)) { |
Steve Grubb | ce29b68 | 2006-04-01 18:29:34 -0500 | [diff] [blame] | 1353 | audit_log_format(ab, " osid=%u", |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1354 | axi->osid); |
| 1355 | call_panic = 1; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1356 | } else { |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1357 | audit_log_format(ab, " obj=%s", ctx); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1358 | security_release_secctx(ctx, len); |
| 1359 | } |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1360 | } |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 1361 | break; } |
| 1362 | |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 1363 | case AUDIT_IPC_SET_PERM: { |
| 1364 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
| 1365 | audit_log_format(ab, |
Steve Grubb | 5b9a426 | 2007-05-29 10:38:18 -0400 | [diff] [blame] | 1366 | "qbytes=%lx ouid=%u ogid=%u mode=%#o", |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 1367 | axi->qbytes, axi->uid, axi->gid, axi->mode); |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 1368 | break; } |
Linda Knippers | ac03221 | 2006-05-16 22:03:48 -0400 | [diff] [blame] | 1369 | |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 1370 | case AUDIT_EXECVE: { |
| 1371 | struct audit_aux_data_execve *axi = (void *)aux; |
Eric Paris | de6bbd1 | 2008-01-07 14:31:58 -0500 | [diff] [blame] | 1372 | audit_log_execve_info(context, &ab, axi); |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 1373 | break; } |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 1374 | |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 1375 | case AUDIT_SOCKETCALL: { |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 1376 | struct audit_aux_data_socketcall *axs = (void *)aux; |
| 1377 | audit_log_format(ab, "nargs=%d", axs->nargs); |
| 1378 | for (i=0; i<axs->nargs; i++) |
| 1379 | audit_log_format(ab, " a%d=%lx", i, axs->args[i]); |
| 1380 | break; } |
| 1381 | |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 1382 | case AUDIT_FD_PAIR: { |
| 1383 | struct audit_aux_data_fd_pair *axs = (void *)aux; |
| 1384 | audit_log_format(ab, "fd0=%d fd1=%d", axs->fd[0], axs->fd[1]); |
| 1385 | break; } |
| 1386 | |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 1387 | case AUDIT_BPRM_FCAPS: { |
| 1388 | struct audit_aux_data_bprm_fcaps *axs = (void *)aux; |
| 1389 | audit_log_format(ab, "fver=%x", axs->fcap_ver); |
| 1390 | audit_log_cap(ab, "fp", &axs->fcap.permitted); |
| 1391 | audit_log_cap(ab, "fi", &axs->fcap.inheritable); |
| 1392 | audit_log_format(ab, " fe=%d", axs->fcap.fE); |
| 1393 | audit_log_cap(ab, "old_pp", &axs->old_pcap.permitted); |
| 1394 | audit_log_cap(ab, "old_pi", &axs->old_pcap.inheritable); |
| 1395 | audit_log_cap(ab, "old_pe", &axs->old_pcap.effective); |
| 1396 | audit_log_cap(ab, "new_pp", &axs->new_pcap.permitted); |
| 1397 | audit_log_cap(ab, "new_pi", &axs->new_pcap.inheritable); |
| 1398 | audit_log_cap(ab, "new_pe", &axs->new_pcap.effective); |
| 1399 | break; } |
| 1400 | |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 1401 | case AUDIT_CAPSET: { |
| 1402 | struct audit_aux_data_capset *axs = (void *)aux; |
| 1403 | audit_log_format(ab, "pid=%d", axs->pid); |
| 1404 | audit_log_cap(ab, "cap_pi", &axs->cap.inheritable); |
| 1405 | audit_log_cap(ab, "cap_pp", &axs->cap.permitted); |
| 1406 | audit_log_cap(ab, "cap_pe", &axs->cap.effective); |
| 1407 | break; } |
| 1408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | } |
| 1410 | audit_log_end(ab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 1413 | if (context->sockaddr_len) { |
| 1414 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_SOCKADDR); |
| 1415 | if (ab) { |
| 1416 | audit_log_format(ab, "saddr="); |
| 1417 | audit_log_n_hex(ab, (void *)context->sockaddr, |
| 1418 | context->sockaddr_len); |
| 1419 | audit_log_end(ab); |
| 1420 | } |
| 1421 | } |
| 1422 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1423 | for (aux = context->aux_pids; aux; aux = aux->next) { |
| 1424 | struct audit_aux_data_pids *axs = (void *)aux; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1425 | |
| 1426 | for (i = 0; i < axs->pid_count; i++) |
| 1427 | if (audit_log_pid_context(context, axs->target_pid[i], |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1428 | axs->target_auid[i], |
| 1429 | axs->target_uid[i], |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 1430 | axs->target_sessionid[i], |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1431 | axs->target_sid[i], |
| 1432 | axs->target_comm[i])) |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1433 | call_panic = 1; |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1436 | if (context->target_pid && |
| 1437 | audit_log_pid_context(context, context->target_pid, |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1438 | context->target_auid, context->target_uid, |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 1439 | context->target_sessionid, |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 1440 | context->target_sid, context->target_comm)) |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1441 | call_panic = 1; |
| 1442 | |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 1443 | if (context->pwd.dentry && context->pwd.mnt) { |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1444 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD); |
David Woodhouse | 8f37d47 | 2005-05-27 12:17:28 +0100 | [diff] [blame] | 1445 | if (ab) { |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 1446 | audit_log_d_path(ab, "cwd=", &context->pwd); |
David Woodhouse | 8f37d47 | 2005-05-27 12:17:28 +0100 | [diff] [blame] | 1447 | audit_log_end(ab); |
| 1448 | } |
| 1449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | for (i = 0; i < context->name_count; i++) { |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1451 | struct audit_names *n = &context->names[i]; |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1452 | |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1453 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | if (!ab) |
| 1455 | continue; /* audit_panic has been called */ |
David Woodhouse | 8f37d47 | 2005-05-27 12:17:28 +0100 | [diff] [blame] | 1456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | audit_log_format(ab, "item=%d", i); |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1458 | |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1459 | if (n->name) { |
| 1460 | switch(n->name_len) { |
| 1461 | case AUDIT_NAME_FULL: |
| 1462 | /* log the full path */ |
| 1463 | audit_log_format(ab, " name="); |
| 1464 | audit_log_untrustedstring(ab, n->name); |
| 1465 | break; |
| 1466 | case 0: |
| 1467 | /* name was specified as a relative path and the |
| 1468 | * directory component is the cwd */ |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 1469 | audit_log_d_path(ab, " name=", &context->pwd); |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1470 | break; |
| 1471 | default: |
| 1472 | /* log the name's directory component */ |
| 1473 | audit_log_format(ab, " name="); |
Eric Paris | b556f8a | 2008-04-18 10:12:59 -0400 | [diff] [blame] | 1474 | audit_log_n_untrustedstring(ab, n->name, |
| 1475 | n->name_len); |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1476 | } |
| 1477 | } else |
| 1478 | audit_log_format(ab, " name=(null)"); |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1479 | |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1480 | if (n->ino != (unsigned long)-1) { |
| 1481 | audit_log_format(ab, " inode=%lu" |
| 1482 | " dev=%02x:%02x mode=%#o" |
| 1483 | " ouid=%u ogid=%u rdev=%02x:%02x", |
| 1484 | n->ino, |
| 1485 | MAJOR(n->dev), |
| 1486 | MINOR(n->dev), |
| 1487 | n->mode, |
| 1488 | n->uid, |
| 1489 | n->gid, |
| 1490 | MAJOR(n->rdev), |
| 1491 | MINOR(n->rdev)); |
| 1492 | } |
| 1493 | if (n->osid != 0) { |
Steve Grubb | 1b50eed | 2006-04-03 14:06:13 -0400 | [diff] [blame] | 1494 | char *ctx = NULL; |
| 1495 | u32 len; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1496 | if (security_secid_to_secctx( |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1497 | n->osid, &ctx, &len)) { |
| 1498 | audit_log_format(ab, " osid=%u", n->osid); |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1499 | call_panic = 2; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1500 | } else { |
Steve Grubb | 1b50eed | 2006-04-03 14:06:13 -0400 | [diff] [blame] | 1501 | audit_log_format(ab, " obj=%s", ctx); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1502 | security_release_secctx(ctx, len); |
| 1503 | } |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1506 | audit_log_fcaps(ab, n); |
| 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | audit_log_end(ab); |
| 1509 | } |
Eric Paris | c0641f2 | 2008-01-07 13:49:15 -0500 | [diff] [blame] | 1510 | |
| 1511 | /* Send end of event record to help user space know we are finished */ |
| 1512 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE); |
| 1513 | if (ab) |
| 1514 | audit_log_end(ab); |
Steve Grubb | 9c7aa6a | 2006-03-31 15:22:49 -0500 | [diff] [blame] | 1515 | if (call_panic) |
| 1516 | audit_panic("error converting sid to string"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1519 | /** |
| 1520 | * audit_free - free a per-task audit context |
| 1521 | * @tsk: task whose audit context block to free |
| 1522 | * |
Al Viro | fa84cb9 | 2006-03-29 20:30:19 -0500 | [diff] [blame] | 1523 | * Called from copy_process and do_exit |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1524 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | void audit_free(struct task_struct *tsk) |
| 1526 | { |
| 1527 | struct audit_context *context; |
| 1528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | context = audit_get_context(tsk, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | if (likely(!context)) |
| 1531 | return; |
| 1532 | |
| 1533 | /* Check for system calls that do not go through the exit |
Daniel Walker | 9f8dbe9 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 1534 | * function (e.g., exit_group), then free context block. |
| 1535 | * We use GFP_ATOMIC here because we might be doing this |
David Woodhouse | f556196 | 2005-07-13 22:47:07 +0100 | [diff] [blame] | 1536 | * in the context of the idle thread */ |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1537 | /* that can happen only if we are called from do_exit() */ |
David Woodhouse | f7056d6 | 2005-06-20 16:07:33 +0100 | [diff] [blame] | 1538 | if (context->in_syscall && context->auditable) |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1539 | audit_log_exit(context, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
| 1541 | audit_free_context(context); |
| 1542 | } |
| 1543 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1544 | /** |
| 1545 | * audit_syscall_entry - fill in an audit record at syscall entry |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1546 | * @arch: architecture type |
| 1547 | * @major: major syscall type (function) |
| 1548 | * @a1: additional syscall register 1 |
| 1549 | * @a2: additional syscall register 2 |
| 1550 | * @a3: additional syscall register 3 |
| 1551 | * @a4: additional syscall register 4 |
| 1552 | * |
| 1553 | * Fill in audit context at syscall entry. This only happens if the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | * audit context was created when the task was created and the state or |
| 1555 | * filters demand the audit context be built. If the state from the |
| 1556 | * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT, |
| 1557 | * then the record will be written at syscall exit time (otherwise, it |
| 1558 | * will only be written if another part of the kernel requests that it |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1559 | * be written). |
| 1560 | */ |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 1561 | void audit_syscall_entry(int arch, int major, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | unsigned long a1, unsigned long a2, |
| 1563 | unsigned long a3, unsigned long a4) |
| 1564 | { |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 1565 | struct task_struct *tsk = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | struct audit_context *context = tsk->audit_context; |
| 1567 | enum audit_state state; |
| 1568 | |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 1569 | if (unlikely(!context)) |
| 1570 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1572 | /* |
| 1573 | * This happens only on certain architectures that make system |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | * calls in kernel_thread via the entry.S interface, instead of |
| 1575 | * with direct calls. (If you are porting to a new |
| 1576 | * architecture, hitting this condition can indicate that you |
| 1577 | * got the _exit/_leave calls backward in entry.S.) |
| 1578 | * |
| 1579 | * i386 no |
| 1580 | * x86_64 no |
Jon Mason | 2ef9481 | 2006-01-23 10:58:20 -0600 | [diff] [blame] | 1581 | * ppc64 yes (see arch/powerpc/platforms/iseries/misc.S) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | * |
| 1583 | * This also happens with vm86 emulation in a non-nested manner |
| 1584 | * (entries without exits), so this case must be caught. |
| 1585 | */ |
| 1586 | if (context->in_syscall) { |
| 1587 | struct audit_context *newctx; |
| 1588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | #if AUDIT_DEBUG |
| 1590 | printk(KERN_ERR |
| 1591 | "audit(:%d) pid=%d in syscall=%d;" |
| 1592 | " entering syscall=%d\n", |
| 1593 | context->serial, tsk->pid, context->major, major); |
| 1594 | #endif |
| 1595 | newctx = audit_alloc_context(context->state); |
| 1596 | if (newctx) { |
| 1597 | newctx->previous = context; |
| 1598 | context = newctx; |
| 1599 | tsk->audit_context = newctx; |
| 1600 | } else { |
| 1601 | /* If we can't alloc a new context, the best we |
| 1602 | * can do is to leak memory (any pending putname |
| 1603 | * will be lost). The only other alternative is |
| 1604 | * to abandon auditing. */ |
| 1605 | audit_zero_context(context, context->state); |
| 1606 | } |
| 1607 | } |
| 1608 | BUG_ON(context->in_syscall || context->name_count); |
| 1609 | |
| 1610 | if (!audit_enabled) |
| 1611 | return; |
| 1612 | |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 1613 | context->arch = arch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | context->major = major; |
| 1615 | context->argv[0] = a1; |
| 1616 | context->argv[1] = a2; |
| 1617 | context->argv[2] = a3; |
| 1618 | context->argv[3] = a4; |
| 1619 | |
| 1620 | state = context->state; |
Al Viro | d51374a | 2006-08-03 10:59:26 -0400 | [diff] [blame] | 1621 | context->dummy = !audit_n_rules; |
| 1622 | if (!context->dummy && (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT)) |
David Woodhouse | 0f45aa1 | 2005-06-19 19:35:50 +0100 | [diff] [blame] | 1623 | state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | if (likely(state == AUDIT_DISABLED)) |
| 1625 | return; |
| 1626 | |
David Woodhouse | ce625a8 | 2005-07-18 14:24:46 -0400 | [diff] [blame] | 1627 | context->serial = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | context->ctime = CURRENT_TIME; |
| 1629 | context->in_syscall = 1; |
| 1630 | context->auditable = !!(state == AUDIT_RECORD_CONTEXT); |
Alexander Viro | 419c58f | 2006-09-29 00:08:50 -0400 | [diff] [blame] | 1631 | context->ppid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Al Viro | a64e649 | 2008-11-12 18:37:41 -0500 | [diff] [blame] | 1634 | void audit_finish_fork(struct task_struct *child) |
| 1635 | { |
| 1636 | struct audit_context *ctx = current->audit_context; |
| 1637 | struct audit_context *p = child->audit_context; |
| 1638 | if (!p || !ctx || !ctx->auditable) |
| 1639 | return; |
| 1640 | p->arch = ctx->arch; |
| 1641 | p->major = ctx->major; |
| 1642 | memcpy(p->argv, ctx->argv, sizeof(ctx->argv)); |
| 1643 | p->ctime = ctx->ctime; |
| 1644 | p->dummy = ctx->dummy; |
| 1645 | p->auditable = ctx->auditable; |
| 1646 | p->in_syscall = ctx->in_syscall; |
| 1647 | p->filterkey = kstrdup(ctx->filterkey, GFP_KERNEL); |
| 1648 | p->ppid = current->pid; |
| 1649 | } |
| 1650 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1651 | /** |
| 1652 | * audit_syscall_exit - deallocate audit context after a system call |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1653 | * @valid: success/failure flag |
| 1654 | * @return_code: syscall return value |
| 1655 | * |
| 1656 | * Tear down after system call. If the audit context has been marked as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | * auditable (either because of the AUDIT_RECORD_CONTEXT state from |
| 1658 | * filtering, or because some other part of the kernel write an audit |
| 1659 | * message), then write out the syscall information. In call cases, |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1660 | * free the names stored from getname(). |
| 1661 | */ |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 1662 | void audit_syscall_exit(int valid, long return_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | { |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 1664 | struct task_struct *tsk = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | struct audit_context *context; |
| 1666 | |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 1667 | context = audit_get_context(tsk, valid, return_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | if (likely(!context)) |
Al Viro | 97e94c4 | 2006-03-29 20:26:24 -0500 | [diff] [blame] | 1670 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
David Woodhouse | f7056d6 | 2005-06-20 16:07:33 +0100 | [diff] [blame] | 1672 | if (context->in_syscall && context->auditable) |
Al Viro | e495149 | 2006-03-29 20:17:10 -0500 | [diff] [blame] | 1673 | audit_log_exit(context, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
| 1675 | context->in_syscall = 0; |
| 1676 | context->auditable = 0; |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | if (context->previous) { |
| 1679 | struct audit_context *new_context = context->previous; |
| 1680 | context->previous = NULL; |
| 1681 | audit_free_context(context); |
| 1682 | tsk->audit_context = new_context; |
| 1683 | } else { |
| 1684 | audit_free_names(context); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1685 | unroll_tree_refs(context, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | audit_free_aux(context); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1687 | context->aux = NULL; |
| 1688 | context->aux_pids = NULL; |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 1689 | context->target_pid = 0; |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 1690 | context->target_sid = 0; |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 1691 | context->sockaddr_len = 0; |
Amy Griffis | 5adc8a6 | 2006-06-14 18:45:21 -0400 | [diff] [blame] | 1692 | kfree(context->filterkey); |
| 1693 | context->filterkey = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | tsk->audit_context = context; |
| 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1698 | static inline void handle_one(const struct inode *inode) |
| 1699 | { |
| 1700 | #ifdef CONFIG_AUDIT_TREE |
| 1701 | struct audit_context *context; |
| 1702 | struct audit_tree_refs *p; |
| 1703 | struct audit_chunk *chunk; |
| 1704 | int count; |
| 1705 | if (likely(list_empty(&inode->inotify_watches))) |
| 1706 | return; |
| 1707 | context = current->audit_context; |
| 1708 | p = context->trees; |
| 1709 | count = context->tree_count; |
| 1710 | rcu_read_lock(); |
| 1711 | chunk = audit_tree_lookup(inode); |
| 1712 | rcu_read_unlock(); |
| 1713 | if (!chunk) |
| 1714 | return; |
| 1715 | if (likely(put_tree_ref(context, chunk))) |
| 1716 | return; |
| 1717 | if (unlikely(!grow_tree_refs(context))) { |
Eric Paris | 436c405 | 2008-04-18 10:01:04 -0400 | [diff] [blame] | 1718 | printk(KERN_WARNING "out of memory, audit has lost a tree reference\n"); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1719 | audit_set_auditable(context); |
| 1720 | audit_put_chunk(chunk); |
| 1721 | unroll_tree_refs(context, p, count); |
| 1722 | return; |
| 1723 | } |
| 1724 | put_tree_ref(context, chunk); |
| 1725 | #endif |
| 1726 | } |
| 1727 | |
| 1728 | static void handle_path(const struct dentry *dentry) |
| 1729 | { |
| 1730 | #ifdef CONFIG_AUDIT_TREE |
| 1731 | struct audit_context *context; |
| 1732 | struct audit_tree_refs *p; |
| 1733 | const struct dentry *d, *parent; |
| 1734 | struct audit_chunk *drop; |
| 1735 | unsigned long seq; |
| 1736 | int count; |
| 1737 | |
| 1738 | context = current->audit_context; |
| 1739 | p = context->trees; |
| 1740 | count = context->tree_count; |
| 1741 | retry: |
| 1742 | drop = NULL; |
| 1743 | d = dentry; |
| 1744 | rcu_read_lock(); |
| 1745 | seq = read_seqbegin(&rename_lock); |
| 1746 | for(;;) { |
| 1747 | struct inode *inode = d->d_inode; |
| 1748 | if (inode && unlikely(!list_empty(&inode->inotify_watches))) { |
| 1749 | struct audit_chunk *chunk; |
| 1750 | chunk = audit_tree_lookup(inode); |
| 1751 | if (chunk) { |
| 1752 | if (unlikely(!put_tree_ref(context, chunk))) { |
| 1753 | drop = chunk; |
| 1754 | break; |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | parent = d->d_parent; |
| 1759 | if (parent == d) |
| 1760 | break; |
| 1761 | d = parent; |
| 1762 | } |
| 1763 | if (unlikely(read_seqretry(&rename_lock, seq) || drop)) { /* in this order */ |
| 1764 | rcu_read_unlock(); |
| 1765 | if (!drop) { |
| 1766 | /* just a race with rename */ |
| 1767 | unroll_tree_refs(context, p, count); |
| 1768 | goto retry; |
| 1769 | } |
| 1770 | audit_put_chunk(drop); |
| 1771 | if (grow_tree_refs(context)) { |
| 1772 | /* OK, got more space */ |
| 1773 | unroll_tree_refs(context, p, count); |
| 1774 | goto retry; |
| 1775 | } |
| 1776 | /* too bad */ |
| 1777 | printk(KERN_WARNING |
Eric Paris | 436c405 | 2008-04-18 10:01:04 -0400 | [diff] [blame] | 1778 | "out of memory, audit has lost a tree reference\n"); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1779 | unroll_tree_refs(context, p, count); |
| 1780 | audit_set_auditable(context); |
| 1781 | return; |
| 1782 | } |
| 1783 | rcu_read_unlock(); |
| 1784 | #endif |
| 1785 | } |
| 1786 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1787 | /** |
| 1788 | * audit_getname - add a name to the list |
| 1789 | * @name: name to add |
| 1790 | * |
| 1791 | * Add a name to the list of audit names for this context. |
| 1792 | * Called from fs/namei.c:getname(). |
| 1793 | */ |
Al Viro | d8945bb5 | 2006-05-18 16:01:30 -0400 | [diff] [blame] | 1794 | void __audit_getname(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | { |
| 1796 | struct audit_context *context = current->audit_context; |
| 1797 | |
Al Viro | d8945bb5 | 2006-05-18 16:01:30 -0400 | [diff] [blame] | 1798 | if (IS_ERR(name) || !name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | return; |
| 1800 | |
| 1801 | if (!context->in_syscall) { |
| 1802 | #if AUDIT_DEBUG == 2 |
| 1803 | printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n", |
| 1804 | __FILE__, __LINE__, context->serial, name); |
| 1805 | dump_stack(); |
| 1806 | #endif |
| 1807 | return; |
| 1808 | } |
| 1809 | BUG_ON(context->name_count >= AUDIT_NAMES); |
| 1810 | context->names[context->name_count].name = name; |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1811 | context->names[context->name_count].name_len = AUDIT_NAME_FULL; |
| 1812 | context->names[context->name_count].name_put = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | context->names[context->name_count].ino = (unsigned long)-1; |
Amy Griffis | e41e8bd | 2007-02-13 14:14:09 -0500 | [diff] [blame] | 1814 | context->names[context->name_count].osid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | ++context->name_count; |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 1816 | if (!context->pwd.dentry) { |
David Woodhouse | 8f37d47 | 2005-05-27 12:17:28 +0100 | [diff] [blame] | 1817 | read_lock(¤t->fs->lock); |
Jan Blunck | 44707fd | 2008-02-14 19:38:33 -0800 | [diff] [blame] | 1818 | context->pwd = current->fs->pwd; |
| 1819 | path_get(¤t->fs->pwd); |
David Woodhouse | 8f37d47 | 2005-05-27 12:17:28 +0100 | [diff] [blame] | 1820 | read_unlock(¤t->fs->lock); |
| 1821 | } |
Daniel Walker | 9f8dbe9 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 1822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1825 | /* audit_putname - intercept a putname request |
| 1826 | * @name: name to intercept and delay for putname |
| 1827 | * |
| 1828 | * If we have stored the name from getname in the audit context, |
| 1829 | * then we delay the putname until syscall exit. |
| 1830 | * Called from include/linux/fs.h:putname(). |
| 1831 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | void audit_putname(const char *name) |
| 1833 | { |
| 1834 | struct audit_context *context = current->audit_context; |
| 1835 | |
| 1836 | BUG_ON(!context); |
| 1837 | if (!context->in_syscall) { |
| 1838 | #if AUDIT_DEBUG == 2 |
| 1839 | printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n", |
| 1840 | __FILE__, __LINE__, context->serial, name); |
| 1841 | if (context->name_count) { |
| 1842 | int i; |
| 1843 | for (i = 0; i < context->name_count; i++) |
| 1844 | printk(KERN_ERR "name[%d] = %p = %s\n", i, |
| 1845 | context->names[i].name, |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1846 | context->names[i].name ?: "(null)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | #endif |
| 1849 | __putname(name); |
| 1850 | } |
| 1851 | #if AUDIT_DEBUG |
| 1852 | else { |
| 1853 | ++context->put_count; |
| 1854 | if (context->put_count > context->name_count) { |
| 1855 | printk(KERN_ERR "%s:%d(:%d): major=%d" |
| 1856 | " in_syscall=%d putname(%p) name_count=%d" |
| 1857 | " put_count=%d\n", |
| 1858 | __FILE__, __LINE__, |
| 1859 | context->serial, context->major, |
| 1860 | context->in_syscall, name, context->name_count, |
| 1861 | context->put_count); |
| 1862 | dump_stack(); |
| 1863 | } |
| 1864 | } |
| 1865 | #endif |
| 1866 | } |
| 1867 | |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1868 | static int audit_inc_name_count(struct audit_context *context, |
| 1869 | const struct inode *inode) |
| 1870 | { |
| 1871 | if (context->name_count >= AUDIT_NAMES) { |
| 1872 | if (inode) |
| 1873 | printk(KERN_DEBUG "name_count maxed, losing inode data: " |
Eric Paris | 436c405 | 2008-04-18 10:01:04 -0400 | [diff] [blame] | 1874 | "dev=%02x:%02x, inode=%lu\n", |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1875 | MAJOR(inode->i_sb->s_dev), |
| 1876 | MINOR(inode->i_sb->s_dev), |
| 1877 | inode->i_ino); |
| 1878 | |
| 1879 | else |
Eric Paris | 436c405 | 2008-04-18 10:01:04 -0400 | [diff] [blame] | 1880 | printk(KERN_DEBUG "name_count maxed, losing inode data\n"); |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1881 | return 1; |
| 1882 | } |
| 1883 | context->name_count++; |
| 1884 | #if AUDIT_DEBUG |
| 1885 | context->ino_count++; |
| 1886 | #endif |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1890 | |
| 1891 | static inline int audit_copy_fcaps(struct audit_names *name, const struct dentry *dentry) |
| 1892 | { |
| 1893 | struct cpu_vfs_cap_data caps; |
| 1894 | int rc; |
| 1895 | |
| 1896 | memset(&name->fcap.permitted, 0, sizeof(kernel_cap_t)); |
| 1897 | memset(&name->fcap.inheritable, 0, sizeof(kernel_cap_t)); |
| 1898 | name->fcap.fE = 0; |
| 1899 | name->fcap_ver = 0; |
| 1900 | |
| 1901 | if (!dentry) |
| 1902 | return 0; |
| 1903 | |
| 1904 | rc = get_vfs_caps_from_disk(dentry, &caps); |
| 1905 | if (rc) |
| 1906 | return rc; |
| 1907 | |
| 1908 | name->fcap.permitted = caps.permitted; |
| 1909 | name->fcap.inheritable = caps.inheritable; |
| 1910 | name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE); |
| 1911 | name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT; |
| 1912 | |
| 1913 | return 0; |
| 1914 | } |
| 1915 | |
| 1916 | |
Amy Griffis | 3e2efce | 2006-07-13 13:16:02 -0400 | [diff] [blame] | 1917 | /* Copy inode data into an audit_names. */ |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1918 | static void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, |
| 1919 | const struct inode *inode) |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 1920 | { |
Amy Griffis | 3e2efce | 2006-07-13 13:16:02 -0400 | [diff] [blame] | 1921 | name->ino = inode->i_ino; |
| 1922 | name->dev = inode->i_sb->s_dev; |
| 1923 | name->mode = inode->i_mode; |
| 1924 | name->uid = inode->i_uid; |
| 1925 | name->gid = inode->i_gid; |
| 1926 | name->rdev = inode->i_rdev; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 1927 | security_inode_getsecid(inode, &name->osid); |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1928 | audit_copy_fcaps(name, dentry); |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1931 | /** |
| 1932 | * audit_inode - store the inode and device from a lookup |
| 1933 | * @name: name being audited |
Randy Dunlap | 481968f | 2007-10-21 20:59:53 -0700 | [diff] [blame] | 1934 | * @dentry: dentry being audited |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 1935 | * |
| 1936 | * Called from fs/namei.c:path_lookup(). |
| 1937 | */ |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 1938 | void __audit_inode(const char *name, const struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | { |
| 1940 | int idx; |
| 1941 | struct audit_context *context = current->audit_context; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1942 | const struct inode *inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
| 1944 | if (!context->in_syscall) |
| 1945 | return; |
| 1946 | if (context->name_count |
| 1947 | && context->names[context->name_count-1].name |
| 1948 | && context->names[context->name_count-1].name == name) |
| 1949 | idx = context->name_count - 1; |
| 1950 | else if (context->name_count > 1 |
| 1951 | && context->names[context->name_count-2].name |
| 1952 | && context->names[context->name_count-2].name == name) |
| 1953 | idx = context->name_count - 2; |
| 1954 | else { |
| 1955 | /* FIXME: how much do we care about inodes that have no |
| 1956 | * associated name? */ |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1957 | if (audit_inc_name_count(context, inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | return; |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1959 | idx = context->name_count - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | context->names[idx].name = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1962 | handle_path(dentry); |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 1963 | audit_copy_inode(&context->names[idx], dentry, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1966 | /** |
| 1967 | * audit_inode_child - collect inode info for created/removed objects |
| 1968 | * @dname: inode's dentry name |
Randy Dunlap | 481968f | 2007-10-21 20:59:53 -0700 | [diff] [blame] | 1969 | * @dentry: dentry being audited |
Amy Griffis | 73d3ec5 | 2006-07-13 13:16:39 -0400 | [diff] [blame] | 1970 | * @parent: inode of dentry parent |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1971 | * |
| 1972 | * For syscalls that create or remove filesystem objects, audit_inode |
| 1973 | * can only collect information for the filesystem object's parent. |
| 1974 | * This call updates the audit context with the child's information. |
| 1975 | * Syscalls that create a new filesystem object must be hooked after |
| 1976 | * the object is created. Syscalls that remove a filesystem object |
| 1977 | * must be hooked prior, in order to capture the target inode during |
| 1978 | * unsuccessful attempts. |
| 1979 | */ |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 1980 | void __audit_inode_child(const char *dname, const struct dentry *dentry, |
Amy Griffis | 73d3ec5 | 2006-07-13 13:16:39 -0400 | [diff] [blame] | 1981 | const struct inode *parent) |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1982 | { |
| 1983 | int idx; |
| 1984 | struct audit_context *context = current->audit_context; |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1985 | const char *found_parent = NULL, *found_child = NULL; |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 1986 | const struct inode *inode = dentry->d_inode; |
Amy Griffis | 9c937dc | 2006-06-08 23:19:31 -0400 | [diff] [blame] | 1987 | int dirlen = 0; |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1988 | |
| 1989 | if (!context->in_syscall) |
| 1990 | return; |
| 1991 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1992 | if (inode) |
| 1993 | handle_one(inode); |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1994 | /* determine matching parent */ |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 1995 | if (!dname) |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1996 | goto add_names; |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 1997 | |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 1998 | /* parent is more likely, look for it first */ |
| 1999 | for (idx = 0; idx < context->name_count; idx++) { |
| 2000 | struct audit_names *n = &context->names[idx]; |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 2001 | |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2002 | if (!n->name) |
| 2003 | continue; |
| 2004 | |
| 2005 | if (n->ino == parent->i_ino && |
| 2006 | !audit_compare_dname_path(dname, n->name, &dirlen)) { |
| 2007 | n->name_len = dirlen; /* update parent data in place */ |
| 2008 | found_parent = n->name; |
| 2009 | goto add_names; |
Amy Griffis | f368c07d | 2006-04-07 16:55:56 -0400 | [diff] [blame] | 2010 | } |
Steve Grubb | ac9910c | 2006-09-28 14:31:32 -0400 | [diff] [blame] | 2011 | } |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 2012 | |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2013 | /* no matching parent, look for matching child */ |
| 2014 | for (idx = 0; idx < context->name_count; idx++) { |
| 2015 | struct audit_names *n = &context->names[idx]; |
Amy Griffis | 73d3ec5 | 2006-07-13 13:16:39 -0400 | [diff] [blame] | 2016 | |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2017 | if (!n->name) |
| 2018 | continue; |
| 2019 | |
| 2020 | /* strcmp() is the more likely scenario */ |
| 2021 | if (!strcmp(dname, n->name) || |
| 2022 | !audit_compare_dname_path(dname, n->name, &dirlen)) { |
| 2023 | if (inode) |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 2024 | audit_copy_inode(n, NULL, inode); |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2025 | else |
| 2026 | n->ino = (unsigned long)-1; |
| 2027 | found_child = n->name; |
| 2028 | goto add_names; |
Steve Grubb | ac9910c | 2006-09-28 14:31:32 -0400 | [diff] [blame] | 2029 | } |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | add_names: |
| 2033 | if (!found_parent) { |
| 2034 | if (audit_inc_name_count(context, parent)) |
| 2035 | return; |
| 2036 | idx = context->name_count - 1; |
| 2037 | context->names[idx].name = NULL; |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 2038 | audit_copy_inode(&context->names[idx], NULL, parent); |
Amy Griffis | 73d3ec5 | 2006-07-13 13:16:39 -0400 | [diff] [blame] | 2039 | } |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2040 | |
| 2041 | if (!found_child) { |
| 2042 | if (audit_inc_name_count(context, inode)) |
| 2043 | return; |
| 2044 | idx = context->name_count - 1; |
| 2045 | |
| 2046 | /* Re-use the name belonging to the slot for a matching parent |
| 2047 | * directory. All names for this context are relinquished in |
| 2048 | * audit_free_names() */ |
| 2049 | if (found_parent) { |
| 2050 | context->names[idx].name = found_parent; |
| 2051 | context->names[idx].name_len = AUDIT_NAME_FULL; |
| 2052 | /* don't call __putname() */ |
| 2053 | context->names[idx].name_put = 0; |
| 2054 | } else { |
| 2055 | context->names[idx].name = NULL; |
| 2056 | } |
| 2057 | |
| 2058 | if (inode) |
Eric Paris | 851f7ff | 2008-11-11 21:48:14 +1100 | [diff] [blame] | 2059 | audit_copy_inode(&context->names[idx], NULL, inode); |
Amy Griffis | 5712e88 | 2007-02-13 14:15:22 -0500 | [diff] [blame] | 2060 | else |
| 2061 | context->names[idx].ino = (unsigned long)-1; |
| 2062 | } |
Amy Griffis | 3e2efce | 2006-07-13 13:16:02 -0400 | [diff] [blame] | 2063 | } |
Trond Myklebust | 50e437d | 2007-06-07 22:44:34 -0400 | [diff] [blame] | 2064 | EXPORT_SYMBOL_GPL(__audit_inode_child); |
Amy Griffis | 3e2efce | 2006-07-13 13:16:02 -0400 | [diff] [blame] | 2065 | |
| 2066 | /** |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2067 | * auditsc_get_stamp - get local copies of audit_context values |
| 2068 | * @ctx: audit_context for the task |
| 2069 | * @t: timespec to store time recorded in the audit_context |
| 2070 | * @serial: serial value that is recorded in the audit_context |
| 2071 | * |
| 2072 | * Also sets the context as auditable. |
| 2073 | */ |
Al Viro | 48887e6 | 2008-12-06 01:05:50 -0500 | [diff] [blame] | 2074 | int auditsc_get_stamp(struct audit_context *ctx, |
David Woodhouse | bfb4496 | 2005-05-21 21:08:09 +0100 | [diff] [blame] | 2075 | struct timespec *t, unsigned int *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | { |
Al Viro | 48887e6 | 2008-12-06 01:05:50 -0500 | [diff] [blame] | 2077 | if (!ctx->in_syscall) |
| 2078 | return 0; |
David Woodhouse | ce625a8 | 2005-07-18 14:24:46 -0400 | [diff] [blame] | 2079 | if (!ctx->serial) |
| 2080 | ctx->serial = audit_serial(); |
David Woodhouse | bfb4496 | 2005-05-21 21:08:09 +0100 | [diff] [blame] | 2081 | t->tv_sec = ctx->ctime.tv_sec; |
| 2082 | t->tv_nsec = ctx->ctime.tv_nsec; |
| 2083 | *serial = ctx->serial; |
| 2084 | ctx->auditable = 1; |
Al Viro | 48887e6 | 2008-12-06 01:05:50 -0500 | [diff] [blame] | 2085 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2088 | /* global counter which is incremented every time something logs in */ |
| 2089 | static atomic_t session_id = ATOMIC_INIT(0); |
| 2090 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2091 | /** |
| 2092 | * audit_set_loginuid - set a task's audit_context loginuid |
| 2093 | * @task: task whose audit context is being modified |
| 2094 | * @loginuid: loginuid value |
| 2095 | * |
| 2096 | * Returns 0. |
| 2097 | * |
| 2098 | * Called (set) from fs/proc/base.c::proc_loginuid_write(). |
| 2099 | */ |
Steve Grubb | 456be6c | 2005-04-29 17:30:07 +0100 | [diff] [blame] | 2100 | int audit_set_loginuid(struct task_struct *task, uid_t loginuid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | { |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2102 | unsigned int sessionid = atomic_inc_return(&session_id); |
Steve Grubb | 4175710 | 2006-06-12 07:48:28 -0400 | [diff] [blame] | 2103 | struct audit_context *context = task->audit_context; |
Steve Grubb | c040499 | 2005-05-13 18:17:42 +0100 | [diff] [blame] | 2104 | |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 2105 | if (context && context->in_syscall) { |
| 2106 | struct audit_buffer *ab; |
Steve Grubb | 4175710 | 2006-06-12 07:48:28 -0400 | [diff] [blame] | 2107 | |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 2108 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN); |
| 2109 | if (ab) { |
| 2110 | audit_log_format(ab, "login pid=%d uid=%u " |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2111 | "old auid=%u new auid=%u" |
| 2112 | " old ses=%u new ses=%u", |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2113 | task->pid, task_uid(task), |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2114 | task->loginuid, loginuid, |
| 2115 | task->sessionid, sessionid); |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 2116 | audit_log_end(ab); |
Steve Grubb | c040499 | 2005-05-13 18:17:42 +0100 | [diff] [blame] | 2117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | } |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2119 | task->sessionid = sessionid; |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 2120 | task->loginuid = loginuid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | return 0; |
| 2122 | } |
| 2123 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2124 | /** |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 2125 | * __audit_mq_open - record audit data for a POSIX MQ open |
| 2126 | * @oflag: open flag |
| 2127 | * @mode: mode bits |
| 2128 | * @u_attr: queue attributes |
| 2129 | * |
| 2130 | * Returns 0 for success or NULL context or < 0 on error. |
| 2131 | */ |
| 2132 | int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr) |
| 2133 | { |
| 2134 | struct audit_aux_data_mq_open *ax; |
| 2135 | struct audit_context *context = current->audit_context; |
| 2136 | |
| 2137 | if (!audit_enabled) |
| 2138 | return 0; |
| 2139 | |
| 2140 | if (likely(!context)) |
| 2141 | return 0; |
| 2142 | |
| 2143 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2144 | if (!ax) |
| 2145 | return -ENOMEM; |
| 2146 | |
| 2147 | if (u_attr != NULL) { |
| 2148 | if (copy_from_user(&ax->attr, u_attr, sizeof(ax->attr))) { |
| 2149 | kfree(ax); |
| 2150 | return -EFAULT; |
| 2151 | } |
| 2152 | } else |
| 2153 | memset(&ax->attr, 0, sizeof(ax->attr)); |
| 2154 | |
| 2155 | ax->oflag = oflag; |
| 2156 | ax->mode = mode; |
| 2157 | |
| 2158 | ax->d.type = AUDIT_MQ_OPEN; |
| 2159 | ax->d.next = context->aux; |
| 2160 | context->aux = (void *)ax; |
| 2161 | return 0; |
| 2162 | } |
| 2163 | |
| 2164 | /** |
| 2165 | * __audit_mq_timedsend - record audit data for a POSIX MQ timed send |
| 2166 | * @mqdes: MQ descriptor |
| 2167 | * @msg_len: Message length |
| 2168 | * @msg_prio: Message priority |
Randy Dunlap | 1dbe83c | 2006-06-27 02:54:01 -0700 | [diff] [blame] | 2169 | * @u_abs_timeout: Message timeout in absolute time |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 2170 | * |
| 2171 | * Returns 0 for success or NULL context or < 0 on error. |
| 2172 | */ |
| 2173 | int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, |
| 2174 | const struct timespec __user *u_abs_timeout) |
| 2175 | { |
| 2176 | struct audit_aux_data_mq_sendrecv *ax; |
| 2177 | struct audit_context *context = current->audit_context; |
| 2178 | |
| 2179 | if (!audit_enabled) |
| 2180 | return 0; |
| 2181 | |
| 2182 | if (likely(!context)) |
| 2183 | return 0; |
| 2184 | |
| 2185 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2186 | if (!ax) |
| 2187 | return -ENOMEM; |
| 2188 | |
| 2189 | if (u_abs_timeout != NULL) { |
| 2190 | if (copy_from_user(&ax->abs_timeout, u_abs_timeout, sizeof(ax->abs_timeout))) { |
| 2191 | kfree(ax); |
| 2192 | return -EFAULT; |
| 2193 | } |
| 2194 | } else |
| 2195 | memset(&ax->abs_timeout, 0, sizeof(ax->abs_timeout)); |
| 2196 | |
| 2197 | ax->mqdes = mqdes; |
| 2198 | ax->msg_len = msg_len; |
| 2199 | ax->msg_prio = msg_prio; |
| 2200 | |
| 2201 | ax->d.type = AUDIT_MQ_SENDRECV; |
| 2202 | ax->d.next = context->aux; |
| 2203 | context->aux = (void *)ax; |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * __audit_mq_timedreceive - record audit data for a POSIX MQ timed receive |
| 2209 | * @mqdes: MQ descriptor |
| 2210 | * @msg_len: Message length |
Randy Dunlap | 1dbe83c | 2006-06-27 02:54:01 -0700 | [diff] [blame] | 2211 | * @u_msg_prio: Message priority |
| 2212 | * @u_abs_timeout: Message timeout in absolute time |
George C. Wilson | 20ca73b | 2006-05-24 16:09:55 -0500 | [diff] [blame] | 2213 | * |
| 2214 | * Returns 0 for success or NULL context or < 0 on error. |
| 2215 | */ |
| 2216 | int __audit_mq_timedreceive(mqd_t mqdes, size_t msg_len, |
| 2217 | unsigned int __user *u_msg_prio, |
| 2218 | const struct timespec __user *u_abs_timeout) |
| 2219 | { |
| 2220 | struct audit_aux_data_mq_sendrecv *ax; |
| 2221 | struct audit_context *context = current->audit_context; |
| 2222 | |
| 2223 | if (!audit_enabled) |
| 2224 | return 0; |
| 2225 | |
| 2226 | if (likely(!context)) |
| 2227 | return 0; |
| 2228 | |
| 2229 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2230 | if (!ax) |
| 2231 | return -ENOMEM; |
| 2232 | |
| 2233 | if (u_msg_prio != NULL) { |
| 2234 | if (get_user(ax->msg_prio, u_msg_prio)) { |
| 2235 | kfree(ax); |
| 2236 | return -EFAULT; |
| 2237 | } |
| 2238 | } else |
| 2239 | ax->msg_prio = 0; |
| 2240 | |
| 2241 | if (u_abs_timeout != NULL) { |
| 2242 | if (copy_from_user(&ax->abs_timeout, u_abs_timeout, sizeof(ax->abs_timeout))) { |
| 2243 | kfree(ax); |
| 2244 | return -EFAULT; |
| 2245 | } |
| 2246 | } else |
| 2247 | memset(&ax->abs_timeout, 0, sizeof(ax->abs_timeout)); |
| 2248 | |
| 2249 | ax->mqdes = mqdes; |
| 2250 | ax->msg_len = msg_len; |
| 2251 | |
| 2252 | ax->d.type = AUDIT_MQ_SENDRECV; |
| 2253 | ax->d.next = context->aux; |
| 2254 | context->aux = (void *)ax; |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * __audit_mq_notify - record audit data for a POSIX MQ notify |
| 2260 | * @mqdes: MQ descriptor |
| 2261 | * @u_notification: Notification event |
| 2262 | * |
| 2263 | * Returns 0 for success or NULL context or < 0 on error. |
| 2264 | */ |
| 2265 | |
| 2266 | int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification) |
| 2267 | { |
| 2268 | struct audit_aux_data_mq_notify *ax; |
| 2269 | struct audit_context *context = current->audit_context; |
| 2270 | |
| 2271 | if (!audit_enabled) |
| 2272 | return 0; |
| 2273 | |
| 2274 | if (likely(!context)) |
| 2275 | return 0; |
| 2276 | |
| 2277 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2278 | if (!ax) |
| 2279 | return -ENOMEM; |
| 2280 | |
| 2281 | if (u_notification != NULL) { |
| 2282 | if (copy_from_user(&ax->notification, u_notification, sizeof(ax->notification))) { |
| 2283 | kfree(ax); |
| 2284 | return -EFAULT; |
| 2285 | } |
| 2286 | } else |
| 2287 | memset(&ax->notification, 0, sizeof(ax->notification)); |
| 2288 | |
| 2289 | ax->mqdes = mqdes; |
| 2290 | |
| 2291 | ax->d.type = AUDIT_MQ_NOTIFY; |
| 2292 | ax->d.next = context->aux; |
| 2293 | context->aux = (void *)ax; |
| 2294 | return 0; |
| 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * __audit_mq_getsetattr - record audit data for a POSIX MQ get/set attribute |
| 2299 | * @mqdes: MQ descriptor |
| 2300 | * @mqstat: MQ flags |
| 2301 | * |
| 2302 | * Returns 0 for success or NULL context or < 0 on error. |
| 2303 | */ |
| 2304 | int __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) |
| 2305 | { |
| 2306 | struct audit_aux_data_mq_getsetattr *ax; |
| 2307 | struct audit_context *context = current->audit_context; |
| 2308 | |
| 2309 | if (!audit_enabled) |
| 2310 | return 0; |
| 2311 | |
| 2312 | if (likely(!context)) |
| 2313 | return 0; |
| 2314 | |
| 2315 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2316 | if (!ax) |
| 2317 | return -ENOMEM; |
| 2318 | |
| 2319 | ax->mqdes = mqdes; |
| 2320 | ax->mqstat = *mqstat; |
| 2321 | |
| 2322 | ax->d.type = AUDIT_MQ_GETSETATTR; |
| 2323 | ax->d.next = context->aux; |
| 2324 | context->aux = (void *)ax; |
| 2325 | return 0; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 2329 | * audit_ipc_obj - record audit data for ipc object |
| 2330 | * @ipcp: ipc permissions |
| 2331 | * |
| 2332 | * Returns 0 for success or NULL context or < 0 on error. |
| 2333 | */ |
Al Viro | d8945bb5 | 2006-05-18 16:01:30 -0400 | [diff] [blame] | 2334 | int __audit_ipc_obj(struct kern_ipc_perm *ipcp) |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 2335 | { |
| 2336 | struct audit_aux_data_ipcctl *ax; |
| 2337 | struct audit_context *context = current->audit_context; |
| 2338 | |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 2339 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 2340 | if (!ax) |
| 2341 | return -ENOMEM; |
| 2342 | |
| 2343 | ax->uid = ipcp->uid; |
| 2344 | ax->gid = ipcp->gid; |
| 2345 | ax->mode = ipcp->mode; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2346 | security_ipc_getsecid(ipcp, &ax->osid); |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 2347 | ax->d.type = AUDIT_IPC; |
| 2348 | ax->d.next = context->aux; |
| 2349 | context->aux = (void *)ax; |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
| 2353 | /** |
| 2354 | * audit_ipc_set_perm - record audit data for new ipc permissions |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2355 | * @qbytes: msgq bytes |
| 2356 | * @uid: msgq user id |
| 2357 | * @gid: msgq group id |
| 2358 | * @mode: msgq mode (permissions) |
| 2359 | * |
| 2360 | * Returns 0 for success or NULL context or < 0 on error. |
| 2361 | */ |
Al Viro | d8945bb5 | 2006-05-18 16:01:30 -0400 | [diff] [blame] | 2362 | int __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | { |
| 2364 | struct audit_aux_data_ipcctl *ax; |
| 2365 | struct audit_context *context = current->audit_context; |
| 2366 | |
Dustin Kirkland | 8c8570f | 2005-11-03 17:15:16 +0000 | [diff] [blame] | 2367 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | if (!ax) |
| 2369 | return -ENOMEM; |
| 2370 | |
| 2371 | ax->qbytes = qbytes; |
| 2372 | ax->uid = uid; |
| 2373 | ax->gid = gid; |
| 2374 | ax->mode = mode; |
| 2375 | |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 2376 | ax->d.type = AUDIT_IPC_SET_PERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | ax->d.next = context->aux; |
| 2378 | context->aux = (void *)ax; |
| 2379 | return 0; |
| 2380 | } |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 2381 | |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 2382 | int audit_bprm(struct linux_binprm *bprm) |
| 2383 | { |
| 2384 | struct audit_aux_data_execve *ax; |
| 2385 | struct audit_context *context = current->audit_context; |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 2386 | |
Al Viro | 5ac3a9c | 2006-07-16 06:38:45 -0400 | [diff] [blame] | 2387 | if (likely(!audit_enabled || !context || context->dummy)) |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 2388 | return 0; |
| 2389 | |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 2390 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 2391 | if (!ax) |
| 2392 | return -ENOMEM; |
| 2393 | |
| 2394 | ax->argc = bprm->argc; |
| 2395 | ax->envc = bprm->envc; |
Peter Zijlstra | bdf4c48 | 2007-07-19 01:48:15 -0700 | [diff] [blame] | 2396 | ax->mm = bprm->mm; |
Al Viro | 473ae30 | 2006-04-26 14:04:08 -0400 | [diff] [blame] | 2397 | ax->d.type = AUDIT_EXECVE; |
| 2398 | ax->d.next = context->aux; |
| 2399 | context->aux = (void *)ax; |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2404 | /** |
| 2405 | * audit_socketcall - record audit data for sys_socketcall |
| 2406 | * @nargs: number of args |
| 2407 | * @args: args array |
| 2408 | * |
| 2409 | * Returns 0 for success or NULL context or < 0 on error. |
| 2410 | */ |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2411 | int audit_socketcall(int nargs, unsigned long *args) |
| 2412 | { |
| 2413 | struct audit_aux_data_socketcall *ax; |
| 2414 | struct audit_context *context = current->audit_context; |
| 2415 | |
Al Viro | 5ac3a9c | 2006-07-16 06:38:45 -0400 | [diff] [blame] | 2416 | if (likely(!context || context->dummy)) |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2417 | return 0; |
| 2418 | |
| 2419 | ax = kmalloc(sizeof(*ax) + nargs * sizeof(unsigned long), GFP_KERNEL); |
| 2420 | if (!ax) |
| 2421 | return -ENOMEM; |
| 2422 | |
| 2423 | ax->nargs = nargs; |
| 2424 | memcpy(ax->args, args, nargs * sizeof(unsigned long)); |
| 2425 | |
| 2426 | ax->d.type = AUDIT_SOCKETCALL; |
| 2427 | ax->d.next = context->aux; |
| 2428 | context->aux = (void *)ax; |
| 2429 | return 0; |
| 2430 | } |
| 2431 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2432 | /** |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 2433 | * __audit_fd_pair - record audit data for pipe and socketpair |
| 2434 | * @fd1: the first file descriptor |
| 2435 | * @fd2: the second file descriptor |
| 2436 | * |
| 2437 | * Returns 0 for success or NULL context or < 0 on error. |
| 2438 | */ |
| 2439 | int __audit_fd_pair(int fd1, int fd2) |
| 2440 | { |
| 2441 | struct audit_context *context = current->audit_context; |
| 2442 | struct audit_aux_data_fd_pair *ax; |
| 2443 | |
| 2444 | if (likely(!context)) { |
| 2445 | return 0; |
| 2446 | } |
| 2447 | |
| 2448 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); |
| 2449 | if (!ax) { |
| 2450 | return -ENOMEM; |
| 2451 | } |
| 2452 | |
| 2453 | ax->fd[0] = fd1; |
| 2454 | ax->fd[1] = fd2; |
| 2455 | |
| 2456 | ax->d.type = AUDIT_FD_PAIR; |
| 2457 | ax->d.next = context->aux; |
| 2458 | context->aux = (void *)ax; |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | /** |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2463 | * audit_sockaddr - record audit data for sys_bind, sys_connect, sys_sendto |
| 2464 | * @len: data length in user space |
| 2465 | * @a: data address in kernel space |
| 2466 | * |
| 2467 | * Returns 0 for success or NULL context or < 0 on error. |
| 2468 | */ |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2469 | int audit_sockaddr(int len, void *a) |
| 2470 | { |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2471 | struct audit_context *context = current->audit_context; |
| 2472 | |
Al Viro | 5ac3a9c | 2006-07-16 06:38:45 -0400 | [diff] [blame] | 2473 | if (likely(!context || context->dummy)) |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2474 | return 0; |
| 2475 | |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 2476 | if (!context->sockaddr) { |
| 2477 | void *p = kmalloc(sizeof(struct sockaddr_storage), GFP_KERNEL); |
| 2478 | if (!p) |
| 2479 | return -ENOMEM; |
| 2480 | context->sockaddr = p; |
| 2481 | } |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2482 | |
Al Viro | 4f6b434 | 2008-12-09 19:50:34 -0500 | [diff] [blame^] | 2483 | context->sockaddr_len = len; |
| 2484 | memcpy(context->sockaddr, a, len); |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2485 | return 0; |
| 2486 | } |
| 2487 | |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 2488 | void __audit_ptrace(struct task_struct *t) |
| 2489 | { |
| 2490 | struct audit_context *context = current->audit_context; |
| 2491 | |
| 2492 | context->target_pid = t->pid; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2493 | context->target_auid = audit_get_loginuid(t); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2494 | context->target_uid = task_uid(t); |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2495 | context->target_sessionid = audit_get_sessionid(t); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2496 | security_task_getsecid(t, &context->target_sid); |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2497 | memcpy(context->target_comm, t->comm, TASK_COMM_LEN); |
Al Viro | a5cb013 | 2007-03-20 13:58:35 -0400 | [diff] [blame] | 2498 | } |
| 2499 | |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2500 | /** |
Randy Dunlap | b0dd25a | 2005-09-13 12:47:11 -0700 | [diff] [blame] | 2501 | * audit_signal_info - record signal info for shutting down audit subsystem |
| 2502 | * @sig: signal value |
| 2503 | * @t: task being signaled |
| 2504 | * |
| 2505 | * If the audit subsystem is being terminated, record the task (pid) |
| 2506 | * and uid that is doing that. |
| 2507 | */ |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2508 | int __audit_signal_info(int sig, struct task_struct *t) |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 2509 | { |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2510 | struct audit_aux_data_pids *axp; |
| 2511 | struct task_struct *tsk = current; |
| 2512 | struct audit_context *ctx = tsk->audit_context; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2513 | uid_t uid = current_uid(), t_uid = task_uid(t); |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 2514 | |
Al Viro | 175fc48 | 2007-08-08 00:01:46 +0100 | [diff] [blame] | 2515 | if (audit_pid && t->tgid == audit_pid) { |
Eric Paris | ee1d315 | 2008-07-07 10:49:45 -0400 | [diff] [blame] | 2516 | if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 || sig == SIGUSR2) { |
Al Viro | 175fc48 | 2007-08-08 00:01:46 +0100 | [diff] [blame] | 2517 | audit_sig_pid = tsk->pid; |
Al Viro | bfef93a | 2008-01-10 04:53:18 -0500 | [diff] [blame] | 2518 | if (tsk->loginuid != -1) |
| 2519 | audit_sig_uid = tsk->loginuid; |
Al Viro | 175fc48 | 2007-08-08 00:01:46 +0100 | [diff] [blame] | 2520 | else |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2521 | audit_sig_uid = uid; |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2522 | security_task_getsecid(tsk, &audit_sig_sid); |
Al Viro | 175fc48 | 2007-08-08 00:01:46 +0100 | [diff] [blame] | 2523 | } |
| 2524 | if (!audit_signals || audit_dummy_context()) |
| 2525 | return 0; |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 2526 | } |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2527 | |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2528 | /* optimize the common case by putting first signal recipient directly |
| 2529 | * in audit_context */ |
| 2530 | if (!ctx->target_pid) { |
| 2531 | ctx->target_pid = t->tgid; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2532 | ctx->target_auid = audit_get_loginuid(t); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2533 | ctx->target_uid = t_uid; |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2534 | ctx->target_sessionid = audit_get_sessionid(t); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2535 | security_task_getsecid(t, &ctx->target_sid); |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2536 | memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2537 | return 0; |
| 2538 | } |
| 2539 | |
| 2540 | axp = (void *)ctx->aux_pids; |
| 2541 | if (!axp || axp->pid_count == AUDIT_AUX_PIDS) { |
| 2542 | axp = kzalloc(sizeof(*axp), GFP_ATOMIC); |
| 2543 | if (!axp) |
| 2544 | return -ENOMEM; |
| 2545 | |
| 2546 | axp->d.type = AUDIT_OBJ_PID; |
| 2547 | axp->d.next = ctx->aux_pids; |
| 2548 | ctx->aux_pids = (void *)axp; |
| 2549 | } |
Adrian Bunk | 88ae704 | 2007-08-22 14:01:05 -0700 | [diff] [blame] | 2550 | BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2551 | |
| 2552 | axp->target_pid[axp->pid_count] = t->tgid; |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2553 | axp->target_auid[axp->pid_count] = audit_get_loginuid(t); |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 2554 | axp->target_uid[axp->pid_count] = t_uid; |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2555 | axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2556 | security_task_getsecid(t, &axp->target_sid[axp->pid_count]); |
Eric Paris | c2a7780 | 2008-01-07 13:40:17 -0500 | [diff] [blame] | 2557 | memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); |
Amy Griffis | e54dc24 | 2007-03-29 18:01:04 -0400 | [diff] [blame] | 2558 | axp->pid_count++; |
| 2559 | |
| 2560 | return 0; |
Steve Grubb | c2f0c7c | 2005-05-06 12:38:39 +0100 | [diff] [blame] | 2561 | } |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2562 | |
| 2563 | /** |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2564 | * __audit_log_bprm_fcaps - store information about a loading bprm and relevant fcaps |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2565 | * @bprm: pointer to the bprm being processed |
| 2566 | * @new: the proposed new credentials |
| 2567 | * @old: the old credentials |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2568 | * |
| 2569 | * Simply check if the proc already has the caps given by the file and if not |
| 2570 | * store the priv escalation info for later auditing at the end of the syscall |
| 2571 | * |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2572 | * -Eric |
| 2573 | */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2574 | int __audit_log_bprm_fcaps(struct linux_binprm *bprm, |
| 2575 | const struct cred *new, const struct cred *old) |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2576 | { |
| 2577 | struct audit_aux_data_bprm_fcaps *ax; |
| 2578 | struct audit_context *context = current->audit_context; |
| 2579 | struct cpu_vfs_cap_data vcaps; |
| 2580 | struct dentry *dentry; |
| 2581 | |
| 2582 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); |
| 2583 | if (!ax) |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2584 | return -ENOMEM; |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2585 | |
| 2586 | ax->d.type = AUDIT_BPRM_FCAPS; |
| 2587 | ax->d.next = context->aux; |
| 2588 | context->aux = (void *)ax; |
| 2589 | |
| 2590 | dentry = dget(bprm->file->f_dentry); |
| 2591 | get_vfs_caps_from_disk(dentry, &vcaps); |
| 2592 | dput(dentry); |
| 2593 | |
| 2594 | ax->fcap.permitted = vcaps.permitted; |
| 2595 | ax->fcap.inheritable = vcaps.inheritable; |
| 2596 | ax->fcap.fE = !!(vcaps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE); |
| 2597 | ax->fcap_ver = (vcaps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT; |
| 2598 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2599 | ax->old_pcap.permitted = old->cap_permitted; |
| 2600 | ax->old_pcap.inheritable = old->cap_inheritable; |
| 2601 | ax->old_pcap.effective = old->cap_effective; |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2602 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2603 | ax->new_pcap.permitted = new->cap_permitted; |
| 2604 | ax->new_pcap.inheritable = new->cap_inheritable; |
| 2605 | ax->new_pcap.effective = new->cap_effective; |
| 2606 | return 0; |
Eric Paris | 3fc689e | 2008-11-11 21:48:18 +1100 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | /** |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 2610 | * __audit_log_capset - store information about the arguments to the capset syscall |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2611 | * @pid: target pid of the capset call |
| 2612 | * @new: the new credentials |
| 2613 | * @old: the old (current) credentials |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 2614 | * |
| 2615 | * Record the aguments userspace sent to sys_capset for later printing by the |
| 2616 | * audit system if applicable |
| 2617 | */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2618 | int __audit_log_capset(pid_t pid, |
| 2619 | const struct cred *new, const struct cred *old) |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 2620 | { |
| 2621 | struct audit_aux_data_capset *ax; |
| 2622 | struct audit_context *context = current->audit_context; |
| 2623 | |
| 2624 | if (likely(!audit_enabled || !context || context->dummy)) |
| 2625 | return 0; |
| 2626 | |
| 2627 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); |
| 2628 | if (!ax) |
| 2629 | return -ENOMEM; |
| 2630 | |
| 2631 | ax->d.type = AUDIT_CAPSET; |
| 2632 | ax->d.next = context->aux; |
| 2633 | context->aux = (void *)ax; |
| 2634 | |
| 2635 | ax->pid = pid; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2636 | ax->cap.effective = new->cap_effective; |
| 2637 | ax->cap.inheritable = new->cap_effective; |
| 2638 | ax->cap.permitted = new->cap_permitted; |
Eric Paris | e68b75a0 | 2008-11-11 21:48:22 +1100 | [diff] [blame] | 2639 | |
| 2640 | return 0; |
| 2641 | } |
| 2642 | |
| 2643 | /** |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2644 | * audit_core_dumps - record information about processes that end abnormally |
Henrik Kretzschmar | 6d9525b | 2007-07-15 23:41:10 -0700 | [diff] [blame] | 2645 | * @signr: signal value |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2646 | * |
| 2647 | * If a process ends with a core dump, something fishy is going on and we |
| 2648 | * should record the event for investigation. |
| 2649 | */ |
| 2650 | void audit_core_dumps(long signr) |
| 2651 | { |
| 2652 | struct audit_buffer *ab; |
| 2653 | u32 sid; |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 2654 | uid_t auid = audit_get_loginuid(current), uid; |
| 2655 | gid_t gid; |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2656 | unsigned int sessionid = audit_get_sessionid(current); |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2657 | |
| 2658 | if (!audit_enabled) |
| 2659 | return; |
| 2660 | |
| 2661 | if (signr == SIGQUIT) /* don't care for those */ |
| 2662 | return; |
| 2663 | |
| 2664 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND); |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 2665 | current_uid_gid(&uid, &gid); |
Eric Paris | 4746ec5 | 2008-01-08 10:06:53 -0500 | [diff] [blame] | 2666 | audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u", |
David Howells | 76aac0e | 2008-11-14 10:39:12 +1100 | [diff] [blame] | 2667 | auid, uid, gid, sessionid); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2668 | security_task_getsecid(current, &sid); |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2669 | if (sid) { |
| 2670 | char *ctx = NULL; |
| 2671 | u32 len; |
| 2672 | |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2673 | if (security_secid_to_secctx(sid, &ctx, &len)) |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2674 | audit_log_format(ab, " ssid=%u", sid); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2675 | else { |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2676 | audit_log_format(ab, " subj=%s", ctx); |
Ahmed S. Darwish | 2a862b3 | 2008-03-01 21:54:38 +0200 | [diff] [blame] | 2677 | security_release_secctx(ctx, len); |
| 2678 | } |
Steve Grubb | 0a4ff8c | 2007-04-19 10:28:21 -0400 | [diff] [blame] | 2679 | } |
| 2680 | audit_log_format(ab, " pid=%d comm=", current->pid); |
| 2681 | audit_log_untrustedstring(ab, current->comm); |
| 2682 | audit_log_format(ab, " sig=%ld", signr); |
| 2683 | audit_log_end(ab); |
| 2684 | } |