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