Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3670088pxb; Mon, 21 Feb 2022 03:17:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAniYVxwxG4WbKgkMByuvJAPtCLNYdcoTaumIMHz6fXUcgisSeAEO3PBwpBKHm8JWQNykQ X-Received: by 2002:a63:5f41:0:b0:373:a108:3b60 with SMTP id t62-20020a635f41000000b00373a1083b60mr15948448pgb.0.1645442248282; Mon, 21 Feb 2022 03:17:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645442248; cv=none; d=google.com; s=arc-20160816; b=eMz11eXS+qEXnh0avpCK2oQpHeFz9405OehwxOW703Zj/1c1N0ZgDr7kcC7J0YpL3g BSL8NqaHSriylqZT0/RLAIueIa1StaQQ3MsjR1ptM2WHwJyD17SjYibh17rMgmqSKtf9 j8fcX/uBi+n0vCiz5AfHaCIzocyod9EO2nSjiQGmt7k7BBMa298GaFBuvGx+pI0r0Ldq MDxIv0DCXuvzYX2xYeKxW35tOTPX60VYjsbf4o8jnP7eWk9Y7k3LHizBYM3PMGQNTKam C0gmjKy/mkLoTGdPH20SEoFj6RQ5MGuPgKDCd+bBnDXe8m2yUHd4zq+obn2ngp0QnETl 9EkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=NcBfBvIGN108GW6jqQkaKU5JgXcj88Gw87NnerqCbbk=; b=PFH+Tj6YACzJlpYjYo5QbteitVIx8+ALpGYUrkSfvs9uCTxyXPE2g718eDQMMfMKgk qxpLLIcgvJ1biLzTFWxgTlZ98admoxKflZHGO4F9jATQUL3z7XtmCSUapmF1qxUZxdL7 SQa8nruqoXPNNfFiOWQQB18pC74RcHUfFFip9N2T+1V42jHOF1N+Dw9MxUKFEg4xVK4x CtrTtm4oNpDwc4TyzMrUvS/I4Ddh5ny0zNbVsDZN4nAghnhcwipryMVhoRvgDl0LaSvQ Cy2K8AUKlvIg9QMahy2eh7ALFneIl1kiv/APDMhKEpu/y1PDbi/+TZDib0mEmaB6AL4Q 79uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@benyossef-com.20210112.gappssmtp.com header.s=20210112 header.b=U5GQR6zl; 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 c12-20020a17090a4d0c00b001bc3ee8ac1esi1929166pjg.128.2022.02.21.03.16.59; Mon, 21 Feb 2022 03:17:28 -0800 (PST) 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=@benyossef-com.20210112.gappssmtp.com header.s=20210112 header.b=U5GQR6zl; 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 S1355458AbiBUKrN (ORCPT + 99 others); Mon, 21 Feb 2022 05:47:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355428AbiBUKrD (ORCPT ); Mon, 21 Feb 2022 05:47:03 -0500 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD7A53B69 for ; Mon, 21 Feb 2022 02:08:14 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-2d07ae0b1bfso131936597b3.6 for ; Mon, 21 Feb 2022 02:08:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benyossef-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=NcBfBvIGN108GW6jqQkaKU5JgXcj88Gw87NnerqCbbk=; b=U5GQR6zl+wEC+s4zqGuQ4Z/opVNdqTCgBCpxJTCXnyqOyuqKQzveaubSuCxrl+2A3i RxAO0Qa8+vn7ok7GQ02CVdScymbqa0/BCZ8POoqrSXbGg8MC3qls8kS+PmtccZ2nche5 v8PRQ7U5t7qzrqYVDgG7uzboch8pq2uHY9w8xsdxwSNK0gO3BpboqOvbEDYx8Vtg+RFl az7pOvlBzLVs9z3Aevx2tpPKz8MHJOhrPS2CZKmFqUJdUP+7UtFS4GpmqokaDG0IQrrC 7ROWUUNfCw7MMAmpAAzOJBGMYsAXt/zeqmKh8Q6P+lmk4YT22Msg7kOLGXauwmbypvWg Ip8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=NcBfBvIGN108GW6jqQkaKU5JgXcj88Gw87NnerqCbbk=; b=pxdDQEzWZIbAjSkQFqUDiq3pB7r+A5pSGOzbtQw9oLOuDf3vxjhjYivpKVt6dV7Ky8 e+gAVIyJALgTKVfedPMTkC9JCxwRBsSNz7T0VWKKWu0UCNTiJe8Eo/ISSQAoSmfzsR/o 5qOXWahSwdNPeqEaCvH1FVyz5V+kbW5ALlYvVmBdhwXLyX/JUqpG9PelvCprDBiTa1K7 IBQ+DDXZllbf1754olN+39l38VEZf4HeP6VBw+86pMf87NCOMXO/u0/jWBK3xnLfabV5 IjeIDyn/8kd63stQzQUR+EHpnLLCe6VNHjDBmIkv8PFRG7ZDe6EDaiq7eiWh0JUfJJn1 ilMA== X-Gm-Message-State: AOAM533Aj4AieZQKcoi7OqoWdnohjzT8yvtiSq3DH4vUI9XxX5xqNL2/ U+WXZCyKQw3pUKwxMp55h2JSQlGsM6ZKIjznaAmF+w== X-Received: by 2002:a81:a97:0:b0:2d0:b672:5bd4 with SMTP id 145-20020a810a97000000b002d0b6725bd4mr18539822ywk.90.1645438093649; Mon, 21 Feb 2022 02:08:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Gilad Ben-Yossef Date: Mon, 21 Feb 2022 12:08:12 +0200 Message-ID: Subject: Re: [BUG] crypto: ccree: driver does not handle case where cryptlen = authsize =0 To: Corentin Labbe Cc: Herbert Xu , Linux Crypto Mailing List , Linux kernel mailing list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_NONE, 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 Hi, On Sun, Feb 20, 2022 at 9:26 PM Corentin Labbe wrote: > ... > > Hello > > While testing your patch for this problem, I saw another warning (unrelat= ed with your patch): Dear Corentin, you are a treasure trove of bug reports. I love it. Thank you! :-) > [ 34.061953] ------------[ cut here ]------------ > [ 34.066656] DMA-API: ccree e6601000.crypto: cacheline tracking EEXIST,= overlapping mappings aren't supported > [ 34.076555] WARNING: CPU: 3 PID: 475 at /home/clabbe/linux-next/kernel= /dma/debug.c:571 add_dma_entry+0x1d0/0x288 > [ 34.086748] Modules linked in: > [ 34.089809] CPU: 3 PID: 475 Comm: cryptomgr_test Tainted: G W = 5.17.0-rc3-next-20220210-00115-g1ca9f29d9780-dirty #25 > [ 34.101635] Hardware name: Renesas Salvator-X board based on r8a77950 = (DT) > [ 34.108508] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYP= E=3D--) > [ 34.115471] pc : add_dma_entry+0x1d0/0x288 > [ 34.119569] lr : add_dma_entry+0x1d0/0x288 > [ 34.123664] sp : ffff80000e3236f0 > [ 34.126976] x29: ffff80000e3236f0 x28: 0000000000000000 x27: 000000000= 0000000 > [ 34.134122] x26: 0000000000000000 x25: ffff80000b3c76c0 x24: ffff80000= b3c7000 > [ 34.141267] x23: 0000000000000000 x22: 00000000ffffffef x21: ffff80000= a8c1000 > [ 34.148410] x20: ffff0004c0b93f80 x19: ffff80000b320000 x18: fffffffff= fffffff > [ 34.155554] x17: 6c7265766f202c54 x16: 534958454520676e x15: 000000000= 00001fa > [ 34.162697] x14: ffff80000e3233f0 x13: 00000000ffffffea x12: ffff80000= b3bdda0 > [ 34.169840] x11: 0000000000000001 x10: 0000000000000001 x9 : ffff80000= b3a5db8 > [ 34.176984] x8 : c0000000ffffefff x7 : 0000000000017fe8 x6 : ffff80000= b3a5d60 > [ 34.184126] x5 : 0000000000057fa8 x4 : 0000000000000000 x3 : 00000000f= fffefff > [ 34.191269] x2 : ffff80000b34db38 x1 : 371dfc0f85526100 x0 : 000000000= 0000000 > [ 34.198411] Call trace: > [ 34.200856] add_dma_entry+0x1d0/0x288 > [ 34.204604] debug_dma_map_sg+0x150/0x398 > [ 34.208615] __dma_map_sg_attrs+0x9c/0x108 > [ 34.212717] dma_map_sg_attrs+0x10/0x28 > [ 34.216554] cc_map_sg+0x80/0x100 > [ 34.219875] cc_map_cipher_request+0x170/0x3c8 > [ 34.224319] cc_cipher_process+0x210/0xb58 > [ 34.228415] cc_cipher_encrypt+0x2c/0x38 > [ 34.232338] crypto_skcipher_encrypt+0x44/0x78 > [ 34.236786] drbg_kcapi_sym_ctr+0xdc/0x1f8 > [ 34.240887] drbg_ctr_generate+0x5c/0x98 > [ 34.244812] drbg_kcapi_random+0xb4/0x260 > [ 34.248823] alg_test_stdrng+0xf8/0x2b0 > [ 34.252661] alg_test.part.29+0xb4/0x398 > [ 34.256583] alg_test+0x48/0x78 > [ 34.259724] cryptomgr_test+0x48/0x50 > [ 34.263386] kthread+0x11c/0x128 > [ 34.266619] ret_from_fork+0x10/0x20 > [ 34.270198] irq event stamp: 318 > [ 34.273424] hardirqs last enabled at (317): [] __up= _console_sem+0x60/0x98 > [ 34.281869] hardirqs last disabled at (318): [] el1_= dbg+0x28/0x90 > [ 34.289531] softirqs last enabled at (314): [] __do= _softirq+0x4a8/0x5ec > [ 34.297796] softirqs last disabled at (305): [] irq_= exit_rcu+0x18c/0x1b0 > [ 34.306061] ---[ end trace 0000000000000000 ]--- > So, this is an interesting one. What I *think* is happening is that the drbg implementation is actually doing something naughty: it is passing the same exact memory buffer, both as source and destination to an encryption operation to the crypto skcipher API, BUT via two different scatter gather lists. I'm not sure but I believe this is not a legitimate use of the API, but before we even go into this, let's see if this little fix helps at all and this is indeed the root cause. Can you test this small change for me, please? diff --git a/crypto/drbg.c b/crypto/drbg.c index 177983b6ae38..13824fd27627 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1851,7 +1851,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg= , /* Use scratchpad for in-place operation */ inlen =3D scratchpad_use; memset(drbg->outscratchpad, 0, scratchpad_use); - sg_set_buf(sg_in, drbg->outscratchpad, scratchpad_use); + sg_in =3D sg_out; } while (outlen) { Thanks! Gilad --=20 Gilad Ben-Yossef Chief Coffee Drinker values of =CE=B2 will give rise to dom!