Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1850963pxb; Fri, 27 Aug 2021 20:17:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRnJwvTCglBMfbu4dIQ58xbqVVYMMDrD4+W0pX8auy0o4HL+dBFkIUL+VLJ95Q15Ht8SAJ X-Received: by 2002:a05:6e02:1288:: with SMTP id y8mr8457878ilq.206.1630120641516; Fri, 27 Aug 2021 20:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630120641; cv=none; d=google.com; s=arc-20160816; b=LuvJuICBoCz2fffOgKnPuChp44mrxMUyGfKUckuzMOf5aKzB1S4IedMjAVpRQVghcU 9yXDuolrbCwbp1yHjWsy+DBZpSKXVBY/0BoPx8udnqgDElgt0ZpmloXSI+5YogH+vf0A fGHHVELhslA5tg42JmaboU13V0MJXp35amRw8E2hFDsfF20ZOrfBeoCyMKNAIqcgt33S 4Rou4JTTMFuAe6uHZ6+daRCMutsvVVN+SZLK/YHz2OJSZb47d+ehCMZWshxBynjtdbgg KTULyZqM4wf6mISl4FoCWTWwNA+ipVhTjFu4k1utdILAXf3C0oqCb+1o1WyEHP5TFNxY b6vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:to:subject; bh=9jlndjR2og6d6uoLnUYMbNiSaJDPMpJ1nxhhFIzYIZE=; b=jrsd80IxgCSAfV4bDI3LZIHO57LJsDJ7g5H/F8yRtry5p98OIDDfeUT42YJGLr0eyV Z1GK/UKgTzTwqk/0P12i6bfDbETLhepYD4n8VZPC8xNiQ0gKDU6APZ0+jnwAi7eEd+Ef xoqdZprQuGSE4QDXUPgut62wTIdzdDeNuSwMs2UexpN8XbPl1U2O2m/o8ocpkRcuhg+b uO+OHmnBWNIn9n+IGL3yyJvLV93rgFiKSQBLgsLqYlr5tMH2oaZFSrZHkNSLpWbk8dEs a+ulKYirItWnmaw8mQzn3HtzAgd7ChmJmiIaFMwitq7cJDXbj5O3JW9zbM+Y1/3F60tU YM0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n22si7820768jaj.53.2021.08.27.20.16.52; Fri, 27 Aug 2021 20:17:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233158AbhH1DRk (ORCPT + 99 others); Fri, 27 Aug 2021 23:17:40 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:18983 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233117AbhH1DRj (ORCPT ); Fri, 27 Aug 2021 23:17:39 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GxM8l49nzzbhfN for ; Sat, 28 Aug 2021 11:12:55 +0800 (CST) Received: from dggpeml500012.china.huawei.com (7.185.36.15) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 28 Aug 2021 11:16:47 +0800 Received: from [10.67.103.212] (10.67.103.212) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 28 Aug 2021 11:16:47 +0800 Subject: Re: [PATCH 2/5] crypto: hisilicon/sec - add ahash alg features for Kunpeng920 To: Herbert Xu , , References: <1628847626-24383-1-git-send-email-yekai13@huawei.com> <1628847626-24383-3-git-send-email-yekai13@huawei.com> <20210821072557.GA31491@gondor.apana.org.au> <20210827083652.GD21571@gondor.apana.org.au> From: "yekai(A)" Message-ID: <337a3bac-86d4-c66e-9d6a-d4aa6685f83d@huawei.com> Date: Sat, 28 Aug 2021 11:16:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20210827083652.GD21571@gondor.apana.org.au> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.103.212] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500012.china.huawei.com (7.185.36.15) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 2021/8/27 16:36, Herbert Xu wrote: > On Sat, Aug 21, 2021 at 05:07:00PM +0800, yekai(A) wrote: >> >> >> On 2021/8/21 15:25, Herbert Xu wrote: >>> On Fri, Aug 13, 2021 at 05:40:23PM +0800, Kai Ye wrote: >>>> >>>> +static int sec_ahash_import(struct ahash_request *req, const void *in) >>>> +{ >>>> + /* >>>> + * Import partial state of the transformation. This function loads the >>>> + * entire state of the ongoing transformation from a provided block of >>>> + * data so the transformation can continue from this point onward. >>>> + */ >>>> + struct sec_req *sreq = ahash_request_ctx(req); >>>> + >>>> + memcpy(sreq, in, sizeof(struct sec_req)); >>>> + return 0; >>>> +} >>> >>> Please explain how this works given that you've got pointers in >>> struct sec_req? >>> >>> Thanks, >>> >> We have set the sec_req size by use the "crypto_ahash_set_reqsize" in ahash >> tfm init process. The crypto will allocate memory for the sec_req by >> "__ctx[]". And we can got the pointers by use ahash_request. like >> >> void *temp = ahash_request_ctx(req); >> struct sec_req *sreq = (struct sec_req)temp; >> >> The value of halg.statesize is sizeof(struct sec_req), so the user can get >> the statesize. > > The data you get from the import could be random garbage. Please > explain how you avoid dereferencing random pointers in your code > through the import path. > > Thanks, > I refered to other people's plans. Modify the value of halg.statesize is sizeof(struct sec_req) + sizeof(u32), So user can allocate an extra sizeof(u32) memory. The driver will write a tag number to the addr in the export process, then the driver will check the pointers by the tag number through the import path. I think this plan can avoid random pointers. Thanks Kai