soc: imx: imx-scu: Getting UID from SCU should have response
PATCH 1/1 soc: imx: imx-scu: Getting UID from SCU should have response
The SCU firmware API for getting UID should have response, otherwise, the message stored in function stack could be released and then the response data received from SCU will be stored into that released stack and cause kernel NULL pointer dump.
--- drivers/soc/imx/soc-imx-scu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/imx/soc-imx-scu.c +1 -1
@@ -46,7 +46,7 @@ static ssize_t soc_uid_show(struct device *dev, hdr->func =IMX_SC_MISC_FUNC_UNIQUE_ID ; hdr->size =1 ; - ret =imx_scu_call_rpc (soc_ipc_handle, &msg, false); + ret =imx_scu_call_rpc (soc_ipc_handle, &msg, true);if (ret) {pr_err ("%s: get soc uid failed, ret %d\n" , __func__, ret);return ret;
Signature · 1 line
2.7.4
Quoted 5 lines · Anson Huang
The SCU firmware API for getting UID should have response, otherwise, the message stored in function stack could be released and then the response data received from SCU will be stored into that released stack and cause kernel NULL pointer dump.
This fix looks good, but looking at imx-scu code it seems that passing the incorrect "have_resp" argument to imx_scu_call_rpc or just receiving an unexpected message from SCFW will always result in kernel stack corruption!
This is worth handling inside imx-scu itself: unless a response was explicitly requested it should ignore and print a warning on rx, for example by setting imx_sc_ipc to NULL when not waiting for a response.
Holding on to arbitrary stack pointers is bad.
--
Regards,
Leonard
Quoted 13 lines
drivers/soc/imx/soc-imx-scu.c +1
-1@@ -46,7 +46,7 @@ static ssize_t soc_uid_show(struct device *dev, hdr->func =IMX_SC_MISC_FUNC_UNIQUE_ID ; hdr->size =1 ; - ret =imx_scu_call_rpc (soc_ipc_handle, &msg, false); + ret =imx_scu_call_rpc (soc_ipc_handle, &msg, true);if (ret) {pr_err ("%s: get soc uid failed, ret %d\n" , __func__, ret);return ret;
Hi, Leonard
Quoted 10 lines · Anson Huang
Quoted 4 lines
The SCU firmware API for getting UID should have response, otherwise, the message stored in function stack could be released and then the response data received from SCU will be stored into that released stack and cause kernel NULL pointer dump.
This fix looks good, but looking at imx-scu code it seems that passing the incorrect "
have_resp" argument toimx_scu_call_rpcor just receiving an unexpected message from SCFW will always result in kernel stack corruption!
Quoted 5 lines
This is worth handling inside imx-scu itself: unless a response was explicitly requested it should ignore and print a warning on rx, for example by setting
imx_sc_ipcto NULL when not waiting for a response.Holding on to arbitrary stack pointers is bad.
We noticed this issue recently during the development of ON/OFF button support, this UID is lucky, the stack is NOT released when SCU response data is received, but this fix should be applied.
We talked to Chuck about adding return value for these special APIs, response data needed but no return value from SCU, so very likely we will need a patch in imx_sc_ipc driver to enhance/handle that, will do a patch for it later.
Thanks,
Anson
Shawn Guo
AppliedQuoted 8 lines · Anson Huang
The SCU firmware API for getting UID should have response, otherwise, the message stored in function stack could be released and then the response data received from SCU will be stored into that released stack and cause kernel NULL pointer dump.
Fixes 73feb4d0f8f1 ("soc: imx-scu: Add SoC UID(unique identifier) support")Signed-off-by Anson Huang <[email protected]>
Applied, thanks.