2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2025-01-04 19:54:03 +08:00

IMA: use audit_log_untrusted_string rather than %s

Convert all of the places IMA calls audit_log_format with %s into
audit_log_untrusted_string().  This is going to cause them all to get
quoted, but it should make audit log injection harder.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Mimi Zohar <zohar@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
This commit is contained in:
Eric Paris 2010-04-20 10:21:30 -04:00 committed by James Morris
parent 7233e3ee22
commit 2f1506cd82

View File

@ -255,6 +255,13 @@ static int ima_lsm_rule_init(struct ima_measure_rule_entry *entry,
return result; return result;
} }
static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
{
audit_log_format(ab, "%s=", key);
audit_log_untrustedstring(ab, value);
audit_log_format(ab, " ");
}
static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry) static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
{ {
struct audit_buffer *ab; struct audit_buffer *ab;
@ -277,7 +284,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
token = match_token(p, policy_tokens, args); token = match_token(p, policy_tokens, args);
switch (token) { switch (token) {
case Opt_measure: case Opt_measure:
audit_log_format(ab, "%s ", "measure"); ima_log_string(ab, "action", "measure");
if (entry->action != UNKNOWN) if (entry->action != UNKNOWN)
result = -EINVAL; result = -EINVAL;
@ -285,7 +292,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
entry->action = MEASURE; entry->action = MEASURE;
break; break;
case Opt_dont_measure: case Opt_dont_measure:
audit_log_format(ab, "%s ", "dont_measure"); ima_log_string(ab, "action", "dont_measure");
if (entry->action != UNKNOWN) if (entry->action != UNKNOWN)
result = -EINVAL; result = -EINVAL;
@ -293,7 +300,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
entry->action = DONT_MEASURE; entry->action = DONT_MEASURE;
break; break;
case Opt_func: case Opt_func:
audit_log_format(ab, "func=%s ", args[0].from); ima_log_string(ab, "func", args[0].from);
if (entry->func) if (entry->func)
result = -EINVAL; result = -EINVAL;
@ -313,7 +320,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
entry->flags |= IMA_FUNC; entry->flags |= IMA_FUNC;
break; break;
case Opt_mask: case Opt_mask:
audit_log_format(ab, "mask=%s ", args[0].from); ima_log_string(ab, "mask", args[0].from);
if (entry->mask) if (entry->mask)
result = -EINVAL; result = -EINVAL;
@ -332,7 +339,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
entry->flags |= IMA_MASK; entry->flags |= IMA_MASK;
break; break;
case Opt_fsmagic: case Opt_fsmagic:
audit_log_format(ab, "fsmagic=%s ", args[0].from); ima_log_string(ab, "fsmagic", args[0].from);
if (entry->fsmagic) { if (entry->fsmagic) {
result = -EINVAL; result = -EINVAL;
@ -345,7 +352,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
entry->flags |= IMA_FSMAGIC; entry->flags |= IMA_FSMAGIC;
break; break;
case Opt_uid: case Opt_uid:
audit_log_format(ab, "uid=%s ", args[0].from); ima_log_string(ab, "uid", args[0].from);
if (entry->uid != -1) { if (entry->uid != -1) {
result = -EINVAL; result = -EINVAL;
@ -362,44 +369,44 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
} }
break; break;
case Opt_obj_user: case Opt_obj_user:
audit_log_format(ab, "obj_user=%s ", args[0].from); ima_log_string(ab, "obj_user", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_OBJ_USER, LSM_OBJ_USER,
AUDIT_OBJ_USER); AUDIT_OBJ_USER);
break; break;
case Opt_obj_role: case Opt_obj_role:
audit_log_format(ab, "obj_role=%s ", args[0].from); ima_log_string(ab, "obj_role", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_OBJ_ROLE, LSM_OBJ_ROLE,
AUDIT_OBJ_ROLE); AUDIT_OBJ_ROLE);
break; break;
case Opt_obj_type: case Opt_obj_type:
audit_log_format(ab, "obj_type=%s ", args[0].from); ima_log_string(ab, "obj_type", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_OBJ_TYPE, LSM_OBJ_TYPE,
AUDIT_OBJ_TYPE); AUDIT_OBJ_TYPE);
break; break;
case Opt_subj_user: case Opt_subj_user:
audit_log_format(ab, "subj_user=%s ", args[0].from); ima_log_string(ab, "subj_user", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_SUBJ_USER, LSM_SUBJ_USER,
AUDIT_SUBJ_USER); AUDIT_SUBJ_USER);
break; break;
case Opt_subj_role: case Opt_subj_role:
audit_log_format(ab, "subj_role=%s ", args[0].from); ima_log_string(ab, "subj_role", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_SUBJ_ROLE, LSM_SUBJ_ROLE,
AUDIT_SUBJ_ROLE); AUDIT_SUBJ_ROLE);
break; break;
case Opt_subj_type: case Opt_subj_type:
audit_log_format(ab, "subj_type=%s ", args[0].from); ima_log_string(ab, "subj_type", args[0].from);
result = ima_lsm_rule_init(entry, args[0].from, result = ima_lsm_rule_init(entry, args[0].from,
LSM_SUBJ_TYPE, LSM_SUBJ_TYPE,
AUDIT_SUBJ_TYPE); AUDIT_SUBJ_TYPE);
break; break;
case Opt_err: case Opt_err:
ima_log_string(ab, "UNKNOWN", p);
result = -EINVAL; result = -EINVAL;
audit_log_format(ab, "UNKNOWN=%s ", p);
break; break;
} }
} }