Skip to content

Commit fd7af71

Browse files
lian-botorvalds
authored andcommitted
kexec: do not verify the signature without the lockdown or mandatory signature
Signature verification is an important security feature, to protect system from being attacked with a kernel of unknown origin. Kexec rebooting is a way to replace the running kernel, hence need be secured carefully. In the current code of handling signature verification of kexec kernel, the logic is very twisted. It mixes signature verification, IMA signature appraising and kexec lockdown. If there is no KEXEC_SIG_FORCE, kexec kernel image doesn't have one of signature, the supported crypto, and key, we don't think this is wrong, Unless kexec lockdown is executed. IMA is considered as another kind of signature appraising method. If kexec kernel image has signature/crypto/key, it has to go through the signature verification and pass. Otherwise it's seen as verification failure, and won't be loaded. Seems kexec kernel image with an unqualified signature is even worse than those w/o signature at all, this sounds very unreasonable. E.g. If people get a unsigned kernel to load, or a kernel signed with expired key, which one is more dangerous? So, here, let's simplify the logic to improve code readability. If the KEXEC_SIG_FORCE enabled or kexec lockdown enabled, signature verification is mandated. Otherwise, we lift the bar for any kernel image. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Lianbo Jiang <[email protected]> Reviewed-by: Jiri Bohac <[email protected]> Acked-by: Dave Young <[email protected]> Acked-by: Baoquan He <[email protected]> Cc: James Morris <[email protected]> Cc: Matthew Garrett <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b9e20f0 commit fd7af71

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

kernel/kexec_file.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,52 +181,30 @@ void kimage_file_post_load_cleanup(struct kimage *image)
181181
static int
182182
kimage_validate_signature(struct kimage *image)
183183
{
184-
const char *reason;
185184
int ret;
186185

187186
ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf,
188187
image->kernel_buf_len);
189-
switch (ret) {
190-
case 0:
191-
break;
188+
if (ret) {
192189

193-
/* Certain verification errors are non-fatal if we're not
194-
* checking errors, provided we aren't mandating that there
195-
* must be a valid signature.
196-
*/
197-
case -ENODATA:
198-
reason = "kexec of unsigned image";
199-
goto decide;
200-
case -ENOPKG:
201-
reason = "kexec of image with unsupported crypto";
202-
goto decide;
203-
case -ENOKEY:
204-
reason = "kexec of image with unavailable key";
205-
decide:
206190
if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) {
207-
pr_notice("%s rejected\n", reason);
191+
pr_notice("Enforced kernel signature verification failed (%d).\n", ret);
208192
return ret;
209193
}
210194

211-
/* If IMA is guaranteed to appraise a signature on the kexec
195+
/*
196+
* If IMA is guaranteed to appraise a signature on the kexec
212197
* image, permit it even if the kernel is otherwise locked
213198
* down.
214199
*/
215200
if (!ima_appraise_signature(READING_KEXEC_IMAGE) &&
216201
security_locked_down(LOCKDOWN_KEXEC))
217202
return -EPERM;
218203

219-
return 0;
220-
221-
/* All other errors are fatal, including nomem, unparseable
222-
* signatures and signature check failures - even if signatures
223-
* aren't required.
224-
*/
225-
default:
226-
pr_notice("kernel signature verification failed (%d).\n", ret);
204+
pr_debug("kernel signature verification failed (%d).\n", ret);
227205
}
228206

229-
return ret;
207+
return 0;
230208
}
231209
#endif
232210

0 commit comments

Comments
 (0)