From: Herbert Xu Subject: Re: [PATCH v2 1/4] Wrap crc_t10dif function all to use crypto transform framework Date: Sun, 28 Apr 2013 08:11:22 +0800 Message-ID: <20130428001122.GA6973@gondor.apana.org.au> References: <20130425132203.GA29501@gondor.apana.org.au> <1366910910.27102.126.camel@schen9-DESK> <20130426125224.GA4855@gondor.apana.org.au> <1366994657.27102.129.camel@schen9-DESK> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "H. Peter Anvin" , "David S. Miller" , "Martin K. Petersen" , James Bottomley , Matthew Wilcox , Jim Kukunas , Keith Busch , Erdinc Ozturk , Vinodh Gopal , James Guilford , Wajdi Feghali , Jussi Kivilinna , linux-kernel , linux-crypto@vger.kernel.org, linux-scsi@vger.kernel.org To: Tim Chen Return-path: Received: from ringil.hengli.com.au ([178.18.16.133]:50888 "EHLO fornost.hengli.com.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754310Ab3D1ALs (ORCPT ); Sat, 27 Apr 2013 20:11:48 -0400 Content-Disposition: inline In-Reply-To: <1366994657.27102.129.camel@schen9-DESK> Sender: linux-crypto-owner@vger.kernel.org List-ID: On Fri, Apr 26, 2013 at 09:44:17AM -0700, Tim Chen wrote: > > + old_tfm = crct10dif_tfm; > + crc_t10dif_newalg = true; > + /* make sure new alg flag is turned on before starting to switch tfm */ > + mb(); > + > + new_tfm = crypto_alloc_shash("crct10dif", 0, 0); > + if (IS_ERR(new_tfm)) > + goto done; > + > + if (old_tfm) > + if (crypto_tfm_alg_priority(&old_tfm->base) >= > + crypto_tfm_alg_priority(&new_tfm->base)) { > + crypto_free_shash(new_tfm); > + goto done; > + } > + crct10dif_tfm = new_tfm; > + /* make sure update to tfm pointer is completed */ > + mb(); > + crypto_free_shash(old_tfm); This is not safe at all. You'd need to use something like RCU. However, I think this is an overkill. Initialising it once should be enough. If someone really wanted to change things at run-time, they could always build this as a module and unload/reload it. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt