public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Cc: 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: Fri, 29 Apr 2022 17:53:23 +0100	[thread overview]
Message-ID: <e368b193-48f9-c8b8-ea70-59bf7ea7304a@linaro.org> (raw)
In-Reply-To: <20220327062202.5720-1-xiam0nd.tong@gmail.com>



On 27/03/2022 07: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).
> 
> 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.
> 
> Cc: stable@vger.kernel.org
> Fixes: 2419e55e532de ("misc: fastrpc: add mmap/unmap support")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
LGTM,

Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

> --- >   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);
>   

      parent reply	other threads:[~2022-04-29 16:53 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
2022-04-29 16:53 ` Srinivas Kandagatla [this message]

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=e368b193-48f9-c8b8-ea70-59bf7ea7304a@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --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=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