Re: [PATCH] crypto: pcrypt - Avoid deadlock by using per-instance padata queues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Herbert,

On Tue, Nov 19, 2019 at 09:05:57PM +0800, Herbert Xu wrote:
> If the pcrypt template is used multiple times in an algorithm, then a
> deadlock occurs because all pcrypt instances share the same
> padata_instance, which completes requests in the order submitted.  That
> is, the inner pcrypt request waits for the outer pcrypt request while
> the outer request is already waiting for the inner.
> 
> This patch fixes this by allocating a set of queues for each pcrypt
> instance instead of using two global queues.  In order to maintain
> the existing user-space interface, the pinst structure remains global
> so any sysfs modifications will apply to every instance.
> 
> The new per-instance data structure is called padata_shell and is
> essentially a wrapper around parallel_data.
> 
> Reproducer:
> 
> 	#include <linux/if_alg.h>
> 	#include <sys/socket.h>
> 	#include <unistd.h>
> 
> 	int main()
> 	{
> 		struct sockaddr_alg addr = {
> 			.salg_type = "aead",
> 			.salg_name = "pcrypt(pcrypt(rfc4106-gcm-aesni))"
> 		};
> 		int algfd, reqfd;
> 		char buf[32] = { 0 };
> 
> 		algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
> 		bind(algfd, (void *)&addr, sizeof(addr));
> 		setsockopt(algfd, SOL_ALG, ALG_SET_KEY, buf, 20);
> 		reqfd = accept(algfd, 0, 0);
> 		write(reqfd, buf, 32);
> 		read(reqfd, buf, 16);
> 	}
> 
> Reported-by: syzbot+56c7151cad94eec37c521f0e47d2eee53f9361c4@xxxxxxxxxxxxxxxxxxxxxxxxx
> Fixes: 5068c7a883d1 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper")
> Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> 

FYI, with your 3 pcrypt patches applied, I tried enabling CONFIG_CRYPTO_PCRYPT=y
again and running syzkaller targetting AF_ALG, and I quickly got the following
warning:

------------[ cut here ]------------
WARNING: CPU: 7 PID: 64550 at kernel/cpu.c:329 lockdep_assert_cpus_held+0xc3/0xf0 kernel/cpu.c:329
Kernel panic - not syncing: panic_on_warn set ...
CPU: 7 PID: 64550 Comm: cryptomgr_probe Not tainted 5.4.0-rc1-00267-g94b2b3991aca #10
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20191013_105130-anatol 04/01/2014
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0xd4/0x156 lib/dump_stack.c:113
 panic+0x2a3/0x6b3 kernel/panic.c:220
 __warn.cold+0x2f/0x3e kernel/panic.c:581
 report_bug+0x291/0x300 lib/bug.c:195
 fixup_bug arch/x86/kernel/traps.c:179 [inline]
 fixup_bug arch/x86/kernel/traps.c:174 [inline]
 do_error_trap+0x11b/0x1c0 arch/x86/kernel/traps.c:272
 do_invalid_op+0x50/0x70 arch/x86/kernel/traps.c:291
 invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028
RIP: 0010:lockdep_assert_cpus_held+0xc3/0xf0 kernel/cpu.c:329
Code: e8 02 39 24 00 be ff ff ff ff 48 c7 c7 30 55 2b 83 e8 c1 5b 11 00 31 ff 89 c3 89 c6 e8 66 3a 24 00 85 db 75 d3 e8 dd 38 24 00 <0f> 0b e8 d6 38 24 00 5b 5d c3 48 c7 c7 44 71 5a 83 e8 17 7c 46 00
RSP: 0018:ffff888068007d98 EFLAGS: 00010293
RAX: ffff88804b10c040 RBX: 0000000000000000 RCX: ffffffff811f417a
RDX: 0000000000000000 RSI: ffffffff811f4183 RDI: 0000000000000005
RBP: ffff888068007da0 R08: ffff88804b10c040 R09: ffffed100dafe405
R10: ffffed100dafe404 R11: ffff88806d7f2023 R12: ffff88806baa0cc0
R13: ffff88806ae432c0 R14: 000000000000ffff R15: ffff88806b4e9008
 apply_workqueue_attrs+0x18/0x50 kernel/workqueue.c:4042
 padata_setup_cpumasks kernel/padata.c:374 [inline]
 padata_alloc_pd+0x2f5/0xbb0 kernel/padata.c:449
 padata_alloc_shell+0x97/0x290 kernel/padata.c:1052
 pcrypt_create_aead crypto/pcrypt.c:255 [inline]
 pcrypt_create+0x19e/0x890 crypto/pcrypt.c:319
 cryptomgr_probe+0x6f/0x290 crypto/algboss.c:70
 kthread+0x361/0x430 kernel/kthread.c:255
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
Dumping ftrace buffer:
   (ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 1 seconds..



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux