Attention is currently required from: Fred Reitberger, Jason Glenesk, Matt DeVillier, ritul guru.
Hello ritul guru,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/83758?usp=email
to review the following change.
Change subject: [WIP] soc/amd/common/psp_smi_flash: validate target SPI region ID ......................................................................
[WIP] soc/amd/common/psp_smi_flash: validate target SPI region ID
Add and use functions to validate the target non-volatile storage ID in the different command buffer structs.
This patch is a slightly reworked version of parts of CB:65523.
Document #55758 Rev. 2.04 was used as a reference.
Test=TODO, but when selecting SOC_AMD_COMMON_BLOCK_PSP_SMI, Mandolin still builds
Signed-off-by: Felix Held felix-coreboot@felixheld.de Signed-off-by: Ritul Guru ritul.bits@gmail.com Change-Id: Idda0166c862d41d380b2ed21345eead5e0a1c135 --- M src/soc/amd/common/block/psp/psp_smi_flash.c 1 file changed, 46 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/58/83758/1
diff --git a/src/soc/amd/common/block/psp/psp_smi_flash.c b/src/soc/amd/common/block/psp/psp_smi_flash.c index 3c1b920..2c5c38d5 100644 --- a/src/soc/amd/common/block/psp/psp_smi_flash.c +++ b/src/soc/amd/common/block/psp/psp_smi_flash.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */
#include <console/console.h> +#include <device/mmio.h> #include <types.h> #include "psp_def.h"
@@ -45,30 +46,75 @@ struct pspv2_spi_erase_request req; } __packed;
+static bool is_valid_psp_spi_id(u64 target_nv_id) +{ + return target_nv_id == SMI_TARGET_NVRAM || + target_nv_id == SMI_TARGET_RPMC_NVRAM; +} + +static bool is_valid_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf) +{ + return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id)); +} + +static bool is_valid_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf) +{ + return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id)); +} + +static bool is_valid_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf) +{ + return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id)); +} + enum mbox_p2c_status psp_smi_spi_get_info(struct mbox_default_buffer *buffer) { + struct mbox_pspv2_cmd_spi_info *const cmd_buf = + (struct mbox_pspv2_cmd_spi_info *)buffer; + printk(BIOS_SPEW, "PSP: SPI info request\n");
+ if (!is_valid_psp_spi_info(cmd_buf)) + return MBOX_PSP_COMMAND_PROCESS_ERROR; + return MBOX_PSP_UNSUPPORTED; }
enum mbox_p2c_status psp_smi_spi_read(struct mbox_default_buffer *buffer) { + struct mbox_pspv2_cmd_spi_read_write *const cmd_buf = + (struct mbox_pspv2_cmd_spi_read_write *)buffer; + printk(BIOS_SPEW, "PSP: SPI read request\n");
+ if (!is_valid_psp_spi_read_write(cmd_buf)) + return MBOX_PSP_COMMAND_PROCESS_ERROR; + return MBOX_PSP_UNSUPPORTED; }
enum mbox_p2c_status psp_smi_spi_write(struct mbox_default_buffer *buffer) { + struct mbox_pspv2_cmd_spi_read_write *const cmd_buf = + (struct mbox_pspv2_cmd_spi_read_write *)buffer; + printk(BIOS_SPEW, "PSP: SPI write request\n");
+ if (!is_valid_psp_spi_read_write(cmd_buf)) + return MBOX_PSP_COMMAND_PROCESS_ERROR; + return MBOX_PSP_UNSUPPORTED; }
enum mbox_p2c_status psp_smi_spi_erase(struct mbox_default_buffer *buffer) { + struct mbox_pspv2_cmd_spi_erase *const cmd_buf = + (struct mbox_pspv2_cmd_spi_erase *)buffer; + printk(BIOS_SPEW, "PSP: SPI erase request\n");
+ if (!is_valid_psp_spi_erase(cmd_buf)) + return MBOX_PSP_COMMAND_PROCESS_ERROR; + return MBOX_PSP_UNSUPPORTED; }