public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: trix@redhat.com
Cc: giovanni.cabiddu@intel.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, wojciech.ziemba@intel.com,
	karen.xiang@intel.com, bruce.w.allan@intel.com, bo.cui@intel.com,
	pingchaox.yang@intel.com, qat-linux@intel.com,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] crypto: qat: fix double free in qat_uclo_create_batch_init_list
Date: Mon, 13 Jul 2020 16:19:04 +0200	[thread overview]
Message-ID: <20200713141904.GA3730398@kroah.com> (raw)
In-Reply-To: <20200713140634.14730-1-trix@redhat.com>

On Mon, Jul 13, 2020 at 07:06:34AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> clang static analysis flags this error
> 
> qat_uclo.c:297:3: warning: Attempt to free released memory
>   [unix.Malloc]
>                 kfree(*init_tab_base);
>                 ^~~~~~~~~~~~~~~~~~~~~
> 
> When input *init_tab_base is null, the function allocates memory for
> the head of the list.  When there is problem allocating other list
> elements the list is unwound and freed.  Then a check is made if the
> list head was allocated and is also freed.
> 
> Keeping track of the what may need to be freed is the variable 'tail_old'.
> The unwinding/freeing block is
> 
> 	while (tail_old) {
> 		mem_init = tail_old->next;
> 		kfree(tail_old);
> 		tail_old = mem_init;
> 	}
> 
> The problem is that the first element of tail_old is also what was
> allocated for the list head
> 
> 		init_header = kzalloc(sizeof(*init_header), GFP_KERNEL);
> 		...
> 		*init_tab_base = init_header;
> 		flag = 1;
> 	}
> 	tail_old = init_header;
> 
> So *init_tab_base/init_header are freed twice.
> 
> There is another problem.
> When the input *init_tab_base is non null the tail_old is calculated by
> traveling down the list to first non null entry.
> 
> 	tail_old = init_header;
> 	while (tail_old->next)
> 		tail_old = tail_old->next;
> 
> When the unwinding free happens, the last entry of the input list will
> be freed.
> 
> So the freeing needs a general changed.
> If locally allocated the first element of tail_old is freed, else it
> is skipped.  As a bit of cleanup, reset *init_tab_base if it came in
> as null.
> 
> Fixes: b4b7e67c917f ("crypto: qat - Intel(R) QAT ucode part of fw loader")
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/crypto/qat/qat_common/qat_uclo.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

  reply	other threads:[~2020-07-13 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 14:06 [PATCH] crypto: qat: fix double free in qat_uclo_create_batch_init_list trix
2020-07-13 14:19 ` Greg KH [this message]
2020-07-23  7:56 ` Herbert Xu

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=20200713141904.GA3730398@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=bo.cui@intel.com \
    --cc=bruce.w.allan@intel.com \
    --cc=davem@davemloft.net \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=karen.xiang@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pingchaox.yang@intel.com \
    --cc=qat-linux@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=trix@redhat.com \
    --cc=wojciech.ziemba@intel.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