Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3198256imu; Fri, 23 Nov 2018 23:55:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6EQ9Hg3W22kmoR93VOkuptIPYEy0YbvX0z5PHRIBc5EuqpLz3USeJMXBXoKn9Z8r9S2wJ X-Received: by 2002:a63:9712:: with SMTP id n18mr16766548pge.295.1543046102612; Fri, 23 Nov 2018 23:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046102; cv=none; d=google.com; s=arc-20160816; b=wyD3R9WMuCVWIY5IgqZFB5NjpqHnOVJDoB2E42D22zhszKRsMoceJIfOQkfkoZ4lLs KrvVHUQRexK39eJjwaEKC2WiNhlh0BbteSaw68d+MCA021cxR5k4kaiK3OE67M2YagpL +fp6b7YTDrrIFei9zmVjk+IIJIc/nU4sTtm7cs34s6ug6StAsVKucfD8tlmFS1Z2UiXu 1dnxraLwirGJr2Enqf843eEwc/4kw7EJRM6Vdo8vAp8pmrXD9oVXgOldcJnHbb7y+QnS DOJN/GaVuMIvO3oxtkQUw1VET/BPEg85e3pKOFL7/BezJs2o3JWnUYuRnlOY7LCfZObM xStQ== 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=kM7XZGTc+ZfXyDnCUx7oY8hFxcYKeJBAQSGlYfEaLfc=; b=EXjZl/gmh6M7eGeXXEEgnKQvAIZKJO73ba6CwjBaCddzxRMvkwg6sUXJrn+LaLIxoM q1NwVO58+uHWRSMR2jR2azUeXp05o32LroYhGc6bK47TTVZqayr5u2iGUuymBexhhPX/ tDUphVknCOgpt/m/X4rCO9N8YoNfrFZMk0MKxt2rbdJFycBLwlWqgooD9PgehsSDzKEC neAosiKYUP/VsCectTh1byA0iX4yFICl5+qDZTMocifSP9oaoRy8Pz/9hSgGFnp9sZV6 /vu5UXjaoqbHaUSlwgEWTJQjg9ijBrQGHStOxWfztgLUaGO078wk+Lh1U9vRxdEcwK8B E+HQ== 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 89-v6si15029710plb.405.2018.11.23.23.54.48; Fri, 23 Nov 2018 23:55:02 -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 S2439496AbeKWNSq (ORCPT + 99 others); Fri, 23 Nov 2018 08:18:46 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:43264 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727343AbeKWNSp (ORCPT ); Fri, 23 Nov 2018 08:18:45 -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 1gQ1KV-0007mW-Ha; Fri, 23 Nov 2018 10:36:27 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gQ1KT-0003Z6-It; Fri, 23 Nov 2018 10:36:25 +0800 Date: Fri, 23 Nov 2018 10:36:25 +0800 From: Herbert Xu To: PanBian 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: <20181123023625.oguwfmhhi2su6etr@gondor.apana.org.au> References: <1542880816-63838-1-git-send-email-bianpan2016@163.com> <20181122144441.tkfmrq3lzibq2g3y@gondor.apana.org.au> <20181123010555.GA83154@bp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181123010555.GA83154@bp> 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 Fri, Nov 23, 2018 at 09:05:55AM +0800, PanBian wrote: > > Thanks for your explanation! But I find that the function > crypto_init_spawn just lets spawn->alg point to the algorithm without > increasing the reference count, i.e., alg->cra_refcnt. So I am confused > about how this can protect the algorithm from being freed. Maybe I > missed some key points. Could you please explain it in more details? Oh you're right! This bug was introduced during the skcipher conversion. The spawns are not meant to carry a reference count with them because they are not supposed to stop the underlying algorithm from being removed. So yes we do need to hold a reference count on alg until the instance is registered. Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt