kexec_file: Restrict at runtime if the kernel is locked down
authorJiri Bohac <jbohac@suse.cz>
Mon, 18 Feb 2019 12:44:58 +0000 (12:44 +0000)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 26 Sep 2019 12:19:06 +0000 (13:19 +0100)
When KEXEC_SIG is not enabled, kernel should not load images through
kexec_file systemcall if the kernel is locked down unless IMA can be used
to validate the image.

[Modified by David Howells to fit with modifications to the previous patch
 and to return -EPERM if the kernel is locked down for consistency with
 other lockdowns]

Signed-off-by: Jiri Bohac <jbohac@suse.cz>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jiri Bohac <jbohac@suse.cz>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
cc: Chun-Yi Lee <jlee@suse.com>
cc: kexec@lists.infradead.org

Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name 0009-kexec_file-Restrict-at-runtime-if-the-kernel-is-lock.patch

kernel/kexec_file.c

index 0a06e120829a0a651e643463a841fe8b9354c364..aa2f8d42d460d5ca3d1e20293e638a6e5b5ef527 100644 (file)
@@ -237,6 +237,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
                }
 
                ret = 0;
+               if (is_ima_appraise_enabled())
+                       break;
+
+               if (kernel_is_locked_down(reason)) {
+                       ret = -EPERM;
+                       goto out;
+               }
+
                break;
 
                /* All other errors are fatal, including nomem, unparseable