Merge branch 'audit.b62' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current

* 'audit.b62' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current:
Audit: remove spaces from audit_log_d_path
audit: audit_set_auditable defined but not used
audit: incorrect ref counting in audit tree tag_chunk
audit: Fix possible return value truncation in audit_get_context()
audit: ignore terminating NUL in AUDIT_USER_TTY messages
Audit: fix handling of 'strings' with NULL characters
make the e->rule.xxx shorter in kernel auditfilter.c
auditsc: fix kernel-doc notation
audit: EXECVE record - removed bogus newline

+32 -28
+6 -3
kernel/audit.c
··· 766 767 audit_log_format(ab, " msg="); 768 size = nlmsg_len(nlh); 769 audit_log_n_untrustedstring(ab, data, size); 770 } 771 audit_set_pid(ab, pid); ··· 1385 int audit_string_contains_control(const char *string, size_t len) 1386 { 1387 const unsigned char *p; 1388 - for (p = string; p < (const unsigned char *)string + len && *p; p++) { 1389 if (*p == '"' || *p < 0x21 || *p > 0x7e) 1390 return 1; 1391 } ··· 1440 /* We will allow 11 spaces for ' (deleted)' to be appended */ 1441 pathname = kmalloc(PATH_MAX+11, ab->gfp_mask); 1442 if (!pathname) { 1443 - audit_log_format(ab, "<no memory>"); 1444 return; 1445 } 1446 p = d_path(path, pathname, PATH_MAX+11); 1447 if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */ 1448 /* FIXME: can we save some information here? */ 1449 - audit_log_format(ab, "<too long>"); 1450 } else 1451 audit_log_untrustedstring(ab, p); 1452 kfree(pathname);
··· 766 767 audit_log_format(ab, " msg="); 768 size = nlmsg_len(nlh); 769 + if (size > 0 && 770 + ((unsigned char *)data)[size - 1] == '\0') 771 + size--; 772 audit_log_n_untrustedstring(ab, data, size); 773 } 774 audit_set_pid(ab, pid); ··· 1382 int audit_string_contains_control(const char *string, size_t len) 1383 { 1384 const unsigned char *p; 1385 + for (p = string; p < (const unsigned char *)string + len; p++) { 1386 if (*p == '"' || *p < 0x21 || *p > 0x7e) 1387 return 1; 1388 } ··· 1437 /* We will allow 11 spaces for ' (deleted)' to be appended */ 1438 pathname = kmalloc(PATH_MAX+11, ab->gfp_mask); 1439 if (!pathname) { 1440 + audit_log_string(ab, "<no_memory>"); 1441 return; 1442 } 1443 p = d_path(path, pathname, PATH_MAX+11); 1444 if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */ 1445 /* FIXME: can we save some information here? */ 1446 + audit_log_string(ab, "<too_long>"); 1447 } else 1448 audit_log_untrustedstring(ab, p); 1449 kfree(pathname);
+2
kernel/audit_tree.c
··· 385 mutex_lock(&inode->inotify_mutex); 386 if (inotify_clone_watch(&old->watch, &chunk->watch) < 0) { 387 mutex_unlock(&inode->inotify_mutex); 388 free_chunk(chunk); 389 return -ENOSPC; 390 } ··· 395 chunk->dead = 1; 396 inotify_evict_watch(&chunk->watch); 397 mutex_unlock(&inode->inotify_mutex); 398 put_inotify_watch(&chunk->watch); 399 return 0; 400 }
··· 385 mutex_lock(&inode->inotify_mutex); 386 if (inotify_clone_watch(&old->watch, &chunk->watch) < 0) { 387 mutex_unlock(&inode->inotify_mutex); 388 + put_inotify_watch(&old->watch); 389 free_chunk(chunk); 390 return -ENOSPC; 391 } ··· 394 chunk->dead = 1; 395 inotify_evict_watch(&chunk->watch); 396 mutex_unlock(&inode->inotify_mutex); 397 + put_inotify_watch(&old->watch); 398 put_inotify_watch(&chunk->watch); 399 return 0; 400 }
+8 -8
kernel/auditfilter.c
··· 135 static inline void audit_free_rule(struct audit_entry *e) 136 { 137 int i; 138 - 139 /* some rules don't have associated watches */ 140 - if (e->rule.watch) 141 - audit_put_watch(e->rule.watch); 142 - if (e->rule.fields) 143 - for (i = 0; i < e->rule.field_count; i++) { 144 - struct audit_field *f = &e->rule.fields[i]; 145 kfree(f->lsm_str); 146 security_audit_rule_free(f->lsm_rule); 147 } 148 - kfree(e->rule.fields); 149 - kfree(e->rule.filterkey); 150 kfree(e); 151 } 152
··· 135 static inline void audit_free_rule(struct audit_entry *e) 136 { 137 int i; 138 + struct audit_krule *erule = &e->rule; 139 /* some rules don't have associated watches */ 140 + if (erule->watch) 141 + audit_put_watch(erule->watch); 142 + if (erule->fields) 143 + for (i = 0; i < erule->field_count; i++) { 144 + struct audit_field *f = &erule->fields[i]; 145 kfree(f->lsm_str); 146 security_audit_rule_free(f->lsm_rule); 147 } 148 + kfree(erule->fields); 149 + kfree(erule->filterkey); 150 kfree(e); 151 } 152
+16 -17
kernel/auditsc.c
··· 329 */ 330 331 #ifdef CONFIG_AUDIT_TREE 332 static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) 333 { 334 struct audit_tree_refs *p = ctx->trees; ··· 750 rcu_read_unlock(); 751 } 752 753 - static void audit_set_auditable(struct audit_context *ctx) 754 - { 755 - if (!ctx->prio) { 756 - ctx->prio = 1; 757 - ctx->current_state = AUDIT_RECORD_CONTEXT; 758 - } 759 - } 760 - 761 static inline struct audit_context *audit_get_context(struct task_struct *tsk, 762 int return_valid, 763 - int return_code) 764 { 765 struct audit_context *context = tsk->audit_context; 766 ··· 1024 { 1025 char arg_num_len_buf[12]; 1026 const char __user *tmp_p = p; 1027 - /* how many digits are in arg_num? 3 is the length of a=\n */ 1028 size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 3; 1029 size_t len, len_left, to_send; 1030 size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN; ··· 1110 * so we can be sure nothing was lost. 1111 */ 1112 if ((i == 0) && (too_long)) 1113 - audit_log_format(*ab, "a%d_len=%zu ", arg_num, 1114 has_cntl ? 2*len : len); 1115 1116 /* ··· 1130 buf[to_send] = '\0'; 1131 1132 /* actually log it */ 1133 - audit_log_format(*ab, "a%d", arg_num); 1134 if (too_long) 1135 audit_log_format(*ab, "[%d]", i); 1136 audit_log_format(*ab, "="); ··· 1138 audit_log_n_hex(*ab, buf, to_send); 1139 else 1140 audit_log_format(*ab, "\"%s\"", buf); 1141 - audit_log_format(*ab, "\n"); 1142 1143 p += to_send; 1144 len_left -= to_send; ··· 1165 1166 p = (const char __user *)axi->mm->arg_start; 1167 1168 - audit_log_format(*ab, "argc=%d ", axi->argc); 1169 1170 /* 1171 * we need some kernel buffer to hold the userspace args. Just ··· 1478 case 0: 1479 /* name was specified as a relative path and the 1480 * directory component is the cwd */ 1481 - audit_log_d_path(ab, " name=", &context->pwd); 1482 break; 1483 default: 1484 /* log the name's directory component */ ··· 2149 * __audit_mq_open - record audit data for a POSIX MQ open 2150 * @oflag: open flag 2151 * @mode: mode bits 2152 - * @u_attr: queue attributes 2153 * 2154 */ 2155 void __audit_mq_open(int oflag, mode_t mode, struct mq_attr *attr) ··· 2196 /** 2197 * __audit_mq_notify - record audit data for a POSIX MQ notify 2198 * @mqdes: MQ descriptor 2199 - * @u_notification: Notification event 2200 * 2201 */ 2202
··· 329 */ 330 331 #ifdef CONFIG_AUDIT_TREE 332 + static void audit_set_auditable(struct audit_context *ctx) 333 + { 334 + if (!ctx->prio) { 335 + ctx->prio = 1; 336 + ctx->current_state = AUDIT_RECORD_CONTEXT; 337 + } 338 + } 339 + 340 static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) 341 { 342 struct audit_tree_refs *p = ctx->trees; ··· 742 rcu_read_unlock(); 743 } 744 745 static inline struct audit_context *audit_get_context(struct task_struct *tsk, 746 int return_valid, 747 + long return_code) 748 { 749 struct audit_context *context = tsk->audit_context; 750 ··· 1024 { 1025 char arg_num_len_buf[12]; 1026 const char __user *tmp_p = p; 1027 + /* how many digits are in arg_num? 3 is the length of " a=" */ 1028 size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 3; 1029 size_t len, len_left, to_send; 1030 size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN; ··· 1110 * so we can be sure nothing was lost. 1111 */ 1112 if ((i == 0) && (too_long)) 1113 + audit_log_format(*ab, " a%d_len=%zu", arg_num, 1114 has_cntl ? 2*len : len); 1115 1116 /* ··· 1130 buf[to_send] = '\0'; 1131 1132 /* actually log it */ 1133 + audit_log_format(*ab, " a%d", arg_num); 1134 if (too_long) 1135 audit_log_format(*ab, "[%d]", i); 1136 audit_log_format(*ab, "="); ··· 1138 audit_log_n_hex(*ab, buf, to_send); 1139 else 1140 audit_log_format(*ab, "\"%s\"", buf); 1141 1142 p += to_send; 1143 len_left -= to_send; ··· 1166 1167 p = (const char __user *)axi->mm->arg_start; 1168 1169 + audit_log_format(*ab, "argc=%d", axi->argc); 1170 1171 /* 1172 * we need some kernel buffer to hold the userspace args. Just ··· 1479 case 0: 1480 /* name was specified as a relative path and the 1481 * directory component is the cwd */ 1482 + audit_log_d_path(ab, "name=", &context->pwd); 1483 break; 1484 default: 1485 /* log the name's directory component */ ··· 2150 * __audit_mq_open - record audit data for a POSIX MQ open 2151 * @oflag: open flag 2152 * @mode: mode bits 2153 + * @attr: queue attributes 2154 * 2155 */ 2156 void __audit_mq_open(int oflag, mode_t mode, struct mq_attr *attr) ··· 2197 /** 2198 * __audit_mq_notify - record audit data for a POSIX MQ notify 2199 * @mqdes: MQ descriptor 2200 + * @notification: Notification event 2201 * 2202 */ 2203