Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp82799pxb; Fri, 29 Oct 2021 06:13:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyByYHP/vesq+AUwkty7nW5WN5HGqMaBtAQjCk1KCmP+cEhzmdPXgEBtH74089J7XQThLlE X-Received: by 2002:a17:906:9a4c:: with SMTP id aj12mr13771896ejc.557.1635513196370; Fri, 29 Oct 2021 06:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635513196; cv=none; d=google.com; s=arc-20160816; b=Rzl/GBqVlKr1Q44IzJJJggcTIJwYfOw2JmhGtN4ULcgDdThtr/m3S34PjjSkGPm/2F IaUoLXStScwzHT8RmSN27Gqhm0Ca/pYJBnGpUc7A9aRt+gwGa3iFDaTD/vCln1BScwf3 misG9Gbc/8B3ShBKrrByaoMecD66nNRkvDdSlLWi4rAj8k0ETR8Wm0K8bv5ObC0q/apm Nesq34mqUoVfZx24oKM44DDxoyV2ymI2nORIWQdvkzYiVqkGUwwiwwdLVX7cUgjNHLfj B4GmByIJNUqXDVuQtT5FRGoitRIl5d3NHrcRFSXVpwhpdpPXaU66yN31Y5iz/IEIz/ix bz3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=NQPkchhJgnZrVAX0KEmtZ2rWRNVGXpCmUiwMBGTpXCI=; b=kNxQq5vvEomZ3OKaoS361ZzXQrNb2O/63IUtvahr9s/B9vnmLRt0rjpN0nWn7S6fqI s/Ewdqtdt4aRQoJwMIi/mYu5ocVfxzmWD5hOtNgTIMVaHADVKv9R2dfU4F9VksJLdPyX 3KnMGWaUl9tdZk+FvMn6PbVe2SbO6yo54V02NwchyHc3Dd/LxTqG6JrwHHmmxVe5yQ0O b4bHriStD0aeB64Zbh3A3o5EZF9DsPEKnAhgRBACOY7Smsgic6payVYPShVr/rgp2u+k 0AL8V3BSMBznxTyg4PeCedTLkx24PUtFMfJ5b0dMwQ98OfJRA0gzlDBzA7JsV9IQ1pyA rrFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si11373211edc.437.2021.10.29.06.12.52; Fri, 29 Oct 2021 06:13:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbhJ2NOm (ORCPT + 99 others); Fri, 29 Oct 2021 09:14:42 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:56400 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231610AbhJ2NOj (ORCPT ); Fri, 29 Oct 2021 09:14:39 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.92 #5 (Debian)) id 1mgRfy-0002qL-B6; Fri, 29 Oct 2021 21:12:06 +0800 Received: from herbert by gondobar with local (Exim 4.92) (envelope-from ) id 1mgRfw-0003E0-2d; Fri, 29 Oct 2021 21:12:04 +0800 Date: Fri, 29 Oct 2021 21:12:04 +0800 From: Herbert Xu To: Daniel Jordan Cc: Steffen Klassert , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] crypto: pcrypt - Delay write to padata->info Message-ID: <20211029131204.GE12278@gondor.apana.org.au> References: <20211021183028.837112-1-daniel.m.jordan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211021183028.837112-1-daniel.m.jordan@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Oct 21, 2021 at 02:30:28PM -0400, Daniel Jordan wrote: > These three events can race when pcrypt is used multiple times in a > template ("pcrypt(pcrypt(...))"): > > 1. [taskA] The caller makes the crypto request via crypto_aead_encrypt() > 2. [kworkerB] padata serializes the inner pcrypt request > 3. [kworkerC] padata serializes the outer pcrypt request > > 3 might finish before the call to crypto_aead_encrypt() returns in 1, > resulting in two possible issues. > > First, a use-after-free of the crypto request's memory when, for > example, taskA writes to the outer pcrypt request's padata->info in > pcrypt_aead_enc() after kworkerC completes the request. > > Second, the outer pcrypt request overwrites the inner pcrypt request's > return code with -EINPROGRESS, making a successful request appear to > fail. For instance, kworkerB writes the outer pcrypt request's > padata->info in pcrypt_aead_done() and then taskA overwrites it > in pcrypt_aead_enc(). > > Avoid both situations by delaying the write of padata->info until after > the inner crypto request's return code is checked. This prevents the > use-after-free by not touching the crypto request's memory after the > next-inner crypto request is made, and stops padata->info from being > overwritten. > > Fixes: 5068c7a883d16 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper") > Reported-by: syzbot+b187b77c8474f9648fae@syzkaller.appspotmail.com > Signed-off-by: Daniel Jordan > --- > > So, pcrypt(pcrypt(...)) doesn't make all that much sense, but apparently > there's not an easy way to prevent it [1], so I'm going with the minimal > fix. > > [1] https://lkml.kernel.org/20171230083744.vuclnbs677tj7pi2@gauss3.secunet.de/ > > crypto/pcrypt.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt