@@ -530,11 +530,14 @@ static int bzImage64_cleanup(void *loader_data)
}
#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG
-static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len)
+static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len,
+ unsigned int *signature_len, void **signature)
{
return verify_pefile_signature(kernel, kernel_len,
NULL,
- VERIFYING_KEXEC_PE_SIGNATURE);
+ VERIFYING_KEXEC_PE_SIGNATURE,
+ signature_len,
+ signature);
}
#endif
@@ -405,15 +405,19 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
}
#ifdef CONFIG_KEXEC_VERIFY_SIG
-int arch_kexec_kernel_verify_sig(struct kimage *image, void *kernel,
- unsigned long kernel_len)
+int arch_kexec_kernel_verify_sig(struct kimage *image,
+ void *kernel,
+ unsigned long kernel_len,
+ unsigned int *signature_len,
+ void **signature)
{
if (!image->fops || !image->fops->verify_sig) {
pr_debug("kernel loader does not support signature verification.");
return -EKEYREJECTED;
}
- return image->fops->verify_sig(kernel, kernel_len);
+ return image->fops->verify_sig(kernel, kernel_len,
+ signature_len, signature);
}
#endif
@@ -394,6 +394,12 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
* @pelen: Length of the binary image
* @trust_keys: Signing certificate(s) to use as starting points
* @usage: The use to which the key is being put.
+ * @signature_len: If non-NULL the number of bytes in the signature
+ * will be returned in this out parameter
+ * @signature: If non-NULL a pointer to the buffer containing
+ * the file signature will be returned in this out parameter.
+ * The pointer being returned is actually within the buffer
+ * pointed to by pebuf. So the caller should not try to free it.
*
* Validate that the certificate chain inside the PKCS#7 message inside the PE
* binary image intersects keys we already know and trust.
@@ -418,7 +424,9 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
*/
int verify_pefile_signature(const void *pebuf, unsigned pelen,
struct key *trusted_keys,
- enum key_being_used_for usage)
+ enum key_being_used_for usage,
+ unsigned int *signature_len,
+ void **signature)
{
struct pefile_context ctx;
int ret;
@@ -448,6 +456,14 @@ int verify_pefile_signature(const void *pebuf, unsigned pelen,
* contents.
*/
ret = pefile_digest_pe(pebuf, pelen, &ctx);
+ if (ret < 0)
+ goto error;
+
+ /* Check if the caller needs the file signature */
+ if (signature_len != NULL && signature != NULL) {
+ *signature_len = ctx.sig_len;
+ *signature = pebuf + ctx.sig_offset;
+ }
error:
kfree(ctx.digest);
@@ -131,7 +131,9 @@ typedef int (kexec_cleanup_t)(void *loader_data);
#ifdef CONFIG_KEXEC_VERIFY_SIG
typedef int (kexec_verify_sig_t)(const char *kernel_buf,
- unsigned long kernel_len);
+ unsigned long kernel_len,
+ unsigned int *signature_len,
+ void **signature);
#endif
struct kexec_file_ops {
@@ -288,7 +290,9 @@ int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
void * __weak arch_kexec_kernel_image_load(struct kimage *image);
int __weak arch_kimage_file_post_load_cleanup(struct kimage *image);
int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
- unsigned long buf_len);
+ unsigned long buf_len,
+ unsigned int *signature_len,
+ void **signature);
int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
Elf_Shdr *sechdrs, unsigned int relsec);
int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
@@ -42,7 +42,9 @@ extern int verify_pkcs7_signature(const void *data, size_t len,
#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION
extern int verify_pefile_signature(const void *pebuf, unsigned pelen,
struct key *trusted_keys,
- enum key_being_used_for usage);
+ enum key_being_used_for usage,
+ unsigned int *signature_len,
+ void **signature);
#endif
#endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
@@ -54,7 +54,9 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image)
#ifdef CONFIG_KEXEC_VERIFY_SIG
int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
- unsigned long buf_len)
+ unsigned long buf_len,
+ unsigned int *signature_len,
+ void **signature)
{
return -EKEYREJECTED;
}
@@ -126,6 +128,10 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
int ret = 0;
void *ldata;
loff_t size;
+#ifdef CONFIG_KEXEC_VERIFY_SIG
+ unsigned int signature_len;
+ void *signature;
+#endif
ret = kernel_read_file_from_fd(kernel_fd, &image->kernel_buf,
&size, INT_MAX, READING_KEXEC_IMAGE);
@@ -144,12 +150,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
#ifdef CONFIG_KEXEC_VERIFY_SIG
ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf,
- image->kernel_buf_len);
+ image->kernel_buf_len,
+ &signature_len,
+ &signature);
if (ret) {
pr_debug("kernel signature verification failed.\n");
goto out;
}
- pr_debug("kernel signature verification successful.\n");
+ pr_debug("Verified kernel signature. Sig len %d\n", signature_len);
#endif
/* It is possible that there no initramfs is being loaded */
if (!(flags & KEXEC_FILE_NO_INITRAMFS)) {