Skip to content

Commit

Permalink
firmware: imx: scu: Fix corruption of header
Browse files Browse the repository at this point in the history
[ Upstream commit f5f27b7 ]

The header of the message to send can be changed if the
response is longer than the request:
 - 1st word, the header is sent
 - the remaining words of the message are sent
 - the response is received asynchronously during the
   execution of the loop, changing the size field in
   the header
 - the for loop test the termination condition using
   the corrupted header

It is the case for the API build_info which has just a
header as request but 3 words in response.

This issue is fixed storing the header locally instead of
using a pointer on it.

Fixes: edbee09 (firmware: imx: add SCU firmware driver support)

Signed-off-by: Franck LENORMAND <[email protected]>
Reviewed-by: Leonard Crestez <[email protected]>
Signed-off-by: Leonard Crestez <[email protected]>
Cc: [email protected]
Reviewed-by: Dong Aisheng <[email protected]>
Signed-off-by: Shawn Guo <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
lenormandfranck authored and gregkh committed Jun 17, 2020
1 parent a1fd068 commit 0070e73
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/firmware/imx/imx-scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ static void imx_scu_rx_callback(struct mbox_client *c, void *msg)

static int imx_scu_ipc_write(struct imx_sc_ipc *sc_ipc, void *msg)
{
struct imx_sc_rpc_msg *hdr = msg;
struct imx_sc_rpc_msg hdr = *(struct imx_sc_rpc_msg *)msg;
struct imx_sc_chan *sc_chan;
u32 *data = msg;
int ret;
int size;
int i;

/* Check size */
if (hdr->size > IMX_SC_RPC_MAX_MSG)
if (hdr.size > IMX_SC_RPC_MAX_MSG)
return -EINVAL;

dev_dbg(sc_ipc->dev, "RPC SVC %u FUNC %u SIZE %u\n", hdr->svc,
hdr->func, hdr->size);
dev_dbg(sc_ipc->dev, "RPC SVC %u FUNC %u SIZE %u\n", hdr.svc,
hdr.func, hdr.size);

size = sc_ipc->fast_ipc ? 1 : hdr->size;
size = sc_ipc->fast_ipc ? 1 : hdr.size;
for (i = 0; i < size; i++) {
sc_chan = &sc_ipc->chans[i % 4];

Expand Down

0 comments on commit 0070e73

Please sign in to comment.