Skip to content

Commit c8ba56b

Browse files
committed
Merge tag 'integrity-v5.17-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity fixes from Mimi Zohar: "Fixes for recently found bugs. One was found/noticed while reviewing IMA support for fsverity digests and signatures. Two of them were found/noticed while working on IMA namespacing. Plus two other bugs. All of them are for previous kernel releases" * tag 'integrity-v5.17-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: Do not print policy rule with inactive LSM labels ima: Allow template selection with ima_template[_fmt]= after ima_hash= ima: Remove ima_policy file before directory integrity: check the return value of audit_log_start() ima: fix reference leak in asymmetric_verify()
2 parents dfd42fa + 8967719 commit c8ba56b

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

security/integrity/digsig_asymmetric.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,25 @@ int asymmetric_verify(struct key *keyring, const char *sig,
109109

110110
pk = asymmetric_key_public_key(key);
111111
pks.pkey_algo = pk->pkey_algo;
112-
if (!strcmp(pk->pkey_algo, "rsa"))
112+
if (!strcmp(pk->pkey_algo, "rsa")) {
113113
pks.encoding = "pkcs1";
114-
else if (!strncmp(pk->pkey_algo, "ecdsa-", 6))
114+
} else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) {
115115
/* edcsa-nist-p192 etc. */
116116
pks.encoding = "x962";
117-
else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
118-
!strcmp(pk->pkey_algo, "sm2"))
117+
} else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
118+
!strcmp(pk->pkey_algo, "sm2")) {
119119
pks.encoding = "raw";
120-
else
121-
return -ENOPKG;
120+
} else {
121+
ret = -ENOPKG;
122+
goto out;
123+
}
122124

123125
pks.digest = (u8 *)data;
124126
pks.digest_size = datalen;
125127
pks.s = hdr->sig;
126128
pks.s_size = siglen;
127129
ret = verify_signature(key, &pks);
130+
out:
128131
key_put(key);
129132
pr_debug("%s() = %d\n", __func__, ret);
130133
return ret;

security/integrity/ima/ima_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,12 @@ int __init ima_fs_init(void)
496496

497497
return 0;
498498
out:
499+
securityfs_remove(ima_policy);
499500
securityfs_remove(violations);
500501
securityfs_remove(runtime_measurements_count);
501502
securityfs_remove(ascii_runtime_measurements);
502503
securityfs_remove(binary_runtime_measurements);
503504
securityfs_remove(ima_symlink);
504505
securityfs_remove(ima_dir);
505-
securityfs_remove(ima_policy);
506506
return -1;
507507
}

security/integrity/ima/ima_policy.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,14 @@ int ima_policy_show(struct seq_file *m, void *v)
19671967

19681968
rcu_read_lock();
19691969

1970+
/* Do not print rules with inactive LSM labels */
1971+
for (i = 0; i < MAX_LSM_RULES; i++) {
1972+
if (entry->lsm[i].args_p && !entry->lsm[i].rule) {
1973+
rcu_read_unlock();
1974+
return 0;
1975+
}
1976+
}
1977+
19701978
if (entry->action & MEASURE)
19711979
seq_puts(m, pt(Opt_measure));
19721980
if (entry->action & DONT_MEASURE)

security/integrity/ima/ima_template.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static struct ima_template_desc builtin_templates[] = {
2929

3030
static LIST_HEAD(defined_templates);
3131
static DEFINE_SPINLOCK(template_list);
32+
static int template_setup_done;
3233

3334
static const struct ima_template_field supported_fields[] = {
3435
{.field_id = "d", .field_init = ima_eventdigest_init,
@@ -101,10 +102,11 @@ static int __init ima_template_setup(char *str)
101102
struct ima_template_desc *template_desc;
102103
int template_len = strlen(str);
103104

104-
if (ima_template)
105+
if (template_setup_done)
105106
return 1;
106107

107-
ima_init_template_list();
108+
if (!ima_template)
109+
ima_init_template_list();
108110

109111
/*
110112
* Verify that a template with the supplied name exists.
@@ -128,6 +130,7 @@ static int __init ima_template_setup(char *str)
128130
}
129131

130132
ima_template = template_desc;
133+
template_setup_done = 1;
131134
return 1;
132135
}
133136
__setup("ima_template=", ima_template_setup);
@@ -136,7 +139,7 @@ static int __init ima_template_fmt_setup(char *str)
136139
{
137140
int num_templates = ARRAY_SIZE(builtin_templates);
138141

139-
if (ima_template)
142+
if (template_setup_done)
140143
return 1;
141144

142145
if (template_desc_init_fields(str, NULL, NULL) < 0) {
@@ -147,6 +150,7 @@ static int __init ima_template_fmt_setup(char *str)
147150

148151
builtin_templates[num_templates - 1].fmt = str;
149152
ima_template = builtin_templates + num_templates - 1;
153+
template_setup_done = 1;
150154

151155
return 1;
152156
}

security/integrity/integrity_audit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ void integrity_audit_message(int audit_msgno, struct inode *inode,
4545
return;
4646

4747
ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno);
48+
if (!ab)
49+
return;
4850
audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
4951
task_pid_nr(current),
5052
from_kuid(&init_user_ns, current_uid()),

0 commit comments

Comments
 (0)