Skip to content

Commit d857db2

Browse files
committed
platform/x86/intel/ifs: Add metadata validation
Bugzilla: https://bugzilla.redhat.com/1971938 commit 48c6e7d Author: Jithu Joseph <jithu.joseph@intel.com> Date: Thu Nov 17 15:04:08 2022 -0800 platform/x86/intel/ifs: Add metadata validation The data portion of a IFS test image file contains a metadata region containing possibly multiple metadata structures in addition to test data and hashes. IFS Metadata layout +----------------------+ 0 |META_TYPE_IFS (=1) | +----------------------+ |meta_size | +----------------------+ |test type | +----------------------+ |fusa info | +----------------------+ |total images | +----------------------+ |current image# | +----------------------+ |total chunks | +----------------------+ |starting chunk | +----------------------+ |size per chunk | +----------------------+ |chunks per stride | +----------------------+ |Reserved[54] | +----------------------+ 256 | | | Test Data/Chunks | | | +----------------------+ meta_size | META_TYPE_END (=0) | +----------------------+ meta_size + 4 | size of end (=8) | +----------------------+ meta_size + 8 Introduce the layout of this meta_data structure and validate the sanity of certain fields of the new image before loading. Tweak references to IFS test image chunks to reflect the updated layout of the test image. [ bp: Massage commit message. ] Signed-off-by: Jithu Joseph <jithu.joseph@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Sohil Mehta <sohil.mehta@intel.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20221117230408.30331-1-jithu.joseph@intel.com Signed-off-by: David Arcari <darcari@redhat.com>
1 parent d901481 commit d857db2

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

drivers/platform/x86/intel/ifs/ifs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ union ifs_status {
197197
* @valid_chunks: number of chunks which could be validated.
198198
* @status: it holds simple status pass/fail/untested
199199
* @scan_details: opaque scan status code from h/w
200+
* @cur_batch: number indicating the currently loaded test file
200201
*/
201202
struct ifs_data {
202203
int integrity_cap_bit;
@@ -207,6 +208,7 @@ struct ifs_data {
207208
int valid_chunks;
208209
int status;
209210
u64 scan_details;
211+
u32 cur_batch;
210212
};
211213

212214
struct ifs_work {

drivers/platform/x86/intel/ifs/load.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@
77

88
#include "ifs.h"
99

10+
#define IFS_CHUNK_ALIGNMENT 256
11+
union meta_data {
12+
struct {
13+
u32 meta_type; // metadata type
14+
u32 meta_size; // size of this entire struct including hdrs.
15+
u32 test_type; // IFS test type
16+
u32 fusa_info; // Fusa info
17+
u32 total_images; // Total number of images
18+
u32 current_image; // Current Image #
19+
u32 total_chunks; // Total number of chunks in this image
20+
u32 starting_chunk; // Starting chunk number in this image
21+
u32 size_per_chunk; // size of each chunk
22+
u32 chunks_per_stride; // number of chunks in a stride
23+
};
24+
u8 padding[IFS_CHUNK_ALIGNMENT];
25+
};
26+
1027
#define IFS_HEADER_SIZE (sizeof(struct microcode_header_intel))
28+
#define META_TYPE_IFS 1
1129
static struct microcode_header_intel *ifs_header_ptr; /* pointer to the ifs image header */
1230
static u64 ifs_hash_ptr; /* Address of ifs metadata (hash) */
1331
static u64 ifs_test_image_ptr; /* 256B aligned address of test pattern */
@@ -128,6 +146,41 @@ static void copy_hashes_authenticate_chunks(struct work_struct *work)
128146
complete(&ifs_done);
129147
}
130148

149+
static int validate_ifs_metadata(struct device *dev)
150+
{
151+
struct ifs_data *ifsd = ifs_get_data(dev);
152+
union meta_data *ifs_meta;
153+
char test_file[64];
154+
int ret = -EINVAL;
155+
156+
snprintf(test_file, sizeof(test_file), "%02x-%02x-%02x-%02x.scan",
157+
boot_cpu_data.x86, boot_cpu_data.x86_model,
158+
boot_cpu_data.x86_stepping, ifsd->cur_batch);
159+
160+
ifs_meta = (union meta_data *)find_meta_data(ifs_header_ptr, META_TYPE_IFS);
161+
if (!ifs_meta) {
162+
dev_err(dev, "IFS Metadata missing in file %s\n", test_file);
163+
return ret;
164+
}
165+
166+
ifs_test_image_ptr = (u64)ifs_meta + sizeof(union meta_data);
167+
168+
/* Scan chunk start must be 256 byte aligned */
169+
if (!IS_ALIGNED(ifs_test_image_ptr, IFS_CHUNK_ALIGNMENT)) {
170+
dev_err(dev, "Scan pattern is not aligned on %d bytes aligned in %s\n",
171+
IFS_CHUNK_ALIGNMENT, test_file);
172+
return ret;
173+
}
174+
175+
if (ifs_meta->current_image != ifsd->cur_batch) {
176+
dev_warn(dev, "Mismatch between filename %s and batch metadata 0x%02x\n",
177+
test_file, ifs_meta->current_image);
178+
return ret;
179+
}
180+
181+
return 0;
182+
}
183+
131184
/*
132185
* IFS requires scan chunks authenticated per each socket in the platform.
133186
* Once the test chunk is authenticated, it is automatically copied to secured memory
@@ -139,8 +192,11 @@ static int scan_chunks_sanity_check(struct device *dev)
139192
struct ifs_work local_work;
140193
int curr_pkg, cpu, ret;
141194

142-
143195
memset(ifsd->pkg_auth, 0, (topology_max_packages() * sizeof(bool)));
196+
ret = validate_ifs_metadata(dev);
197+
if (ret)
198+
return ret;
199+
144200
ifsd->loading_error = false;
145201
ifsd->loaded_version = ifs_header_ptr->rev;
146202

0 commit comments

Comments
 (0)