Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3806315ybt; Tue, 30 Jun 2020 11:36:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT4U9BDCO2mIFTb2G7yEb/hEXSaP/O6lAfgojhxVCI8WwAvWID+TCJXKSm3fdES38nAn/8 X-Received: by 2002:a17:906:6d56:: with SMTP id a22mr20126919ejt.440.1593541518177; Tue, 30 Jun 2020 11:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593541517; cv=none; d=google.com; s=arc-20160816; b=yNILAQjLbGqkL9zU7bRiBF977iqchhSsWZu90XH1Qij+rDA8uL+viZKgftT3uzdPsH zxDz2G3HO/qUhcDvzKsT21rttdlAXSChQm3OQLQPFkKL3BU6+Gz3eT0qrVT5SYBRkeuh +x18n41jNxP4tSKq4YbkCL4/9IqRK8lKQGsUxoTVlDXmYi2I5ENV2NljlZhMrb8NMJnm hFM+OjcgQxKL4sLUF4K53kKPtUhck2oyqDHZD/zJ72HAX4IjA8iFDcGzpdeOLH1kwRpM FbNRPTyVys3vtOwGV/h8MgJcnMnEs1kdwl5pNLNEJPMjFMAJBOeFYy12N8h8z+dsjMfR w9RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=dpDjX+OXz6WlZmf3iFo84skl2yDMnMRmdV9i/Pt4fzg=; b=d/1H2A1ZQo8QzpPL0Jb8l50H1SHEF5XcGtW+ltzj+kL0KixghabxUgMBk+2gnAi4vc 2Rzfae7hWW32R9QLqBGM2CFXr0YjB7OjvMSaVX1i9XP8taAtkwq2Kb6n8rbKroiX+ILj LAl7M4W5/G9cPmVkuUeKRl/R50nmlsuiMdZpit2wxKDULutbffj25xBclBv4/XX7XUyW gSaTuUezuu2xEuW03QHnOhYptx6UWRkzZolo7fqcBcVF6ijjMarN39cUAm95G6zA1oSn i0JKNOP/L/hGSB1avI97m/3eshBXYW0vJ3Bjrgzn0Lt7dpaLcjr8fsehyacJTlD06ZPQ QFMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=noDzOs3h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si2132366ejo.267.2020.06.30.11.24.54; Tue, 30 Jun 2020 11:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=noDzOs3h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389273AbgF3QgF (ORCPT + 99 others); Tue, 30 Jun 2020 12:36:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:48450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389026AbgF3QgE (ORCPT ); Tue, 30 Jun 2020 12:36:04 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9CCC320724; Tue, 30 Jun 2020 16:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593534964; bh=oYCSw4PCki/SDdawcCRdB1g+bOTmh7QoW+EwDPjWJjs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=noDzOs3heH2s23yBmSBcGq/OZohTqVn/ojDBf6gA96/4WN2xjKm4lG9twKUxbMMP6 /6Mu7njaHhCw40O1BjBNqlxJKQx/UwhBVi59PLW4+qPEmQy12oBARxLGCu5TGYIZwk Rc/Er/Xmw8xInG6ajcNADFdvHSTbvJYg8LdH5rdQ= Date: Tue, 30 Jun 2020 09:35:52 -0700 From: Eric Biggers To: Mikulas Patocka Cc: Mike Snitzer , Herbert Xu , Zaibo Xu , linux-kernel@vger.kernel.org, Wei Xu , dm-devel@redhat.com, George Cherian , linux-crypto@vger.kernel.org, Jonathan Cameron , "David S. Miller" , Milan Broz Subject: Re: [dm-devel] [PATCH 1/3 v4] crypto: introduce the flag CRYPTO_ALG_ALLOCATES_MEMORY Message-ID: <20200630163552.GA837@sol.localdomain> References: <20200616173620.GA207319@gmail.com> <20200626044534.GA2870@gondor.apana.org.au> <20200626164617.GA211634@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 30, 2020 at 09:56:22AM -0400, Mikulas Patocka wrote: > Index: linux-2.6/crypto/cryptd.c > =================================================================== > --- linux-2.6.orig/crypto/cryptd.c 2020-06-29 16:03:07.346417000 +0200 > +++ linux-2.6/crypto/cryptd.c 2020-06-30 15:49:04.206417000 +0200 > @@ -202,6 +202,7 @@ static inline void cryptd_check_internal > > *type |= algt->type & CRYPTO_ALG_INTERNAL; > *mask |= algt->mask & CRYPTO_ALG_INTERNAL; > + *mask |= algt->mask & CRYPTO_ALG_INHERITED_FLAGS; > } This needs to use the correct logic (crypto_alg_inherited_mask) to decide which inherited flags to set in 'mask'. > --- linux-2.6.orig/crypto/adiantum.c 2020-06-29 16:03:07.346417000 +0200 > +++ linux-2.6/crypto/adiantum.c 2020-06-29 16:03:07.346417000 +0200 > @@ -507,7 +507,7 @@ static int adiantum_create(struct crypto > if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask) > return -EINVAL; > > - mask = crypto_requires_sync(algt->type, algt->mask); > + mask = crypto_alg_inherited_mask(algt->type, algt->mask); > > inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL); > if (!inst) This is still missing setting the flags correctly on the template instance being constructed. The flags need to be inherited from all "inner" algorithms: inst->alg.base.cra_flags = (streamcipher_alg->base.cra_flags | blockcipher_alg->cra_flags | hash_alg->base.cra_flags) & CRYPTO_ALG_INHERITED_FLAGS; If we don't do that, the template instance may allocate memory but not have CRYPTO_ALG_ALLOCATES_MEMORY set. > Index: linux-2.6/crypto/pcrypt.c > =================================================================== > --- linux-2.6.orig/crypto/pcrypt.c 2020-06-29 16:03:07.346417000 +0200 > +++ linux-2.6/crypto/pcrypt.c 2020-06-30 15:47:32.776417000 +0200 > @@ -263,7 +263,9 @@ static int pcrypt_create_aead(struct cry > if (err) > goto err_free_inst; > > - inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC; > + inst->alg.base.cra_flags = > + CRYPTO_ALG_ASYNC | > + (alg->base.cra_flags & CRYPTO_ALG_INHERITED_FLAGS); > > inst->alg.ivsize = crypto_aead_alg_ivsize(alg); > inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg); And this is still missing setting the mask: diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c index 7240e8bbdebb..643f7f1cc91c 100644 --- a/crypto/pcrypt.c +++ b/crypto/pcrypt.c @@ -232,12 +232,15 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb, struct crypto_attr_type *algt; struct aead_instance *inst; struct aead_alg *alg; + u32 mask; int err; algt = crypto_get_attr_type(tb); if (IS_ERR(algt)) return PTR_ERR(algt); + mask = crypto_alg_inherited_mask(algt->type, algt->mask); + inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); if (!inst) return -ENOMEM; @@ -254,7 +257,7 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb, goto err_free_inst; err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst), - crypto_attr_alg_name(tb[1]), 0, 0); + crypto_attr_alg_name(tb[1]), 0, mask); if (err) goto err_free_inst; Can you please think logically about what you're trying to accomplish? In particular, if someone requests an algorithm that doesn't allocate memory (which is indicated by type=0, mask=CRYPTO_ALG_ALLOCATES_MEMORY), that request needs to be honored. - Eric