lib/mpi: Fix karactx leak in mpi_powm
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 24 Jun 2019 10:32:26 +0000 (18:32 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Jul 2019 07:54:40 +0000 (09:54 +0200)
commit9fbe87fc25ad9b169505ab6ad282c7072b2d275e
tree2d44dcca46f5187caa512ea3c364bca0fa4a75dd
parent76cdeea3b1fdfbcbfbcf5c9c15d48639323be4e8
lib/mpi: Fix karactx leak in mpi_powm

commit c8ea9fce2baf7b643384f36f29e4194fa40d33a6 upstream.

Sometimes mpi_powm will leak karactx because a memory allocation
failure causes a bail-out that skips the freeing of karactx.  This
patch moves the freeing of karactx to the end of the function like
everything else so that it can't be skipped.

Reported-by: syzbot+f7baccc38dcc1e094e77@syzkaller.appspotmail.com
Fixes: cdec9cb5167a ("crypto: GnuPG based MPI lib - source files...")
Cc: <stable@vger.kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/mpi/mpi-pow.c