mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
soc: qcom: geni-se: Fix write to read-only firmware buffer
geni_find_protocol_fw() casts fw->data to a non-const struct se_fw_hdr
pointer and writes back the rounded-up fw_size value:
sefw->fw_size_in_items = cpu_to_le16(fw_size);
The firmware subsystem maps the firmware blob read-only. Writing through
the cast pointer causes a level-3 permission fault on AArch64 and
crashes the kernel during driver probe.
The write-back is no longer necessary: geni_find_protocol_fw() now
propagates the rounded size to the caller via fw_size_out. Remove the
write-back and make sefw (and the hdr pointer in the caller)
const-correct.
Fixes: d4bf06592a ("soc: qcom: geni-se: Add support to load QUP SE Firmware via Linux subsystem")
Cc: stable@vger.kernel.org
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260821-fix-write-to-read-only-firmware-buffer-v3-4-43e6a3abd651@oss.qualcomm.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
This commit is contained in:
parent
091269da39
commit
f38399670d
|
|
@ -1238,17 +1238,17 @@ EXPORT_SYMBOL_GPL(geni_se_resources_init);
|
|||
* controller. Validates the firmware size against the hardware PROG_RAM_DEPTH
|
||||
* read from SE_HW_PARAM_2.
|
||||
*
|
||||
* Return: pointer to a valid 'struct se_fw_hdr' if found, or NULL otherwise.
|
||||
* Return: pointer to a valid 'const struct se_fw_hdr' if found, or NULL otherwise.
|
||||
*/
|
||||
static struct se_fw_hdr *geni_find_protocol_fw(struct geni_se *se, const struct firmware *fw,
|
||||
enum geni_se_protocol_type protocol,
|
||||
u32 *fw_size_out)
|
||||
static const struct se_fw_hdr *geni_find_protocol_fw(struct geni_se *se, const struct firmware *fw,
|
||||
enum geni_se_protocol_type protocol,
|
||||
u32 *fw_size_out)
|
||||
{
|
||||
struct device *dev = se->dev;
|
||||
const struct elf32_hdr *ehdr;
|
||||
const struct elf32_phdr *phdrs;
|
||||
const struct elf32_phdr *phdr;
|
||||
struct se_fw_hdr *sefw;
|
||||
const struct se_fw_hdr *sefw;
|
||||
u32 fw_end, cfg_idx_end, cfg_val_end;
|
||||
u32 prog_ram_depth;
|
||||
u32 fw_size;
|
||||
|
|
@ -1290,7 +1290,7 @@ static struct se_fw_hdr *geni_find_protocol_fw(struct geni_se *se, const struct
|
|||
if (phdr->p_filesz < sizeof(struct se_fw_hdr))
|
||||
continue;
|
||||
|
||||
sefw = (struct se_fw_hdr *)(fw->data + phdr->p_offset);
|
||||
sefw = (const struct se_fw_hdr *)(fw->data + phdr->p_offset);
|
||||
fw_size = le16_to_cpu(sefw->fw_size_in_items);
|
||||
|
||||
if (le32_to_cpu(sefw->magic) != SE_MAGIC_NUM || le32_to_cpu(sefw->version) != 1)
|
||||
|
|
@ -1299,10 +1299,8 @@ static struct se_fw_hdr *geni_find_protocol_fw(struct geni_se *se, const struct
|
|||
if (le16_to_cpu(sefw->serial_protocol) != protocol)
|
||||
continue;
|
||||
|
||||
if (fw_size % 2 != 0) {
|
||||
if (fw_size % 2 != 0)
|
||||
fw_size++;
|
||||
sefw->fw_size_in_items = cpu_to_le16(fw_size);
|
||||
}
|
||||
|
||||
fw_end = le16_to_cpu(sefw->fw_offset) + fw_size * sizeof(u32);
|
||||
cfg_idx_end = le16_to_cpu(sefw->cfg_idx_offset) +
|
||||
|
|
@ -1437,15 +1435,15 @@ static int geni_load_se_fw(struct geni_se *se, const struct firmware *fw,
|
|||
const u8 *cfg_idx_arr;
|
||||
u32 i, reg_value, fw_size_in_items;
|
||||
int ret;
|
||||
struct se_fw_hdr *hdr;
|
||||
const struct se_fw_hdr *hdr;
|
||||
|
||||
hdr = geni_find_protocol_fw(se, fw, protocol, &fw_size_in_items);
|
||||
if (!hdr)
|
||||
return -EINVAL;
|
||||
|
||||
fw_data = (const u32 *)((u8 *)hdr + le16_to_cpu(hdr->fw_offset));
|
||||
fw_data = (const u32 *)((const u8 *)hdr + le16_to_cpu(hdr->fw_offset));
|
||||
cfg_idx_arr = (const u8 *)hdr + le16_to_cpu(hdr->cfg_idx_offset);
|
||||
cfg_val_arr = (const u32 *)((u8 *)hdr + le16_to_cpu(hdr->cfg_val_offset));
|
||||
cfg_val_arr = (const u32 *)((const u8 *)hdr + le16_to_cpu(hdr->cfg_val_offset));
|
||||
|
||||
ret = geni_icc_set_bw(se);
|
||||
if (ret)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user