firmware/imx-dsp: Fix use_after_free in imx_dsp_setup_channels()
authorHao Ge <gehao@kylinos.cn>
Sun, 8 Oct 2023 03:29:08 +0000 (11:29 +0800)
committerShawn Guo <shawnguo@kernel.org>
Tue, 10 Oct 2023 02:30:29 +0000 (10:30 +0800)
dsp_chan->name and chan_name points to same block of memory,
because dev_err still needs to be used it,so we need free
it's memory after use to avoid use_after_free.

Fixes: e527adfb9b7d ("firmware: imx-dsp: Fix an error handling path in imx_dsp_setup_channels()")
Signed-off-by: Hao Ge <gehao@kylinos.cn>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
drivers/firmware/imx/imx-dsp.c

index 508eab3..a48a58e 100644 (file)
@@ -114,11 +114,11 @@ static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
                dsp_chan->idx = i % 2;
                dsp_chan->ch = mbox_request_channel_byname(cl, chan_name);
                if (IS_ERR(dsp_chan->ch)) {
-                       kfree(dsp_chan->name);
                        ret = PTR_ERR(dsp_chan->ch);
                        if (ret != -EPROBE_DEFER)
                                dev_err(dev, "Failed to request mbox chan %s ret %d\n",
                                        chan_name, ret);
+                       kfree(dsp_chan->name);
                        goto out;
                }