Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp978335img; Thu, 28 Feb 2019 10:54:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwpCRxCU39Jj+3djTPHhNGdXMzS9IiSRJ5VPwArNAPZsYdJy9j5MRoSp13Aq35HKOh/8SuB X-Received: by 2002:a63:1625:: with SMTP id w37mr605115pgl.13.1551380093148; Thu, 28 Feb 2019 10:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551380093; cv=none; d=google.com; s=arc-20160816; b=JVLCgSXrdxuwt3umucOz5/twsG40Z4FyHr7Owvz1xCiJEG0AbLOmYDFCvmh0/KYw9O r7rfVGc275VmORR4rriDkVsEY91A9Ut3FaF92mgBY9546s9Smn0dh/C8cr6QAYnWYVzz 2KnzaPrUe6+xmWu1/jifsgLksc2zKaO2OvnuL0/w88Z9kwAoYlyjJIbsbPXyhzbiAtMX v3HVMf+vAv1u4O43wAr1HL/PsmxGeRx2W9XxxV4GPEiq12t2brP2lDSb2rqg1xiOSy6X 4xHNaRLFBKRtHzI4xoJB1LvlWs2X2vuH8UJyujXZ1lbcNMhOTPV2aguhH3mQEtp0smKC j/qA== 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:mail-followup-to :message-id:subject:cc:to:from:date; bh=QE8ki39h6L75xI0qAFVJGWVdM7dtCA78p/DtK7RtZ/U=; b=pET4ImNONm7B5KECO0NOyvyCmD2kxbX+jZEanKUvCYMk5fJlB/bSyKuxP+vL6zKOn5 gXSeM3wuGRkz1KbbiGxnanViYqiuWkpLQGdtYs7WEwqYBf31F8WpZk6tQL31pg1lzZ3h hPjkhQbQ5PuTKk1gOTLC+MErmrR18k3WXRUfK+WrGUU1IKnGMKQ/cluJyfMhLPG75f84 KacCUpJ7Q1a6hxI2e0HSVy8imw9d5TjifXYbrNWch+ojGAXH2TC2K1jGcLCsUalQgZkZ dVTDjukeeMD5goU0rewEauUrxyOm8Yj7tPNN0pwCb5xFp9tnokqg3SOBHgcObNUKHwwB 26iw== 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 p2si17971948plk.438.2019.02.28.10.54.37; Thu, 28 Feb 2019 10:54:53 -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 S2387992AbfB1Sj1 (ORCPT + 99 others); Thu, 28 Feb 2019 13:39:27 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:58248 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732879AbfB1Sj0 (ORCPT ); Thu, 28 Feb 2019 13:39:26 -0500 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id 2E47172CA65; Thu, 28 Feb 2019 21:39:24 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id 0FC2F4A4AE7; Thu, 28 Feb 2019 21:39:24 +0300 (MSK) Date: Thu, 28 Feb 2019 21:39:23 +0300 From: Vitaly Chikunov To: David Howells Cc: Herbert Xu , Mimi Zohar , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 04/10] crypto: akcipher - new verify API for public key algorithms Message-ID: <20190228183923.5klzwli5zmeew54j@altlinux.org> Mail-Followup-To: David Howells , Herbert Xu , Mimi Zohar , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190224060828.2527-5-vt@altlinux.org> <20190224060828.2527-1-vt@altlinux.org> <14843.1551377934@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <14843.1551377934@warthog.procyon.org.uk> User-Agent: NeoMutt/20171215-106-ac61c7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David, On Thu, Feb 28, 2019 at 06:18:54PM +0000, David Howells wrote: > Vitaly Chikunov wrote: > > > + digest = kmemdup(sig->digest, sig->digest_size, GFP_KERNEL); > > + if (!digest) > > You shouldn't need to copy the digest. It's being passed in to the crypto > algorithm, not extracted out. That's how Herbert suggested to do it. Quoting FYI: | On Fri, Feb 01, 2019 at 02:26:55PM +0800, Herbert Xu wrote: | > On Fri, Jan 25, 2019 at 09:01:16PM +0300, Vitaly Chikunov wrote: | > > | > > @@ -781,36 +780,17 @@ static int tpm_key_verify_signature(const struct key *key, | > > if (!req) | > > goto error_free_tfm; | > > | > > - ret = -ENOMEM; | > > - outlen = crypto_akcipher_maxsize(tfm); | > > - output = kmalloc(outlen, GFP_KERNEL); | > > - if (!output) | > > - goto error_free_req; | > > - | > > - sg_init_one(&sig_sg, sig->s, sig->s_size); | > > - sg_init_one(&digest_sg, output, outlen); | > > - akcipher_request_set_crypt(req, &sig_sg, &digest_sg, sig->s_size, | > > - outlen); | > > + sg_init_table(&src_sg, 2); | > > + sg_set_buf(&src_sg[0], sig->s, sig->s_size); | > > + sg_set_buf(&src_sg[1], sig->digest, sig->digest_size); | > > + akcipher_request_set_crypt(req, &src_sg, NULL, sig->s_size, | > > + sig->digest_size); | > | > It's not clear that sig->digest is guaranteed to be kmalloc memory. | > In any case, it's best not to mix unrelated changes in a single | > patch. So please keep the kmalloc on output and then copy | > sig->digest into it and put output into the SG list. > > + if (memcmp(c, outbuf_enc, c_size)) { > > Please use == 0 and != 0 with memcmp() and strcmp(). Their return values are > kind of inverted in sense if you treat them as boolean. OK. Thanks!