Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2715216imu; Fri, 23 Nov 2018 13:36:01 -0800 (PST) X-Google-Smtp-Source: AJdET5e+ZPPIJ+xmf7D4ySpSxJjMJmSOXE72TMbXMg7nepPtxBOHIktnNkCfXItTVAMLjYMvEsTe X-Received: by 2002:a62:c28e:: with SMTP id w14mr17675239pfk.115.1543008961695; Fri, 23 Nov 2018 13:36:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543008961; cv=none; d=google.com; s=arc-20160816; b=jSBQuNIHu9cmNRhZbeKIIA3w/5vJAwfXw9r3lIptAPD8mgCbIudXh2r/fJqhPkAj4Q nyriaCVAbSxikNN1LODOoyGyZPbuz+It9uIpJkMzt3XFMoW3n2tWSiUl+KhcSDrvCByh MT3r0gp1Fxpq5zC27nvdC5TtxxKZTsYrr7MYSk70Wnst4wygH/9MkpsU6c5qVTAUAvR1 MDmFxOckUP72G9pgdZLwiniau+aq5BVPcanv+UStp1oLx8+gEWH1AkKJiNGD+a0L+PqK DyTFAvseWKPTOEigQU0CgxbUw7ExZrWA3mzGMT1yvHRwkWUiswsI3B5RFFVjWOxHx0Rf UeZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=F/64fcx/L7oAeE6zPAyPPUx7A1Cb3hjGd+PDCMkykto=; b=HoGHazLRYCMtuGaAGSQ8CqtzG3ovBfp2JZBDO+atPAdUEzbRd92DDW8WZTRCwJ/6QN RvMOyIXPuFkU/NdKioeuaTfzFi3rLrFSPTN3nY+KLZ5dkPpjSlc27PdwhHktDAw5pHzU Eoth+2uGHy01XmsUR+o0VsG997i5mgTJgfo5suij+vVMRXud20R4qpKRvUcRex8hI6qn IJ7r3kimgFVfjZLMlhlLEQbQUw4QrLThvnwqizmEJDB9jJp/Vo9e5STCdI+3hwfwvIGN wYLVMA1b1sjSQcmEOno1g2hLqPyb6GVwHJ7+/o6DI96Mbkhyz6Tpo0n+ziTA3GH9JZqJ uhbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si31682009pfl.279.2018.11.23.13.35.21; Fri, 23 Nov 2018 13:36:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405623AbeKWBYZ (ORCPT + 99 others); Thu, 22 Nov 2018 20:24:25 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:42740 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726556AbeKWBYZ (ORCPT ); Thu, 22 Nov 2018 20:24:25 -0500 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1gPqDi-0001DX-Lb; Thu, 22 Nov 2018 22:44:42 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gPqDh-0002wP-W7; Thu, 22 Nov 2018 22:44:42 +0800 Date: Thu, 22 Nov 2018 22:44:41 +0800 From: Herbert Xu To: Pan Bian Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] crypto: do not free algorithm before using Message-ID: <20181122144441.tkfmrq3lzibq2g3y@gondor.apana.org.au> References: <1542880816-63838-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1542880816-63838-1-git-send-email-bianpan2016@163.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 22, 2018 at 06:00:16PM +0800, Pan Bian wrote: > In multiple functions, the algorithm fields are read after its reference > is dropped through crypto_mod_put. In this case, the algorithm memory > may be freed, resulting in use-after-free bugs. This patch delays the > put operation until the algorithm is never used. > > Signed-off-by: Pan Bian I don't think this patch is needed. > --- > crypto/cbc.c | 6 ++++-- > crypto/cfb.c | 6 ++++-- > crypto/pcbc.c | 6 ++++-- > 3 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/crypto/cbc.c b/crypto/cbc.c > index b761b1f..dd5f332 100644 > --- a/crypto/cbc.c > +++ b/crypto/cbc.c > @@ -140,9 +140,8 @@ static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb) > spawn = skcipher_instance_ctx(inst); > err = crypto_init_spawn(spawn, alg, skcipher_crypto_instance(inst), > CRYPTO_ALG_TYPE_MASK); > - crypto_mod_put(alg); > if (err) > - goto err_free_inst; > + goto err_put_alg; We can safely drop the reference to the algorithm because the spawn is now meant to hold a reference to it. As long as the spawn is alive so will the algorithm. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt