From: Tuo Li <islituo@gmail.com>
To: shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com,
alexander.stein@ew.tq-group.com, quic_mojha@quicinc.com
Cc: linux-arm-kernel@lists.infradead.org,
Linux Kernel <linux-kernel@vger.kernel.org>,
baijiaju1990@outlook.com
Subject: [BUG] firmware: imx: possible null-pointer dereferences and data-inconsistency due to data races in imx_scu_rx_callback()
Date: Mon, 26 Jun 2023 23:30:20 +0800 [thread overview]
Message-ID: <496af9e1-4a25-e68a-da80-ec11126b6dc2@gmail.com> (raw)
Hello,
Our static analysis tool finds some possible data races in the IMX
firmware in Linux 6.4.0.
In the function imx_scu_call_rpc(), the variable sc_ipc->msg is
accessed with holding the lock sc_ipc->lock:
imx_scu_call_rpc() --> Line 203
mutex_lock(&sc_ipc->lock); --> Line 212 (Lock sc_ipc->lock)
sc_ipc->msg = msg; --> Line 216 (Access sc_ipc->msg)
sc_ipc->msg = NULL; --> Line 251 (Access sc_ipc->msg)
However, in the function imx_scu_rx_callback(), the variable
sc_ipc->msg is accessed without holding the lock sc_ipc->lock:
imx_scu_rx_callback() --> Line 112
sc_ipc->msg[0] = *data++; --> Line 129 (Access sc_ipc->msg)
sc_ipc->msg[sc_chan->idx] = *data; --> Line 148 (Access sc_ipc->msg)
I am not sure whether the functions imx_scu_call_rpc() and
imx_scu_rx_callback() can be executed concurrently and whether
the variables sc_ipc in the two functions can be the same. If so,
harmful data races can occur because:
1. If the variable sc_ipc->msg is set to NULL after the if check at
Line 120, null-pointer dereferences may occur at Lines 129 and 148;
2. If sc_ipc->msg is changed by imx_scu_call_rpc() when updating
sc_ipc->msg with data. The values in data can be written to different
msgs and cause data-inconsistency.
I am not quite sure whether these possible data races are real and
how to fix them if they are real.
Any feedback would be appreciated, thanks!
Reported-by: BassCheck <bass@buaa.edu.cn>
Best wishes,
Tuo Li
reply other threads:[~2023-06-26 15:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=496af9e1-4a25-e68a-da80-ec11126b6dc2@gmail.com \
--to=islituo@gmail.com \
--cc=alexander.stein@ew.tq-group.com \
--cc=baijiaju1990@outlook.com \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_mojha@quicinc.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox