mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dinh Nguyen <dinguyen@kernel.org>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Cc: gregkh@linuxfoundation.org, richard.gong@intel.com,
	atull@kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [RESEND][PATCH] firmware: stratix10-svc: fix a missing check on list iterator
Date: Mon, 2 May 2022 16:02:59 -0500	[thread overview]
Message-ID: <96911abe-c1c6-42a4-322e-d7b06dae0c8e@kernel.org> (raw)
In-Reply-To: <20220414035609.2239-1-xiam0nd.tong@gmail.com>



On 4/13/22 22:56, Xiaomeng Tong wrote:
> The bug is here:
> 	pmem->vaddr = NULL;
> 
> The list iterator 'pmem' will point to a bogus position containing
> HEAD if the list is empty or no element is found. This case must
> be checked before any use of the iterator, otherwise it will
> lead to a invalid memory access.
> 
> To fix this bug, just gen_pool_free/set NULL/list_del() and return
> when found, otherwise list_del HEAD and return;
> 
> Cc: stable@vger.kernel.org
> Fixes: 7ca5ce896524f ("firmware: add Intel Stratix10 service layer driver")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
> ---
>   drivers/firmware/stratix10-svc.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
> index 29c0a616b317..30093aa82b7f 100644
> --- a/drivers/firmware/stratix10-svc.c
> +++ b/drivers/firmware/stratix10-svc.c
> @@ -941,17 +941,17 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);
>   void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr)
>   {
>   	struct stratix10_svc_data_mem *pmem;
> -	size_t size = 0;
>   
>   	list_for_each_entry(pmem, &svc_data_mem, node)
>   		if (pmem->vaddr == kaddr) {
> -			size = pmem->size;
> -			break;
> +			gen_pool_free(chan->ctrl->genpool,
> +				       (unsigned long)kaddr, pmem->size);
> +			pmem->vaddr = NULL;
> +			list_del(&pmem->node);
> +			return;
>   		}
>   
> -	gen_pool_free(chan->ctrl->genpool, (unsigned long)kaddr, size);
> -	pmem->vaddr = NULL;
> -	list_del(&pmem->node);
> +	list_del(&svc_data_mem);
>   }
>   EXPORT_SYMBOL_GPL(stratix10_svc_free_memory);
>   

Acked-by: Dinh Nguyen <dinguyen@kernel.org>

      reply	other threads:[~2022-05-02 21:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14  3:56 Xiaomeng Tong
2022-05-02 21:02 ` Dinh Nguyen [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=96911abe-c1c6-42a4-322e-d7b06dae0c8e@kernel.org \
    --to=dinguyen@kernel.org \
    --cc=atull@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard.gong@intel.com \
    --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

all inboxes | Powered by JetHome®