Eric Biggers
12d41a023e
crypto: dh - Fix double free of ctx->p
When setting the secret with the software Diffie-Hellman implementation,
if allocating 'g' failed (e.g. if it was longer than
MAX_EXTERN_MPI_BITS), then 'p' was freed twice: once immediately, and
once later when the crypto_kpp tfm was destroyed.
Fix it by using dh_free_ctx() (renamed to dh_clear_ctx()) in the error
paths, as that correctly sets the pointers to NULL.
KASAN report:
MPI: mpi too large (32760 bits)
==================================================================
BUG: KASAN: use-after-free in mpi_free+0x131/0x170
Read of size 4 at addr ffff88006c7cdf90 by task reproduce_doubl/367
CPU: 1 PID: 367 Comm: reproduce_doubl Not tainted 4.14.0-rc7-00040-g05298abde6fe #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Call Trace:
dump_stack+0xb3/0x10b
? mpi_free+0x131/0x170
print_address_description+0x79/0x2a0
? mpi_free+0x131/0x170
kasan_report+0x236/0x340
? akcipher_register_instance+0x90/0x90
__asan_report_load4_noabort+0x14/0x20
mpi_free+0x131/0x170
? akcipher_register_instance+0x90/0x90
dh_exit_tfm+0x3d/0x140
crypto_kpp_exit_tfm+0x52/0x70
crypto_destroy_tfm+0xb3/0x250
__keyctl_dh_compute+0x640/0xe90
? kasan_slab_free+0x12f/0x180
? dh_data_from_key+0x240/0x240
? key_create_or_update+0x1ee/0xb20
? key_instantiate_and_link+0x440/0x440
? lock_contended+0xee0/0xee0
? kfree+0xcf/0x210
? SyS_add_key+0x268/0x340
keyctl_dh_compute+0xb3/0xf1
? __keyctl_dh_compute+0xe90/0xe90
? SyS_add_key+0x26d/0x340
? entry_SYSCALL_64_fastpath+0x5/0xbe
? trace_hardirqs_on_caller+0x3f4/0x560
SyS_keyctl+0x72/0x2c0
entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x43ccf9
RSP: 002b:00007ffeeec96158 EFLAGS: 00000246 ORIG_RAX: 00000000000000fa
RAX: ffffffffffffffda RBX: 000000000248b9b9 RCX: 000000000043ccf9
RDX: 00007ffeeec96170 RSI: 00007ffeeec96160 RDI: 0000000000000017
RBP: 0000000000000046 R08: 0000000000000000 R09: 0248b9b9143dc936
R10: 0000000000001000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000409670 R14: 0000000000409700 R15: 0000000000000000
Allocated by task 367:
save_stack_trace+0x16/0x20
kasan_kmalloc+0xeb/0x180
kmem_cache_alloc_trace+0x114/0x300
mpi_alloc+0x4b/0x230
mpi_read_raw_data+0xbe/0x360
dh_set_secret+0x1dc/0x460
__keyctl_dh_compute+0x623/0xe90
keyctl_dh_compute+0xb3/0xf1
SyS_keyctl+0x72/0x2c0
entry_SYSCALL_64_fastpath+0x1f/0xbe
Freed by task 367:
save_stack_trace+0x16/0x20
kasan_slab_free+0xab/0x180
kfree+0xb5/0x210
mpi_free+0xcb/0x170
dh_set_secret+0x2d7/0x460
__keyctl_dh_compute+0x623/0xe90
keyctl_dh_compute+0xb3/0xf1
SyS_keyctl+0x72/0x2c0
entry_SYSCALL_64_fastpath+0x1f/0xbe
Fixes: 802c7f1c84 ("crypto: dh - Add DH software implementation")
Cc: <stable@vger.kernel.org> # v4.8+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-11-10 19:20:16 +08:00
..
2017-11-03 22:11:18 +08:00
2017-05-16 10:01:57 +05:30
2015-06-25 23:29:24 +08:00
2016-10-25 11:08:33 +08:00
2016-06-23 18:29:53 +08:00
2017-01-13 00:24:39 +08:00
2017-04-21 20:30:50 +08:00
2017-01-13 00:24:39 +08:00
2017-02-11 17:50:43 +08:00
2017-06-19 14:11:53 +08:00
2017-11-03 22:11:18 +08:00
2017-11-03 22:11:17 +08:00
2017-01-13 00:24:39 +08:00
2017-11-03 22:11:16 +08:00
2017-10-07 12:10:34 +08:00
2017-11-03 22:11:18 +08:00
2017-11-03 22:11:18 +08:00
2015-04-22 09:30:21 +08:00
2017-11-03 22:11:18 +08:00
2015-04-22 09:30:18 +08:00
2014-11-24 22:43:57 +08:00
2017-11-03 22:11:18 +08:00
2014-11-24 22:43:57 +08:00
2016-11-01 08:37:17 +08:00
2017-07-18 17:01:11 +08:00
2017-01-13 00:24:39 +08:00
2015-01-13 22:29:11 +11:00
2015-01-13 22:29:11 +11:00
2015-01-13 22:29:11 +11:00
2015-01-13 22:29:11 +11:00
2013-08-14 20:42:03 +10:00
2017-03-09 18:34:39 +08:00
2017-02-28 17:29:17 +08:00
2017-08-22 14:45:47 +08:00
2016-11-01 08:37:17 +08:00
2016-10-21 11:03:42 +08:00
2017-02-11 17:52:28 +08:00
2016-10-21 11:03:42 +08:00
2016-01-30 22:11:22 +08:00
2016-01-19 15:52:10 +08:00
2013-09-12 15:31:34 +10:00
2016-09-13 20:27:26 +08:00
2017-11-03 22:11:16 +08:00
2017-06-19 14:19:54 +08:00
2016-07-18 17:35:44 +08:00
2017-05-02 16:40:27 -07:00
2014-03-21 21:54:28 +08:00
2017-08-04 09:27:15 +08:00
2017-11-03 22:11:17 +08:00
2017-04-24 18:11:08 +08:00
2015-01-13 22:29:11 +11:00
2017-10-12 22:55:05 +08:00
2017-11-10 19:20:16 +08:00
2017-11-03 22:11:19 +08:00
2014-11-26 20:06:30 +08:00
2016-06-23 18:29:57 +08:00
2017-06-10 12:04:35 +08:00
2017-06-10 12:04:35 +08:00
2017-10-12 22:55:00 +08:00
2017-11-06 14:45:04 +08:00
2016-09-13 18:44:57 +08:00
2014-11-24 22:43:57 +08:00
2015-04-23 14:18:09 +08:00
2017-11-03 22:11:19 +08:00
2017-11-03 21:50:43 +08:00
2016-10-02 22:26:40 +08:00
2015-12-20 15:27:12 +02:00
2017-05-23 12:52:05 +08:00
2016-10-21 11:03:42 +08:00
2016-11-17 23:34:52 +08:00
2015-06-25 23:18:33 +08:00
2017-09-22 17:43:07 +08:00
2017-10-12 22:55:06 +08:00
2014-11-24 22:43:57 +08:00
2017-01-13 00:24:39 +08:00
2017-11-03 22:11:17 +08:00
2017-04-10 19:17:27 +08:00
2017-04-10 19:17:27 +08:00
2017-05-08 17:15:13 -07:00
2017-09-22 17:43:07 +08:00
2017-03-02 08:42:34 +01:00
2014-11-24 22:43:57 +08:00
2017-03-24 22:02:56 +08:00
2013-12-09 20:09:12 +08:00
2014-11-24 22:43:57 +08:00
2017-08-04 09:27:15 +08:00
2015-08-17 16:53:53 +08:00
2016-11-13 17:45:03 +08:00
2015-04-23 14:18:09 +08:00
2017-09-22 17:43:28 +08:00
2017-09-22 17:43:28 +08:00
2017-09-22 17:43:28 +08:00
2017-09-22 17:43:28 +08:00
2017-07-28 17:56:00 +08:00
2016-08-24 21:07:10 +08:00
2017-11-03 22:11:17 +08:00
2017-06-10 12:04:30 +08:00
2016-07-05 23:05:26 +08:00
2015-10-14 22:23:16 +08:00
2015-01-13 22:29:11 +11:00
2016-11-22 15:02:25 +08:00
2017-08-03 13:52:44 +08:00
2014-11-24 22:43:57 +08:00
2017-02-11 17:52:28 +08:00
2017-08-09 20:17:54 +08:00
2015-12-22 20:43:35 +08:00
2016-08-08 23:43:46 +08:00
2015-12-22 20:43:35 +08:00
2015-04-10 21:39:41 +08:00
2017-01-13 00:24:39 +08:00
2016-11-28 21:23:18 +08:00
2017-05-18 13:04:05 +08:00
2017-09-22 17:43:07 +08:00
2017-11-03 22:11:22 +08:00
2015-07-17 21:20:20 +08:00
2015-01-13 22:29:11 +11:00
2017-11-03 22:11:19 +08:00
2017-09-22 17:43:08 +08:00
2015-01-13 22:29:11 +11:00
2015-01-13 22:29:11 +11:00
2014-11-26 20:06:30 +08:00
2015-01-13 22:29:11 +11:00
2014-11-26 20:06:30 +08:00
2016-08-31 23:00:48 +08:00
2017-11-03 22:11:17 +08:00