|
| 1 | +From 7d571d86ed3c464645d86f5d4750b197f7ccacdb Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dan Streetman < [email protected]> |
| 3 | +Date: Fri, 6 Dec 2024 11:34:22 -0500 |
| 4 | +Subject: [PATCH] change hardcoded 'firmware' location of sk_loader and sk to |
| 5 | + per-kernel namespaced location |
| 6 | + |
| 7 | +Instead of the sk_loader and sk living in a common 'firmware' |
| 8 | +directory, find them in a location specific to the currently running |
| 9 | +kernel, i.e. /lib/modules/$(uname -r)/secure/ |
| 10 | +--- |
| 11 | + drivers/hv/hv_vsm_boot.c | 37 +++++++++++++++++++++++++++++-------- |
| 12 | + 1 file changed, 29 insertions(+), 8 deletions(-) |
| 13 | + |
| 14 | +diff --git a/drivers/hv/hv_vsm_boot.c b/drivers/hv/hv_vsm_boot.c |
| 15 | +index c932b468f931..eef8a77d0022 100644 |
| 16 | +--- a/drivers/hv/hv_vsm_boot.c |
| 17 | ++++ b/drivers/hv/hv_vsm_boot.c |
| 18 | +@@ -16,6 +16,7 @@ |
| 19 | + #include <linux/fs.h> |
| 20 | + #include <linux/slab.h> |
| 21 | + #include <linux/cpumask.h> |
| 22 | ++#include <linux/utsname.h> |
| 23 | + #include <linux/vmalloc.h> |
| 24 | + #include <linux/vsm.h> |
| 25 | + #include <linux/verification.h> |
| 26 | +@@ -915,6 +916,8 @@ static int __init hv_vsm_load_secure_kernel(void) |
| 27 | + |
| 28 | + int __init hv_vsm_boot_init(void) |
| 29 | + { |
| 30 | ++ char *sk_loader_path = NULL, *sk_path = NULL; |
| 31 | ++ char *sk_loader_sig_path = NULL, *sk_sig_path = NULL; |
| 32 | + cpumask_var_t mask; |
| 33 | + unsigned int boot_cpu; |
| 34 | + u16 partition_enabled_vtl_set = 0, partition_mbec_enabled_vtl_set = 0; |
| 35 | +@@ -931,29 +934,43 @@ int __init hv_vsm_boot_init(void) |
| 36 | + return -ENOMEM; |
| 37 | + } |
| 38 | + |
| 39 | +- sk_loader = filp_open("/usr/lib/firmware/skloader.bin", O_RDONLY, 0); |
| 40 | ++ sk_loader_path = kasprintf(GFP_KERNEL, "/lib/modules/%s/secure/skloader.bin", |
| 41 | ++ init_utsname()->release); |
| 42 | ++ sk_path = kasprintf(GFP_KERNEL, "/lib/modules/%s/secure/vmlinux.bin", |
| 43 | ++ init_utsname()->release); |
| 44 | ++ if (!sk_loader_path || !sk_path) { |
| 45 | ++ ret = -ENOMEM; |
| 46 | ++ goto free_mem; |
| 47 | ++ } |
| 48 | ++ sk_loader = filp_open(sk_loader_path, O_RDONLY, 0); |
| 49 | + if (IS_ERR(sk_loader)) { |
| 50 | +- pr_err("%s: File usr/lib/firmware/skloader.bin not found\n", __func__); |
| 51 | ++ pr_err("%s: File %s not found\n", __func__, sk_loader_path); |
| 52 | + ret = -ENOENT; |
| 53 | + goto free_mem; |
| 54 | + } |
| 55 | +- sk = filp_open("/usr/lib/firmware/vmlinux.bin", O_RDONLY, 0); |
| 56 | ++ sk = filp_open(sk_path, O_RDONLY, 0); |
| 57 | + if (IS_ERR(sk)) { |
| 58 | +- pr_err("%s: File usr/lib/firmware/vmlinux.bin not found\n", __func__); |
| 59 | ++ pr_err("%s: File %s not found\n", __func__, sk_path); |
| 60 | + ret = -ENOENT; |
| 61 | + goto close_skl_file; |
| 62 | + } |
| 63 | + |
| 64 | + #ifndef CONFIG_HYPERV_VSM_DISABLE_IMG_VERIFY |
| 65 | +- sk_loader_sig = filp_open("/usr/lib/firmware/skloader.bin.p7s", O_RDONLY, 0); |
| 66 | ++ sk_loader_sig_path = kasprintf(GFP_KERNEL, "%s.p7s", sk_loader_path); |
| 67 | ++ sk_sig_path = kasprintf(GFP_KERNEL, "%s.p7s", sk_path); |
| 68 | ++ if (!sk_loader_sig_path || !sk_sig_path) { |
| 69 | ++ ret = -ENOMEM; |
| 70 | ++ goto close_sk_file; |
| 71 | ++ } |
| 72 | ++ sk_loader_sig = filp_open(sk_loader_sig_path, O_RDONLY, 0); |
| 73 | + if (IS_ERR(sk_loader_sig)) { |
| 74 | +- pr_err("%s: File usr/lib/firmware/skloader.bin.p7s not found\n", __func__); |
| 75 | ++ pr_err("%s: File %s not found\n", __func__, sk_loader_sig_path); |
| 76 | + ret = -ENOENT; |
| 77 | + goto close_sk_file; |
| 78 | + } |
| 79 | +- sk_sig = filp_open("/usr/lib/firmware/vmlinux.bin.p7s", O_RDONLY, 0); |
| 80 | ++ sk_sig = filp_open(sk_sig_path, O_RDONLY, 0); |
| 81 | + if (IS_ERR(sk_sig)) { |
| 82 | +- pr_err("%s: File usr/lib/firmware/vmlinux.bin.p7s not found\n", __func__); |
| 83 | ++ pr_err("%s: File %s not found\n", __func__, sk_sig_path); |
| 84 | + ret = -ENOENT; |
| 85 | + goto close_skl_sig_file; |
| 86 | + } |
| 87 | +@@ -1079,5 +1096,9 @@ int __init hv_vsm_boot_init(void) |
| 88 | + free_mem: |
| 89 | + vunmap(vsm_skm_va); |
| 90 | + vsm_skm_pa = 0; |
| 91 | ++ kfree(sk_sig_path); |
| 92 | ++ kfree(sk_loader_sig_path); |
| 93 | ++ kfree(sk_path); |
| 94 | ++ kfree(sk_loader_path); |
| 95 | + return ret; |
| 96 | + } |
| 97 | +-- |
| 98 | +2.43.0 |
| 99 | + |
0 commit comments