Skip to content

Commit 2d38dbf

Browse files
keesgregkh
authored andcommitted
test_firmware: Test platform fw loading on non-EFI systems
On non-EFI systems, it wasn't possible to test the platform firmware loader because it will have never set "checked_fw" during __init. Instead, allow the test code to override this check. Additionally split the declarations into a private header file so it there is greater enforcement of the symbol visibility. Fixes: 548193c ("test_firmware: add support for firmware_request_platform") Cc: [email protected] Acked-by: Scott Branden <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 90b109d commit 2d38dbf

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

drivers/firmware/efi/embedded-firmware.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
#include <linux/vmalloc.h>
1515
#include <crypto/sha.h>
1616

17+
#include "embedded-firmware.h"
18+
19+
#ifdef CONFIG_TEST_FIRMWARE
20+
# define EFI_EMBEDDED_FW_VISIBILITY
21+
#else
22+
# define EFI_EMBEDDED_FW_VISIBILITY static
23+
#endif
24+
25+
EFI_EMBEDDED_FW_VISIBILITY LIST_HEAD(efi_embedded_fw_list);
26+
EFI_EMBEDDED_FW_VISIBILITY bool efi_embedded_fw_checked;
27+
1728
/* Exported for use by lib/test_firmware.c only */
18-
LIST_HEAD(efi_embedded_fw_list);
29+
#ifdef CONFIG_TEST_FIRMWARE
1930
EXPORT_SYMBOL_GPL(efi_embedded_fw_list);
20-
21-
static bool checked_for_fw;
31+
EXPORT_SYMBOL_GPL(efi_embedded_fw_checked);
32+
#endif
2233

2334
static const struct dmi_system_id * const embedded_fw_table[] = {
2435
#ifdef CONFIG_TOUCHSCREEN_DMI
@@ -119,14 +130,14 @@ void __init efi_check_for_embedded_firmwares(void)
119130
}
120131
}
121132

122-
checked_for_fw = true;
133+
efi_embedded_fw_checked = true;
123134
}
124135

125136
int efi_get_embedded_fw(const char *name, const u8 **data, size_t *size)
126137
{
127138
struct efi_embedded_fw *iter, *fw = NULL;
128139

129-
if (!checked_for_fw) {
140+
if (!efi_embedded_fw_checked) {
130141
pr_warn("Warning %s called while we did not check for embedded fw\n",
131142
__func__);
132143
return -ENOENT;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _EFI_EMBEDDED_FW_INTERNAL_H_
3+
#define _EFI_EMBEDDED_FW_INTERNAL_H_
4+
5+
/*
6+
* This struct and efi_embedded_fw_list are private to the efi-embedded fw
7+
* implementation they only in separate header for use by lib/test_firmware.c.
8+
*/
9+
struct efi_embedded_fw {
10+
struct list_head list;
11+
const char *name;
12+
const u8 *data;
13+
size_t length;
14+
};
15+
16+
extern struct list_head efi_embedded_fw_list;
17+
extern bool efi_embedded_fw_checked;
18+
19+
#endif /* _EFI_EMBEDDED_FW_INTERNAL_H_ */

include/linux/efi_embedded_fw.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77

88
#define EFI_EMBEDDED_FW_PREFIX_LEN 8
99

10-
/*
11-
* This struct and efi_embedded_fw_list are private to the efi-embedded fw
12-
* implementation they are in this header for use by lib/test_firmware.c only!
13-
*/
14-
struct efi_embedded_fw {
15-
struct list_head list;
16-
const char *name;
17-
const u8 *data;
18-
size_t length;
19-
};
20-
21-
extern struct list_head efi_embedded_fw_list;
22-
2310
/**
2411
* struct efi_embedded_fw_desc - This struct is used by the EFI embedded-fw
2512
* code to search for embedded firmwares.

lib/test_firmware.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ static ssize_t trigger_request_store(struct device *dev,
489489
static DEVICE_ATTR_WO(trigger_request);
490490

491491
#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
492+
#include "../drivers/firmware/efi/embedded-firmware.h"
492493
static ssize_t trigger_request_platform_store(struct device *dev,
493494
struct device_attribute *attr,
494495
const char *buf, size_t count)
@@ -501,6 +502,7 @@ static ssize_t trigger_request_platform_store(struct device *dev,
501502
};
502503
struct efi_embedded_fw efi_embedded_fw;
503504
const struct firmware *firmware = NULL;
505+
bool saved_efi_embedded_fw_checked;
504506
char *name;
505507
int rc;
506508

@@ -513,6 +515,8 @@ static ssize_t trigger_request_platform_store(struct device *dev,
513515
efi_embedded_fw.data = (void *)test_data;
514516
efi_embedded_fw.length = sizeof(test_data);
515517
list_add(&efi_embedded_fw.list, &efi_embedded_fw_list);
518+
saved_efi_embedded_fw_checked = efi_embedded_fw_checked;
519+
efi_embedded_fw_checked = true;
516520

517521
pr_info("loading '%s'\n", name);
518522
rc = firmware_request_platform(&firmware, name, dev);
@@ -530,6 +534,7 @@ static ssize_t trigger_request_platform_store(struct device *dev,
530534
rc = count;
531535

532536
out:
537+
efi_embedded_fw_checked = saved_efi_embedded_fw_checked;
533538
release_firmware(firmware);
534539
list_del(&efi_embedded_fw.list);
535540
kfree(name);

0 commit comments

Comments
 (0)