Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751038AbdL3Ihs (ORCPT ); Sat, 30 Dec 2017 03:37:48 -0500 Received: from a.mx.secunet.com ([62.96.220.36]:41148 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750806AbdL3Ihr (ORCPT ); Sat, 30 Dec 2017 03:37:47 -0500 Date: Sat, 30 Dec 2017 09:37:44 +0100 From: Steffen Klassert To: Eric Biggers CC: Dmitry Vyukov , syzbot , LKML , Ingo Molnar , "Peter Zijlstra" , , "Herbert Xu" , David Miller , Subject: Re: INFO: task hung in aead_recvmsg Message-ID: <20171230083744.vuclnbs677tj7pi2@gauss3.secunet.de> References: <001a1140b8307b0439055ffc7872@google.com> <20171223202942.GB10162@zzz.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20171223202942.GB10162@zzz.localdomain> User-Agent: NeoMutt/20170609 (1.8.3) X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: BCAFA990-EE8F-43F4-A248-668F58662AF2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1747 Lines: 47 On Sat, Dec 23, 2017 at 02:29:42PM -0600, Eric Biggers wrote: > [+Cc Steffen Klassert ] > > > I was able to reproduce this by trying to use 'pcrypt' recursively. I am not > 100% sure it is the exact same bug, but it probably is. Here is a C reproducer: > > #include > #include > #include > > 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); > } > > It seems the problem is that all 'pcrypt' instances use the same > 'padata_instance', which completes works in the order they are submitted. But > with nested use, the outer work is submitted before the inner work, so the inner > work isn't allowed to complete until the outer work does, which deadlocks > because actually the inner work needs to complete first. > > What a mess. Maybe there should be a separate 'padata_instance' per pcrypt > instance? Or maybe there should be a way for an algorithm to declare that it > can only appear in the stack one time? Having two nested pcrypt templates in one algorithm instance does not make so much sense in the first place. I thought that the crypto layer would refuse to build an instance with two nested templates of the same type. At least for pcrypt, refusing such instantiations would be the correct behaviour. Are there any other templates where a nested use would make sense?