Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/83758?usp=email )
(
3 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: soc/amd/common/psp_smi_flash: validate target SPI region ID ......................................................................
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=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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/83758 Reviewed-by: Martin Roth martin.roth@amd.corp-partner.google.com Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/soc/amd/common/block/psp/psp_smi_flash.c 1 file changed, 46 insertions(+), 0 deletions(-)
Approvals: Martin Roth: Looks good to me, approved build bot (Jenkins): Verified
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 b987cec..f1b9d85 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; }