* memory leak in mpihelp_mul_karatsuba_case
@ 2019-06-24 7:27 syzbot
2019-06-24 10:32 ` lib/mpi: Fix karactx leak in mpi_powm Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2019-06-24 7:27 UTC (permalink / raw)
To: davem, herbert, linux-crypto, linux-kernel, syzkaller-bugs
Hello,
syzbot found the following crash on:
HEAD commit: abf02e29 Merge tag 'pm-5.2-rc6' of git://git.kernel.org/pu..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17a8bfeaa00000
kernel config: https://syzkaller.appspot.com/x/.config?x=56f1da14935c3cce
dashboard link: https://syzkaller.appspot.com/bug?extid=f7baccc38dcc1e094e77
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=171aa7e6a00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=153306cea00000
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+f7baccc38dcc1e094e77@syzkaller.appspotmail.com
ffffffffda RBX: 0000000000000000 RCX: 0000000000441ac9
BUG: memory leak
unreferenced object 0xffff88811f4da200 (size 512):
comm "syz-executor301", pid 7045, jiffies 4294955450 (age 7.850s)
hex dump (first 32 bytes):
ad dc f4 43 66 b0 1a 88 8f 0c 17 d5 86 34 3a 85 ...Cf........4:.
e3 63 c8 bf 2e 3b f5 0d 1c ab 63 30 15 fe a1 e9 .c...;....c0....
backtrace:
[<00000000d5589961>] kmemleak_alloc_recursive
include/linux/kmemleak.h:43 [inline]
[<00000000d5589961>] slab_post_alloc_hook mm/slab.h:439 [inline]
[<00000000d5589961>] slab_alloc mm/slab.c:3326 [inline]
[<00000000d5589961>] __do_kmalloc mm/slab.c:3658 [inline]
[<00000000d5589961>] __kmalloc+0x161/0x2c0 mm/slab.c:3669
[<00000000022eaa00>] kmalloc include/linux/slab.h:552 [inline]
[<00000000022eaa00>] mpi_alloc_limb_space+0x29/0x50 lib/mpi/mpiutil.c:64
[<00000000d637c699>] mpihelp_mul_karatsuba_case+0x67/0x460
lib/mpi/mpih-mul.c:331
[<00000000401dc6f9>] mpi_powm+0x7b0/0xdd0 lib/mpi/mpi-pow.c:225
[<00000000be8dcb84>] _compute_val crypto/dh.c:39 [inline]
[<00000000be8dcb84>] dh_compute_value+0x160/0x220 crypto/dh.c:178
[<00000000471846ad>] crypto_kpp_generate_public_key
include/crypto/kpp.h:315 [inline]
[<00000000471846ad>] __keyctl_dh_compute+0x447/0x970
security/keys/dh.c:367
[<000000002f6d650d>] keyctl_dh_compute+0x67/0xa6 security/keys/dh.c:422
[<00000000b798bc7f>] __do_sys_keyctl security/keys/keyctl.c:1737
[inline]
[<00000000b798bc7f>] __se_sys_keyctl security/keys/keyctl.c:1633
[inline]
[<00000000b798bc7f>] __x64_sys_keyctl+0xa5/0x330
security/keys/keyctl.c:1633
[<000000007a6f9515>] do_syscall_64+0x76/0x1a0
arch/x86/entry/common.c:301
[<00000000057f2768>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
BUG: memory leak
unreferenced object 0xffff88811f4dac00 (size 512):
comm "syz-executor301", pid 7045, jiffies 4294955450 (age 7.850s)
hex dump (first 32 bytes):
62 72 c4 ae ac af a3 ba e5 24 da a5 30 5e cb c4 br.......$..0^..
a6 46 44 39 76 2e 42 f6 85 6a 5b ad ae 97 4e 83 .FD9v.B..j[...N.
backtrace:
[<00000000d5589961>] kmemleak_alloc_recursive
include/linux/kmemleak.h:43 [inline]
[<00000000d5589961>] slab_post_alloc_hook mm/slab.h:439 [inline]
[<00000000d5589961>] slab_alloc mm/slab.c:3326 [inline]
[<00000000d5589961>] __do_kmalloc mm/slab.c:3658 [inline]
[<00000000d5589961>] __kmalloc+0x161/0x2c0 mm/slab.c:3669
[<00000000022eaa00>] kmalloc include/linux/slab.h:552 [inline]
[<00000000022eaa00>] mpi_alloc_limb_space+0x29/0x50 lib/mpi/mpiutil.c:64
[<0000000025804541>] mpihelp_mul_karatsuba_case+0x394/0x460
lib/mpi/mpih-mul.c:346
[<00000000401dc6f9>] mpi_powm+0x7b0/0xdd0 lib/mpi/mpi-pow.c:225
[<00000000be8dcb84>] _compute_val crypto/dh.c:39 [inline]
[<00000000be8dcb84>] dh_compute_value+0x160/0x220 crypto/dh.c:178
[<00000000471846ad>] crypto_kpp_generate_public_key
include/crypto/kpp.h:315 [inline]
[<00000000471846ad>] __keyctl_dh_compute+0x447/0x970
security/keys/dh.c:367
[<000000002f6d650d>] keyctl_dh_compute+0x67/0xa6 security/keys/dh.c:422
[<00000000b798bc7f>] __do_sys_keyctl security/keys/keyctl.c:1737
[inline]
[<00000000b798bc7f>] __se_sys_keyctl security/keys/keyctl.c:1633
[inline]
[<00000000b798bc7f>] __x64_sys_keyctl+0xa5/0x330
security/keys/keyctl.c:1633
[<000000007a6f9515>] do_syscall_64+0x76/0x1a0
arch/x86/entry/common.c:301
[<00000000057f2768>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches
^ permalink raw reply [flat|nested] 3+ messages in thread* lib/mpi: Fix karactx leak in mpi_powm 2019-06-24 7:27 memory leak in mpihelp_mul_karatsuba_case syzbot @ 2019-06-24 10:32 ` Herbert Xu 2019-06-24 21:17 ` Eric Biggers 0 siblings, 1 reply; 3+ messages in thread From: Herbert Xu @ 2019-06-24 10:32 UTC (permalink / raw) To: syzbot; +Cc: davem, linux-crypto, linux-kernel, syzkaller-bugs On Mon, Jun 24, 2019 at 12:27:08AM -0700, syzbot wrote: > Hello, > > syzbot found the following crash on: > > HEAD commit: abf02e29 Merge tag 'pm-5.2-rc6' of git://git.kernel.org/pu.. > git tree: upstream > console output: https://syzkaller.appspot.com/x/log.txt?x=17a8bfeaa00000 > kernel config: https://syzkaller.appspot.com/x/.config?x=56f1da14935c3cce > dashboard link: https://syzkaller.appspot.com/bug?extid=f7baccc38dcc1e094e77 > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=171aa7e6a00000 > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=153306cea00000 > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > Reported-by: syzbot+f7baccc38dcc1e094e77@syzkaller.appspotmail.com The only memory leak that I can find is on the out-of-memory error path: ---8<--- 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> diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c index 82b19e4f1189..2fd7a46d55ec 100644 --- a/lib/mpi/mpi-pow.c +++ b/lib/mpi/mpi-pow.c @@ -24,6 +24,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) { mpi_ptr_t mp_marker = NULL, bp_marker = NULL, ep_marker = NULL; + struct karatsuba_ctx karactx = {}; mpi_ptr_t xp_marker = NULL; mpi_ptr_t tspace = NULL; mpi_ptr_t rp, ep, mp, bp; @@ -150,13 +151,11 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) int c; mpi_limb_t e; mpi_limb_t carry_limb; - struct karatsuba_ctx karactx; xp = xp_marker = mpi_alloc_limb_space(2 * (msize + 1)); if (!xp) goto enomem; - memset(&karactx, 0, sizeof karactx); negative_result = (ep[0] & 1) && base->sign; i = esize - 1; @@ -281,8 +280,6 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) if (mod_shift_cnt) mpihelp_rshift(rp, rp, rsize, mod_shift_cnt); MPN_NORMALIZE(rp, rsize); - - mpihelp_release_karatsuba_ctx(&karactx); } if (negative_result && rsize) { @@ -299,6 +296,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) leave: rc = 0; enomem: + mpihelp_release_karatsuba_ctx(&karactx); if (assign_rp) mpi_assign_limb_space(res, rp, size); if (mp_marker) -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: lib/mpi: Fix karactx leak in mpi_powm 2019-06-24 10:32 ` lib/mpi: Fix karactx leak in mpi_powm Herbert Xu @ 2019-06-24 21:17 ` Eric Biggers 0 siblings, 0 replies; 3+ messages in thread From: Eric Biggers @ 2019-06-24 21:17 UTC (permalink / raw) To: Herbert Xu; +Cc: syzbot, davem, linux-crypto, linux-kernel, syzkaller-bugs On Mon, Jun 24, 2019 at 06:32:26PM +0800, Herbert Xu wrote: > On Mon, Jun 24, 2019 at 12:27:08AM -0700, syzbot wrote: > > Hello, > > > > syzbot found the following crash on: > > > > HEAD commit: abf02e29 Merge tag 'pm-5.2-rc6' of git://git.kernel.org/pu.. > > git tree: upstream > > console output: https://syzkaller.appspot.com/x/log.txt?x=17a8bfeaa00000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=56f1da14935c3cce > > dashboard link: https://syzkaller.appspot.com/bug?extid=f7baccc38dcc1e094e77 > > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=171aa7e6a00000 > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=153306cea00000 > > > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > > Reported-by: syzbot+f7baccc38dcc1e094e77@syzkaller.appspotmail.com > > The only memory leak that I can find is on the out-of-memory error > path: > > ---8<--- > 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> > > diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c > index 82b19e4f1189..2fd7a46d55ec 100644 > --- a/lib/mpi/mpi-pow.c > +++ b/lib/mpi/mpi-pow.c > @@ -24,6 +24,7 @@ > int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) > { > mpi_ptr_t mp_marker = NULL, bp_marker = NULL, ep_marker = NULL; > + struct karatsuba_ctx karactx = {}; > mpi_ptr_t xp_marker = NULL; > mpi_ptr_t tspace = NULL; > mpi_ptr_t rp, ep, mp, bp; > @@ -150,13 +151,11 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) > int c; > mpi_limb_t e; > mpi_limb_t carry_limb; > - struct karatsuba_ctx karactx; > > xp = xp_marker = mpi_alloc_limb_space(2 * (msize + 1)); > if (!xp) > goto enomem; > > - memset(&karactx, 0, sizeof karactx); > negative_result = (ep[0] & 1) && base->sign; > > i = esize - 1; > @@ -281,8 +280,6 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) > if (mod_shift_cnt) > mpihelp_rshift(rp, rp, rsize, mod_shift_cnt); > MPN_NORMALIZE(rp, rsize); > - > - mpihelp_release_karatsuba_ctx(&karactx); > } > > if (negative_result && rsize) { > @@ -299,6 +296,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) > leave: > rc = 0; > enomem: > + mpihelp_release_karatsuba_ctx(&karactx); > if (assign_rp) > mpi_assign_limb_space(res, rp, size); > if (mp_marker) > -- Reviewed-by: Eric Biggers <ebiggers@kernel.org> - Eric ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-24 21:17 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-06-24 7:27 memory leak in mpihelp_mul_karatsuba_case syzbot 2019-06-24 10:32 ` lib/mpi: Fix karactx leak in mpi_powm Herbert Xu 2019-06-24 21:17 ` Eric Biggers
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).