From: "Jorge Ramirez-Ortiz, Gmail" <jorge.ramirez.ortiz@gmail.com>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Cc: srinivas.kandagatla@linaro.org, amahesh@qti.qualcomm.com,
arnd@arndb.de, gregkh@linuxfoundation.org,
jorge.ramirez-ortiz@linaro.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] misc: fastrpc: fix an incorrect NULL check on list iterator
Date: Mon, 28 Mar 2022 19:00:01 +0200 [thread overview]
Message-ID: <20220328170001.GA3040725@trex> (raw)
In-Reply-To: <20220327062202.5720-1-xiam0nd.tong@gmail.com>
On 27/03/22, Xiaomeng Tong wrote:
> The bug is here:
> if (!buf) {
>
> The list iterator value 'buf' will *always* be set and non-NULL
> by list_for_each_entry(), so it is incorrect to assume that the
> iterator value will be NULL if the list is empty (in this case, the
> check 'if (!buf) {' will always be false and never exit expectly).
yes.
>
> To fix the bug, use a new variable 'iter' as the list iterator,
> while use the original variable 'buf' as a dedicated pointer to
> point to the found element.
LGTM
>
> Cc: stable@vger.kernel.org
> Fixes: 2419e55e532de ("misc: fastrpc: add mmap/unmap support")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
> ---
> drivers/misc/fastrpc.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index aa1682b94a23..45aaf54a7560 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -1353,17 +1353,18 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
> struct fastrpc_req_munmap *req)
> {
> struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
> - struct fastrpc_buf *buf, *b;
> + struct fastrpc_buf *buf = NULL, *iter, *b;
> struct fastrpc_munmap_req_msg req_msg;
> struct device *dev = fl->sctx->dev;
> int err;
> u32 sc;
>
> spin_lock(&fl->lock);
> - list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
> - if ((buf->raddr == req->vaddrout) && (buf->size == req->size))
> + list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
> + if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) {
> + buf = iter;
> break;
> - buf = NULL;
> + }
> }
> spin_unlock(&fl->lock);
>
> --
> 2.17.1
>
next prev parent reply other threads:[~2022-03-28 17:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 6:22 [PATCH] misc: fastrpc: fix an incorrect NULL check on list iterator Xiaomeng Tong
2022-03-28 17:00 ` Jorge Ramirez-Ortiz, Gmail [this message]
2022-04-29 16:53 ` Srinivas Kandagatla
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=20220328170001.GA3040725@trex \
--to=jorge.ramirez.ortiz@gmail.com \
--cc=amahesh@qti.qualcomm.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jorge.ramirez-ortiz@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=stable@vger.kernel.org \
--cc=xiam0nd.tong@gmail.com \
/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