diff options
Diffstat (limited to 'kernel/auditsc.c')
| -rw-r--r-- | kernel/auditsc.c | 327 |
1 files changed, 229 insertions, 98 deletions
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index e75f84e1a1a0..88696f639aab 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
| @@ -39,6 +39,9 @@ | |||
| 39 | #include <linux/audit.h> | 39 | #include <linux/audit.h> |
| 40 | #include <linux/personality.h> | 40 | #include <linux/personality.h> |
| 41 | #include <linux/time.h> | 41 | #include <linux/time.h> |
| 42 | #include <linux/kthread.h> | ||
| 43 | #include <linux/netlink.h> | ||
| 44 | #include <linux/compiler.h> | ||
| 42 | #include <asm/unistd.h> | 45 | #include <asm/unistd.h> |
| 43 | 46 | ||
| 44 | /* 0 = no checking | 47 | /* 0 = no checking |
| @@ -95,6 +98,7 @@ struct audit_names { | |||
| 95 | uid_t uid; | 98 | uid_t uid; |
| 96 | gid_t gid; | 99 | gid_t gid; |
| 97 | dev_t rdev; | 100 | dev_t rdev; |
| 101 | unsigned flags; | ||
| 98 | }; | 102 | }; |
| 99 | 103 | ||
| 100 | struct audit_aux_data { | 104 | struct audit_aux_data { |
| @@ -167,9 +171,16 @@ struct audit_context { | |||
| 167 | /* There are three lists of rules -- one to search at task creation | 171 | /* There are three lists of rules -- one to search at task creation |
| 168 | * time, one to search at syscall entry time, and another to search at | 172 | * time, one to search at syscall entry time, and another to search at |
| 169 | * syscall exit time. */ | 173 | * syscall exit time. */ |
| 170 | static LIST_HEAD(audit_tsklist); | 174 | static struct list_head audit_filter_list[AUDIT_NR_FILTERS] = { |
| 171 | static LIST_HEAD(audit_entlist); | 175 | LIST_HEAD_INIT(audit_filter_list[0]), |
| 172 | static LIST_HEAD(audit_extlist); | 176 | LIST_HEAD_INIT(audit_filter_list[1]), |
| 177 | LIST_HEAD_INIT(audit_filter_list[2]), | ||
| 178 | LIST_HEAD_INIT(audit_filter_list[3]), | ||
| 179 | LIST_HEAD_INIT(audit_filter_list[4]), | ||
| 180 | #if AUDIT_NR_FILTERS != 5 | ||
| 181 | #error Fix audit_filter_list initialiser | ||
| 182 | #endif | ||
| 183 | }; | ||
| 173 | 184 | ||
| 174 | struct audit_entry { | 185 | struct audit_entry { |
| 175 | struct list_head list; | 186 | struct list_head list; |
| @@ -179,9 +190,36 @@ struct audit_entry { | |||
| 179 | 190 | ||
| 180 | extern int audit_pid; | 191 | extern int audit_pid; |
| 181 | 192 | ||
| 193 | /* Copy rule from user-space to kernel-space. Called from | ||
| 194 | * audit_add_rule during AUDIT_ADD. */ | ||
| 195 | static inline int audit_copy_rule(struct audit_rule *d, struct audit_rule *s) | ||
| 196 | { | ||
| 197 | int i; | ||
| 198 | |||
| 199 | if (s->action != AUDIT_NEVER | ||
| 200 | && s->action != AUDIT_POSSIBLE | ||
| 201 | && s->action != AUDIT_ALWAYS) | ||
| 202 | return -1; | ||
| 203 | if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS) | ||
| 204 | return -1; | ||
| 205 | if ((s->flags & ~AUDIT_FILTER_PREPEND) >= AUDIT_NR_FILTERS) | ||
| 206 | return -1; | ||
| 207 | |||
| 208 | d->flags = s->flags; | ||
| 209 | d->action = s->action; | ||
| 210 | d->field_count = s->field_count; | ||
| 211 | for (i = 0; i < d->field_count; i++) { | ||
| 212 | d->fields[i] = s->fields[i]; | ||
| 213 | d->values[i] = s->values[i]; | ||
| 214 | } | ||
| 215 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i]; | ||
| 216 | return 0; | ||
| 217 | } | ||
| 218 | |||
| 182 | /* Check to see if two rules are identical. It is called from | 219 | /* Check to see if two rules are identical. It is called from |
| 220 | * audit_add_rule during AUDIT_ADD and | ||
| 183 | * audit_del_rule during AUDIT_DEL. */ | 221 | * audit_del_rule during AUDIT_DEL. */ |
| 184 | static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b) | 222 | static inline int audit_compare_rule(struct audit_rule *a, struct audit_rule *b) |
| 185 | { | 223 | { |
| 186 | int i; | 224 | int i; |
| 187 | 225 | ||
| @@ -210,19 +248,37 @@ static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b) | |||
| 210 | /* Note that audit_add_rule and audit_del_rule are called via | 248 | /* Note that audit_add_rule and audit_del_rule are called via |
| 211 | * audit_receive() in audit.c, and are protected by | 249 | * audit_receive() in audit.c, and are protected by |
| 212 | * audit_netlink_sem. */ | 250 | * audit_netlink_sem. */ |
| 213 | static inline int audit_add_rule(struct audit_entry *entry, | 251 | static inline int audit_add_rule(struct audit_rule *rule, |
| 214 | struct list_head *list) | 252 | struct list_head *list) |
| 215 | { | 253 | { |
| 216 | if (entry->rule.flags & AUDIT_PREPEND) { | 254 | struct audit_entry *entry; |
| 217 | entry->rule.flags &= ~AUDIT_PREPEND; | 255 | |
| 256 | /* Do not use the _rcu iterator here, since this is the only | ||
| 257 | * addition routine. */ | ||
| 258 | list_for_each_entry(entry, list, list) { | ||
| 259 | if (!audit_compare_rule(rule, &entry->rule)) { | ||
| 260 | return -EEXIST; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL))) | ||
| 265 | return -ENOMEM; | ||
| 266 | if (audit_copy_rule(&entry->rule, rule)) { | ||
| 267 | kfree(entry); | ||
| 268 | return -EINVAL; | ||
| 269 | } | ||
| 270 | |||
| 271 | if (entry->rule.flags & AUDIT_FILTER_PREPEND) { | ||
| 272 | entry->rule.flags &= ~AUDIT_FILTER_PREPEND; | ||
| 218 | list_add_rcu(&entry->list, list); | 273 | list_add_rcu(&entry->list, list); |
| 219 | } else { | 274 | } else { |
| 220 | list_add_tail_rcu(&entry->list, list); | 275 | list_add_tail_rcu(&entry->list, list); |
| 221 | } | 276 | } |
| 277 | |||
| 222 | return 0; | 278 | return 0; |
| 223 | } | 279 | } |
| 224 | 280 | ||
| 225 | static void audit_free_rule(struct rcu_head *head) | 281 | static inline void audit_free_rule(struct rcu_head *head) |
| 226 | { | 282 | { |
| 227 | struct audit_entry *e = container_of(head, struct audit_entry, rcu); | 283 | struct audit_entry *e = container_of(head, struct audit_entry, rcu); |
| 228 | kfree(e); | 284 | kfree(e); |
| @@ -245,82 +301,82 @@ static inline int audit_del_rule(struct audit_rule *rule, | |||
| 245 | return 0; | 301 | return 0; |
| 246 | } | 302 | } |
| 247 | } | 303 | } |
| 248 | return -EFAULT; /* No matching rule */ | 304 | return -ENOENT; /* No matching rule */ |
| 249 | } | 305 | } |
| 250 | 306 | ||
| 251 | /* Copy rule from user-space to kernel-space. Called during | 307 | static int audit_list_rules(void *_dest) |
| 252 | * AUDIT_ADD. */ | ||
| 253 | static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s) | ||
| 254 | { | 308 | { |
| 309 | int pid, seq; | ||
| 310 | int *dest = _dest; | ||
| 311 | struct audit_entry *entry; | ||
| 255 | int i; | 312 | int i; |
| 256 | 313 | ||
| 257 | if (s->action != AUDIT_NEVER | 314 | pid = dest[0]; |
| 258 | && s->action != AUDIT_POSSIBLE | 315 | seq = dest[1]; |
| 259 | && s->action != AUDIT_ALWAYS) | 316 | kfree(dest); |
| 260 | return -1; | ||
| 261 | if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS) | ||
| 262 | return -1; | ||
| 263 | 317 | ||
| 264 | d->flags = s->flags; | 318 | down(&audit_netlink_sem); |
| 265 | d->action = s->action; | 319 | |
| 266 | d->field_count = s->field_count; | 320 | /* The *_rcu iterators not needed here because we are |
| 267 | for (i = 0; i < d->field_count; i++) { | 321 | always called with audit_netlink_sem held. */ |
| 268 | d->fields[i] = s->fields[i]; | 322 | for (i=0; i<AUDIT_NR_FILTERS; i++) { |
| 269 | d->values[i] = s->values[i]; | 323 | list_for_each_entry(entry, &audit_filter_list[i], list) |
| 324 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | ||
| 325 | &entry->rule, sizeof(entry->rule)); | ||
| 270 | } | 326 | } |
| 271 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i]; | 327 | audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0); |
| 328 | |||
| 329 | up(&audit_netlink_sem); | ||
| 272 | return 0; | 330 | return 0; |
| 273 | } | 331 | } |
| 274 | 332 | ||
| 275 | int audit_receive_filter(int type, int pid, int uid, int seq, void *data, | 333 | int audit_receive_filter(int type, int pid, int uid, int seq, void *data, |
| 276 | uid_t loginuid) | 334 | uid_t loginuid) |
| 277 | { | 335 | { |
| 278 | u32 flags; | 336 | struct task_struct *tsk; |
| 279 | struct audit_entry *entry; | 337 | int *dest; |
| 280 | int err = 0; | 338 | int err = 0; |
| 339 | unsigned listnr; | ||
| 281 | 340 | ||
| 282 | switch (type) { | 341 | switch (type) { |
| 283 | case AUDIT_LIST: | 342 | case AUDIT_LIST: |
| 284 | /* The *_rcu iterators not needed here because we are | 343 | /* We can't just spew out the rules here because we might fill |
| 285 | always called with audit_netlink_sem held. */ | 344 | * the available socket buffer space and deadlock waiting for |
| 286 | list_for_each_entry(entry, &audit_tsklist, list) | 345 | * auditctl to read from it... which isn't ever going to |
| 287 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 346 | * happen if we're actually running in the context of auditctl |
| 288 | &entry->rule, sizeof(entry->rule)); | 347 | * trying to _send_ the stuff */ |
| 289 | list_for_each_entry(entry, &audit_entlist, list) | 348 | |
| 290 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 349 | dest = kmalloc(2 * sizeof(int), GFP_KERNEL); |
| 291 | &entry->rule, sizeof(entry->rule)); | 350 | if (!dest) |
| 292 | list_for_each_entry(entry, &audit_extlist, list) | 351 | return -ENOMEM; |
| 293 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 352 | dest[0] = pid; |
| 294 | &entry->rule, sizeof(entry->rule)); | 353 | dest[1] = seq; |
| 295 | audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0); | 354 | |
| 355 | tsk = kthread_run(audit_list_rules, dest, "audit_list_rules"); | ||
| 356 | if (IS_ERR(tsk)) { | ||
| 357 | kfree(dest); | ||
| 358 | err = PTR_ERR(tsk); | ||
| 359 | } | ||
| 296 | break; | 360 | break; |
| 297 | case AUDIT_ADD: | 361 | case AUDIT_ADD: |
| 298 | if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL))) | 362 | listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND; |
| 299 | return -ENOMEM; | 363 | if (listnr >= AUDIT_NR_FILTERS) |
| 300 | if (audit_copy_rule(&entry->rule, data)) { | ||
| 301 | kfree(entry); | ||
| 302 | return -EINVAL; | 364 | return -EINVAL; |
| 303 | } | 365 | |
| 304 | flags = entry->rule.flags; | 366 | err = audit_add_rule(data, &audit_filter_list[listnr]); |
| 305 | if (!err && (flags & AUDIT_PER_TASK)) | 367 | if (!err) |
| 306 | err = audit_add_rule(entry, &audit_tsklist); | 368 | audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, |
| 307 | if (!err && (flags & AUDIT_AT_ENTRY)) | 369 | "auid=%u added an audit rule\n", loginuid); |
| 308 | err = audit_add_rule(entry, &audit_entlist); | ||
| 309 | if (!err && (flags & AUDIT_AT_EXIT)) | ||
| 310 | err = audit_add_rule(entry, &audit_extlist); | ||
| 311 | audit_log(NULL, AUDIT_CONFIG_CHANGE, | ||
| 312 | "auid=%u added an audit rule\n", loginuid); | ||
| 313 | break; | 370 | break; |
| 314 | case AUDIT_DEL: | 371 | case AUDIT_DEL: |
| 315 | flags =((struct audit_rule *)data)->flags; | 372 | listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND; |
| 316 | if (!err && (flags & AUDIT_PER_TASK)) | 373 | if (listnr >= AUDIT_NR_FILTERS) |
| 317 | err = audit_del_rule(data, &audit_tsklist); | 374 | return -EINVAL; |
| 318 | if (!err && (flags & AUDIT_AT_ENTRY)) | 375 | |
| 319 | err = audit_del_rule(data, &audit_entlist); | 376 | err = audit_del_rule(data, &audit_filter_list[listnr]); |
| 320 | if (!err && (flags & AUDIT_AT_EXIT)) | 377 | if (!err) |
| 321 | err = audit_del_rule(data, &audit_extlist); | 378 | audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, |
| 322 | audit_log(NULL, AUDIT_CONFIG_CHANGE, | 379 | "auid=%u removed an audit rule\n", loginuid); |
| 323 | "auid=%u removed an audit rule\n", loginuid); | ||
| 324 | break; | 380 | break; |
| 325 | default: | 381 | default: |
| 326 | return -EINVAL; | 382 | return -EINVAL; |
| @@ -384,8 +440,12 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
| 384 | result = (ctx->return_code == value); | 440 | result = (ctx->return_code == value); |
| 385 | break; | 441 | break; |
| 386 | case AUDIT_SUCCESS: | 442 | case AUDIT_SUCCESS: |
| 387 | if (ctx && ctx->return_valid) | 443 | if (ctx && ctx->return_valid) { |
| 388 | result = (ctx->return_valid == AUDITSC_SUCCESS); | 444 | if (value) |
| 445 | result = (ctx->return_valid == AUDITSC_SUCCESS); | ||
| 446 | else | ||
| 447 | result = (ctx->return_valid == AUDITSC_FAILURE); | ||
| 448 | } | ||
| 389 | break; | 449 | break; |
| 390 | case AUDIT_DEVMAJOR: | 450 | case AUDIT_DEVMAJOR: |
| 391 | if (ctx) { | 451 | if (ctx) { |
| @@ -454,7 +514,7 @@ static enum audit_state audit_filter_task(struct task_struct *tsk) | |||
| 454 | enum audit_state state; | 514 | enum audit_state state; |
| 455 | 515 | ||
| 456 | rcu_read_lock(); | 516 | rcu_read_lock(); |
| 457 | list_for_each_entry_rcu(e, &audit_tsklist, list) { | 517 | list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) { |
| 458 | if (audit_filter_rules(tsk, &e->rule, NULL, &state)) { | 518 | if (audit_filter_rules(tsk, &e->rule, NULL, &state)) { |
| 459 | rcu_read_unlock(); | 519 | rcu_read_unlock(); |
| 460 | return state; | 520 | return state; |
| @@ -474,20 +534,84 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, | |||
| 474 | struct list_head *list) | 534 | struct list_head *list) |
| 475 | { | 535 | { |
| 476 | struct audit_entry *e; | 536 | struct audit_entry *e; |
| 537 | enum audit_state state; | ||
| 538 | |||
| 539 | if (audit_pid && tsk->tgid == audit_pid) | ||
| 540 | return AUDIT_DISABLED; | ||
| 541 | |||
| 542 | rcu_read_lock(); | ||
| 543 | if (!list_empty(list)) { | ||
| 544 | int word = AUDIT_WORD(ctx->major); | ||
| 545 | int bit = AUDIT_BIT(ctx->major); | ||
| 546 | |||
| 547 | list_for_each_entry_rcu(e, list, list) { | ||
| 548 | if ((e->rule.mask[word] & bit) == bit | ||
| 549 | && audit_filter_rules(tsk, &e->rule, ctx, &state)) { | ||
| 550 | rcu_read_unlock(); | ||
| 551 | return state; | ||
| 552 | } | ||
| 553 | } | ||
| 554 | } | ||
| 555 | rcu_read_unlock(); | ||
| 556 | return AUDIT_BUILD_CONTEXT; | ||
| 557 | } | ||
| 558 | |||
| 559 | static int audit_filter_user_rules(struct netlink_skb_parms *cb, | ||
| 560 | struct audit_rule *rule, | ||
| 561 | enum audit_state *state) | ||
| 562 | { | ||
| 563 | int i; | ||
| 564 | |||
| 565 | for (i = 0; i < rule->field_count; i++) { | ||
| 566 | u32 field = rule->fields[i] & ~AUDIT_NEGATE; | ||
| 567 | u32 value = rule->values[i]; | ||
| 568 | int result = 0; | ||
| 569 | |||
| 570 | switch (field) { | ||
| 571 | case AUDIT_PID: | ||
| 572 | result = (cb->creds.pid == value); | ||
| 573 | break; | ||
| 574 | case AUDIT_UID: | ||
| 575 | result = (cb->creds.uid == value); | ||
| 576 | break; | ||
| 577 | case AUDIT_GID: | ||
| 578 | result = (cb->creds.gid == value); | ||
| 579 | break; | ||
| 580 | case AUDIT_LOGINUID: | ||
| 581 | result = (cb->loginuid == value); | ||
| 582 | break; | ||
| 583 | } | ||
| 584 | |||
| 585 | if (rule->fields[i] & AUDIT_NEGATE) | ||
| 586 | result = !result; | ||
| 587 | if (!result) | ||
| 588 | return 0; | ||
| 589 | } | ||
| 590 | switch (rule->action) { | ||
| 591 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; | ||
| 592 | case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break; | ||
| 593 | case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break; | ||
| 594 | } | ||
| 595 | return 1; | ||
| 596 | } | ||
| 597 | |||
| 598 | int audit_filter_user(struct netlink_skb_parms *cb, int type) | ||
| 599 | { | ||
| 600 | struct audit_entry *e; | ||
| 477 | enum audit_state state; | 601 | enum audit_state state; |
| 478 | int word = AUDIT_WORD(ctx->major); | 602 | int ret = 1; |
| 479 | int bit = AUDIT_BIT(ctx->major); | ||
| 480 | 603 | ||
| 481 | rcu_read_lock(); | 604 | rcu_read_lock(); |
| 482 | list_for_each_entry_rcu(e, list, list) { | 605 | list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_USER], list) { |
| 483 | if ((e->rule.mask[word] & bit) == bit | 606 | if (audit_filter_user_rules(cb, &e->rule, &state)) { |
| 484 | && audit_filter_rules(tsk, &e->rule, ctx, &state)) { | 607 | if (state == AUDIT_DISABLED) |
| 485 | rcu_read_unlock(); | 608 | ret = 0; |
| 486 | return state; | 609 | break; |
| 487 | } | 610 | } |
| 488 | } | 611 | } |
| 489 | rcu_read_unlock(); | 612 | rcu_read_unlock(); |
| 490 | return AUDIT_BUILD_CONTEXT; | 613 | |
| 614 | return ret; /* Audit by default */ | ||
| 491 | } | 615 | } |
| 492 | 616 | ||
| 493 | /* This should be called with task_lock() held. */ | 617 | /* This should be called with task_lock() held. */ |
| @@ -504,7 +628,7 @@ static inline struct audit_context *audit_get_context(struct task_struct *tsk, | |||
| 504 | 628 | ||
| 505 | if (context->in_syscall && !context->auditable) { | 629 | if (context->in_syscall && !context->auditable) { |
| 506 | enum audit_state state; | 630 | enum audit_state state; |
| 507 | state = audit_filter_syscall(tsk, context, &audit_extlist); | 631 | state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]); |
| 508 | if (state == AUDIT_RECORD_CONTEXT) | 632 | if (state == AUDIT_RECORD_CONTEXT) |
| 509 | context->auditable = 1; | 633 | context->auditable = 1; |
| 510 | } | 634 | } |
| @@ -679,13 +803,13 @@ static void audit_log_task_info(struct audit_buffer *ab) | |||
| 679 | up_read(&mm->mmap_sem); | 803 | up_read(&mm->mmap_sem); |
| 680 | } | 804 | } |
| 681 | 805 | ||
| 682 | static void audit_log_exit(struct audit_context *context) | 806 | static void audit_log_exit(struct audit_context *context, unsigned int gfp_mask) |
| 683 | { | 807 | { |
| 684 | int i; | 808 | int i; |
| 685 | struct audit_buffer *ab; | 809 | struct audit_buffer *ab; |
| 686 | struct audit_aux_data *aux; | 810 | struct audit_aux_data *aux; |
| 687 | 811 | ||
| 688 | ab = audit_log_start(context, AUDIT_SYSCALL); | 812 | ab = audit_log_start(context, gfp_mask, AUDIT_SYSCALL); |
| 689 | if (!ab) | 813 | if (!ab) |
| 690 | return; /* audit_panic has been called */ | 814 | return; /* audit_panic has been called */ |
| 691 | audit_log_format(ab, "arch=%x syscall=%d", | 815 | audit_log_format(ab, "arch=%x syscall=%d", |
| @@ -717,7 +841,7 @@ static void audit_log_exit(struct audit_context *context) | |||
| 717 | 841 | ||
| 718 | for (aux = context->aux; aux; aux = aux->next) { | 842 | for (aux = context->aux; aux; aux = aux->next) { |
| 719 | 843 | ||
| 720 | ab = audit_log_start(context, aux->type); | 844 | ab = audit_log_start(context, GFP_KERNEL, aux->type); |
| 721 | if (!ab) | 845 | if (!ab) |
| 722 | continue; /* audit_panic has been called */ | 846 | continue; /* audit_panic has been called */ |
| 723 | 847 | ||
| @@ -754,14 +878,14 @@ static void audit_log_exit(struct audit_context *context) | |||
| 754 | } | 878 | } |
| 755 | 879 | ||
| 756 | if (context->pwd && context->pwdmnt) { | 880 | if (context->pwd && context->pwdmnt) { |
| 757 | ab = audit_log_start(context, AUDIT_CWD); | 881 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD); |
| 758 | if (ab) { | 882 | if (ab) { |
| 759 | audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt); | 883 | audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt); |
| 760 | audit_log_end(ab); | 884 | audit_log_end(ab); |
| 761 | } | 885 | } |
| 762 | } | 886 | } |
| 763 | for (i = 0; i < context->name_count; i++) { | 887 | for (i = 0; i < context->name_count; i++) { |
| 764 | ab = audit_log_start(context, AUDIT_PATH); | 888 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH); |
| 765 | if (!ab) | 889 | if (!ab) |
| 766 | continue; /* audit_panic has been called */ | 890 | continue; /* audit_panic has been called */ |
| 767 | 891 | ||
| @@ -770,6 +894,8 @@ static void audit_log_exit(struct audit_context *context) | |||
| 770 | audit_log_format(ab, " name="); | 894 | audit_log_format(ab, " name="); |
| 771 | audit_log_untrustedstring(ab, context->names[i].name); | 895 | audit_log_untrustedstring(ab, context->names[i].name); |
| 772 | } | 896 | } |
| 897 | audit_log_format(ab, " flags=%x\n", context->names[i].flags); | ||
| 898 | |||
| 773 | if (context->names[i].ino != (unsigned long)-1) | 899 | if (context->names[i].ino != (unsigned long)-1) |
| 774 | audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o" | 900 | audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o" |
| 775 | " ouid=%u ogid=%u rdev=%02x:%02x", | 901 | " ouid=%u ogid=%u rdev=%02x:%02x", |
| @@ -799,9 +925,11 @@ void audit_free(struct task_struct *tsk) | |||
| 799 | return; | 925 | return; |
| 800 | 926 | ||
| 801 | /* Check for system calls that do not go through the exit | 927 | /* Check for system calls that do not go through the exit |
| 802 | * function (e.g., exit_group), then free context block. */ | 928 | * function (e.g., exit_group), then free context block. |
| 803 | if (context->in_syscall && context->auditable && context->pid != audit_pid) | 929 | * We use GFP_ATOMIC here because we might be doing this |
| 804 | audit_log_exit(context); | 930 | * in the context of the idle thread */ |
| 931 | if (context->in_syscall && context->auditable) | ||
| 932 | audit_log_exit(context, GFP_ATOMIC); | ||
| 805 | 933 | ||
| 806 | audit_free_context(context); | 934 | audit_free_context(context); |
| 807 | } | 935 | } |
| @@ -876,11 +1004,11 @@ void audit_syscall_entry(struct task_struct *tsk, int arch, int major, | |||
| 876 | 1004 | ||
| 877 | state = context->state; | 1005 | state = context->state; |
| 878 | if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT) | 1006 | if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT) |
| 879 | state = audit_filter_syscall(tsk, context, &audit_entlist); | 1007 | state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]); |
| 880 | if (likely(state == AUDIT_DISABLED)) | 1008 | if (likely(state == AUDIT_DISABLED)) |
| 881 | return; | 1009 | return; |
| 882 | 1010 | ||
| 883 | context->serial = audit_serial(); | 1011 | context->serial = 0; |
| 884 | context->ctime = CURRENT_TIME; | 1012 | context->ctime = CURRENT_TIME; |
| 885 | context->in_syscall = 1; | 1013 | context->in_syscall = 1; |
| 886 | context->auditable = !!(state == AUDIT_RECORD_CONTEXT); | 1014 | context->auditable = !!(state == AUDIT_RECORD_CONTEXT); |
| @@ -903,10 +1031,10 @@ void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) | |||
| 903 | /* Not having a context here is ok, since the parent may have | 1031 | /* Not having a context here is ok, since the parent may have |
| 904 | * called __put_task_struct. */ | 1032 | * called __put_task_struct. */ |
| 905 | if (likely(!context)) | 1033 | if (likely(!context)) |
| 906 | return; | 1034 | goto out; |
| 907 | 1035 | ||
| 908 | if (context->in_syscall && context->auditable && context->pid != audit_pid) | 1036 | if (context->in_syscall && context->auditable) |
| 909 | audit_log_exit(context); | 1037 | audit_log_exit(context, GFP_KERNEL); |
| 910 | 1038 | ||
| 911 | context->in_syscall = 0; | 1039 | context->in_syscall = 0; |
| 912 | context->auditable = 0; | 1040 | context->auditable = 0; |
| @@ -919,9 +1047,9 @@ void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) | |||
| 919 | } else { | 1047 | } else { |
| 920 | audit_free_names(context); | 1048 | audit_free_names(context); |
| 921 | audit_free_aux(context); | 1049 | audit_free_aux(context); |
| 922 | audit_zero_context(context, context->state); | ||
| 923 | tsk->audit_context = context; | 1050 | tsk->audit_context = context; |
| 924 | } | 1051 | } |
| 1052 | out: | ||
| 925 | put_task_struct(tsk); | 1053 | put_task_struct(tsk); |
| 926 | } | 1054 | } |
| 927 | 1055 | ||
| @@ -996,7 +1124,7 @@ void audit_putname(const char *name) | |||
| 996 | 1124 | ||
| 997 | /* Store the inode and device from a lookup. Called from | 1125 | /* Store the inode and device from a lookup. Called from |
| 998 | * fs/namei.c:path_lookup(). */ | 1126 | * fs/namei.c:path_lookup(). */ |
| 999 | void audit_inode(const char *name, const struct inode *inode) | 1127 | void audit_inode(const char *name, const struct inode *inode, unsigned flags) |
| 1000 | { | 1128 | { |
| 1001 | int idx; | 1129 | int idx; |
| 1002 | struct audit_context *context = current->audit_context; | 1130 | struct audit_context *context = current->audit_context; |
| @@ -1022,17 +1150,20 @@ void audit_inode(const char *name, const struct inode *inode) | |||
| 1022 | ++context->ino_count; | 1150 | ++context->ino_count; |
| 1023 | #endif | 1151 | #endif |
| 1024 | } | 1152 | } |
| 1025 | context->names[idx].ino = inode->i_ino; | 1153 | context->names[idx].flags = flags; |
| 1026 | context->names[idx].dev = inode->i_sb->s_dev; | 1154 | context->names[idx].ino = inode->i_ino; |
| 1027 | context->names[idx].mode = inode->i_mode; | 1155 | context->names[idx].dev = inode->i_sb->s_dev; |
| 1028 | context->names[idx].uid = inode->i_uid; | 1156 | context->names[idx].mode = inode->i_mode; |
| 1029 | context->names[idx].gid = inode->i_gid; | 1157 | context->names[idx].uid = inode->i_uid; |
| 1030 | context->names[idx].rdev = inode->i_rdev; | 1158 | context->names[idx].gid = inode->i_gid; |
| 1159 | context->names[idx].rdev = inode->i_rdev; | ||
| 1031 | } | 1160 | } |
| 1032 | 1161 | ||
| 1033 | void auditsc_get_stamp(struct audit_context *ctx, | 1162 | void auditsc_get_stamp(struct audit_context *ctx, |
| 1034 | struct timespec *t, unsigned int *serial) | 1163 | struct timespec *t, unsigned int *serial) |
| 1035 | { | 1164 | { |
| 1165 | if (!ctx->serial) | ||
| 1166 | ctx->serial = audit_serial(); | ||
| 1036 | t->tv_sec = ctx->ctime.tv_sec; | 1167 | t->tv_sec = ctx->ctime.tv_sec; |
| 1037 | t->tv_nsec = ctx->ctime.tv_nsec; | 1168 | t->tv_nsec = ctx->ctime.tv_nsec; |
| 1038 | *serial = ctx->serial; | 1169 | *serial = ctx->serial; |
| @@ -1044,7 +1175,7 @@ int audit_set_loginuid(struct task_struct *task, uid_t loginuid) | |||
| 1044 | if (task->audit_context) { | 1175 | if (task->audit_context) { |
| 1045 | struct audit_buffer *ab; | 1176 | struct audit_buffer *ab; |
| 1046 | 1177 | ||
| 1047 | ab = audit_log_start(NULL, AUDIT_LOGIN); | 1178 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN); |
| 1048 | if (ab) { | 1179 | if (ab) { |
| 1049 | audit_log_format(ab, "login pid=%d uid=%u " | 1180 | audit_log_format(ab, "login pid=%d uid=%u " |
| 1050 | "old auid=%u new auid=%u", | 1181 | "old auid=%u new auid=%u", |
| @@ -1153,7 +1284,7 @@ void audit_signal_info(int sig, struct task_struct *t) | |||
| 1153 | extern pid_t audit_sig_pid; | 1284 | extern pid_t audit_sig_pid; |
| 1154 | extern uid_t audit_sig_uid; | 1285 | extern uid_t audit_sig_uid; |
| 1155 | 1286 | ||
| 1156 | if (unlikely(audit_pid && t->pid == audit_pid)) { | 1287 | if (unlikely(audit_pid && t->tgid == audit_pid)) { |
| 1157 | if (sig == SIGTERM || sig == SIGHUP) { | 1288 | if (sig == SIGTERM || sig == SIGHUP) { |
| 1158 | struct audit_context *ctx = current->audit_context; | 1289 | struct audit_context *ctx = current->audit_context; |
| 1159 | audit_sig_pid = current->pid; | 1290 | audit_sig_pid = current->pid; |
