Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp346184rwe; Fri, 26 Aug 2022 06:12:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6u3n6DWrLRZh8ziW6mdoq5465Oyy1yupPxdwSqp1BceKJ2EQ8Fn1F+v2gXOsSDGhnj/bkL X-Received: by 2002:a62:be0d:0:b0:535:df64:b106 with SMTP id l13-20020a62be0d000000b00535df64b106mr3909047pff.60.1661519569885; Fri, 26 Aug 2022 06:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661519569; cv=none; d=google.com; s=arc-20160816; b=L3LSf1tvxTQl+tQ7aNtOT7WkN2c1ckFLI117t9SqzfQF7JopSWJBFbUMW4hj7HFNmu /+yGKKcJg7znE2XouNXfR8QCRw122Y87eI/UR2PbXTeZT3h54uLhZnXw9LfGkdsNljTg cixmkFkPaZwZzV7tH5F7uCrGFx4KxD2AIMHwhmr1VAbLaTqg1BT9pFT4hnmsRzwBH7uP 8sa6iuuJvcFoT5j/I9H9/jLQoc4ymgesvfXRel6NYusTrvW2HfU/AtRYOfcy+XCZEi++ feJaPLZ1gHICVRwKY+QGWCbbj0kiXQAWhMJzYEi8qCUg5vEAQyxHrWD0YT9EyeQqr6x8 vjlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gbEN9UxsU21xAmPqLRQ6bvCHMSIs70CWk4vdsoTV/Vs=; b=auSMmnhtDMohi9qIJKP18GhuSPdHKCL/PIcP5Uk/8YkF6RlFpm3B0hy17pNB3ULd5v 2WPSf1VMzolAfe2py2LyTbugeyCfEbHaXKg5l2NdHWVcCQaTmgxrppi5Y5CDiquXm/FO KCaE2aXBi3yqhcUGPIKMH/46hUjkCD3IuzSV9wGz/hYvKPfpEhSht6q/DEY8RmdJRWba GwXJCLLf0bVvYbhRvJJhXAcd+ZjqyT7lsQ6J3PvaQKEMoFb872FixfNXMl4iggiJMRVD qiltpgZpugSkwUStbg6yAaUdu1Uu5XP4ZUwe3YfcYdA3Vsaq/6YHOLgI0PlW6eb8D3ga 2yFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gh589+6W; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w63-20020a638242000000b0042a08b6ae1fsi1698783pgd.4.2022.08.26.06.12.02; Fri, 26 Aug 2022 06:12:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gh589+6W; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbiHZNAu (ORCPT + 99 others); Fri, 26 Aug 2022 09:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235235AbiHZNAt (ORCPT ); Fri, 26 Aug 2022 09:00:49 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9C724977 for ; Fri, 26 Aug 2022 06:00:47 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j26so862623wms.0 for ; Fri, 26 Aug 2022 06:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc; bh=gbEN9UxsU21xAmPqLRQ6bvCHMSIs70CWk4vdsoTV/Vs=; b=gh589+6W1ZyYJ1lLD3Z/wqWLWBk+C3Y7Ck1WtAelzQ4mZ5TBg6OXaVXj48DaY0y0xA nnKT7jc2LYXkebw597InPMdPiu6PyxAB34f5wQ7TAa8WJwxWcluBVRnAF7VLusPoRBiY 2khmNbwrBXUcuH4p6WHWTtS1U94HS+jWPlZ/tfHrq6skV7RmMq7TYpX3Rblmf0tEVX0p tKS+pqokJb3mqHbk89QHFXrpNX4KYfYMaHd6s6XfrJd5F72vETmRwHNkB07k8z9ob/7w 6XkTDYlPV4s0zH9AnHwgvZKcdY91vpuiuSeNv3zW1dcZi6atxDFhEuuYmBlvkS7ADQxO rAAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc; bh=gbEN9UxsU21xAmPqLRQ6bvCHMSIs70CWk4vdsoTV/Vs=; b=4FOqzREHNk6AAJmtxW6eW9vI6fGpsS7m+CaBvOOIrnPEOO9BHSz9DrQr82ZTi/UoMk VxonDMWoY2MKSEoHEvS8Hpsh5+j2PQi8hQRMcZTwlydlxZtLH5pGQu8f5r8bn7IQXmOO YEyNoCkg6mrLwyVAVV9AcXX/Lc6HD8/ieit6XEqf1KabNIwhzPYdMDG5Dvn8b/hwqeA6 wrO2m0v5Z+8FculvRMDz+RP62OG6/sju34vgh8x3rzjufR+jX/s0rRNhF2dxt1hWaNTe KyCdY4J4Mmd/RIawA3IRJP2Zs3qwulfrMXpG/R7lztxWXNwmpQPBiJtFiYGSUZ7Zrffw 0u5g== X-Gm-Message-State: ACgBeo1TgIhXb2phs5Qg/uWM+SWVYwpEd2StVIdgWB5x0ffaNHSuisuF xbSAz9nckH+kmqOlFKCsQBJAtQ== X-Received: by 2002:a05:600c:3482:b0:3a6:e09:1ebf with SMTP id a2-20020a05600c348200b003a60e091ebfmr5158387wmq.173.1661518846210; Fri, 26 Aug 2022 06:00:46 -0700 (PDT) Received: from Red ([2a01:cb1d:3d5:a100:264b:feff:fe03:2806]) by smtp.googlemail.com with ESMTPSA id a4-20020adfeec4000000b002258c4e82casm1359965wrp.98.2022.08.26.06.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 06:00:45 -0700 (PDT) Date: Fri, 26 Aug 2022 15:00:42 +0200 From: LABBE Corentin To: Dan Carpenter Cc: linux-crypto@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: Re: [bug report] crypto: sun8i-ss - rework handling of IV Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Le Thu, Aug 25, 2022 at 07:08:56PM +0300, Dan Carpenter a ?crit : > Hello Corentin Labbe, > > The patch 359e893e8af4: "crypto: sun8i-ss - rework handling of IV" > from May 2, 2022, leads to the following Smatch static checker > warning: > > drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c:146 sun8i_ss_setup_ivs() > warn: 'a' is not a DMA mapping error > > drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c:213 sun8i_ss_cipher() > warn: 'rctx->p_key' is not a DMA mapping error Hello I dont know why I used an u32 and not a dma_addr_t. I will work on a patch fixing this soon. Thanks for the report. > > drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c > 115 static int sun8i_ss_setup_ivs(struct skcipher_request *areq) > 116 { > 117 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); > 118 struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > 119 struct sun8i_ss_dev *ss = op->ss; > 120 struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); > 121 struct scatterlist *sg = areq->src; > 122 unsigned int todo, offset; > 123 unsigned int len = areq->cryptlen; > 124 unsigned int ivsize = crypto_skcipher_ivsize(tfm); > 125 struct sun8i_ss_flow *sf = &ss->flows[rctx->flow]; > 126 int i = 0; > 127 u32 a; > > This needs to be a dma_addr_t a; > > 128 int err; > 129 > 130 rctx->ivlen = ivsize; > 131 if (rctx->op_dir & SS_DECRYPTION) { > 132 offset = areq->cryptlen - ivsize; > 133 scatterwalk_map_and_copy(sf->biv, areq->src, offset, > 134 ivsize, 0); > 135 } > 136 > 137 /* we need to copy all IVs from source in case DMA is bi-directionnal */ > 138 while (sg && len) { > 139 if (sg_dma_len(sg) == 0) { > 140 sg = sg_next(sg); > 141 continue; > 142 } > 143 if (i == 0) > 144 memcpy(sf->iv[0], areq->iv, ivsize); > 145 a = dma_map_single(ss->dev, sf->iv[i], ivsize, DMA_TO_DEVICE); > --> 146 if (dma_mapping_error(ss->dev, a)) { > > This can't be true because of the 32/63 bit bug. > > 147 memzero_explicit(sf->iv[i], ivsize); > 148 dev_err(ss->dev, "Cannot DMA MAP IV\n"); > 149 err = -EFAULT; > 150 goto dma_iv_error; > 151 } > 152 rctx->p_iv[i] = a; > > But then only 32 bits are used later in the driver in ->p_iv[]. So it's > more complicated than I thought. > > 153 /* we need to setup all others IVs only in the decrypt way */ > 154 if (rctx->op_dir & SS_ENCRYPTION) > 155 return 0; > 156 todo = min(len, sg_dma_len(sg)); > 157 len -= todo; > 158 i++; > 159 if (i < MAX_SG) { > 160 offset = sg->length - ivsize; > 161 scatterwalk_map_and_copy(sf->iv[i], sg, offset, ivsize, 0); > 162 } > 163 rctx->niv = i; > 164 sg = sg_next(sg); > 165 } > 166 > 167 return 0; > 168 dma_iv_error: > 169 i--; > 170 while (i >= 0) { > 171 dma_unmap_single(ss->dev, rctx->p_iv[i], ivsize, DMA_TO_DEVICE); > 172 memzero_explicit(sf->iv[i], ivsize); > 173 i--; > 174 } > 175 return err; > 176 } > > regards, > dan carpenter