From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1FC7C28CC0 for ; Thu, 30 May 2019 14:29:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A542625AE5 for ; Thu, 30 May 2019 14:29:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Jqd8neyC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbfE3O3I (ORCPT ); Thu, 30 May 2019 10:29:08 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:46046 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbfE3O3I (ORCPT ); Thu, 30 May 2019 10:29:08 -0400 Received: by mail-io1-f67.google.com with SMTP id e3so5193449ioc.12 for ; Thu, 30 May 2019 07:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1ZCcIn2Fw734nRU6CpDHWXMhDHV7F+Ltk873wP06S/g=; b=Jqd8neyCEkNuRN87YhxdFapVtvj+Tbefg7QKya79rtXFcXPvPfbDmD8/LhPlqb3JlP CLnYMuKeVNKY8zTXNbpyX/5sB/fXQYS9elMEpy3HKkwTasyzx0VhVei7/AzkjTDog7uo zIAdFN3YiNTUjjuep8yLqK/uca57TYPkXPbnI4MiquiezKEvElUQ5+4LzR366O9NX9tI gH83EfQVhKpzFbk3tI+w2MQ0ln7MLFlL/UTO1nvEcOvyGaNR2rXIfcmhGr6eVXJwPr1w LT1yegueCSEZe+ljgtOqA5+gasVT1P7p07GP3eu8ipfvmGBQmzMW5vU1bbO043BnJzy7 Onvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1ZCcIn2Fw734nRU6CpDHWXMhDHV7F+Ltk873wP06S/g=; b=dvRPZiZ8PG1XP94Z5g7Yogw7VdO231lt7rxePtbom8J3qV+TE/bVhlC9oy0ySFpXFT nK10FqiUt2AZRnCVx1NKNCCc5O3y/9zheg5vt2dLnoIWw/+mhPhfRHWp/Kg2Iw5huxqd BeZTlGxXzqr76yx5GTh3K/B7yXfCY41bOq/nSYSTuSib27FvIR6tk/5mDo7UqLWO+Wjh ykNh7i+N9z8PyQdBEeH3ETzXOy50YwUZNg0NVlrpeTpjooOoTdKD2oYUlx+o+1JPC2sM QWYAp6b9kyhuh3OspAp7uh0QQRcp2lCw7maK+FT8JJ/ksrS8nd6Q8QGOlX0VFlTafqm2 m/wg== X-Gm-Message-State: APjAAAWYiwwf0Vzp/B6xx34o6HH+wOVL4mB2abwrz1ekpbRU52q3OKSz X3Ml0lCdymGSEwxhBt2zHyjPsRURfkqgMNBNl12rTw== X-Google-Smtp-Source: APXvYqyRcCdwkWKj4MkEkBmEqD3HdIuQ+2BcSRbRW3DnbZonxPFtxP28CM+c3ZOfi1hbdn5vFqZR26SvgsaMzdIq/bk= X-Received: by 2002:a5d:968e:: with SMTP id m14mr2838976ion.49.1559226547782; Thu, 30 May 2019 07:29:07 -0700 (PDT) MIME-Version: 1.0 References: <1559149856-7938-1-git-send-email-iuliana.prodan@nxp.com> <20190529202728.GA35103@gmail.com> <20190530133427.qrwjzctac2x6nsby@gondor.apana.org.au> <20190530142734.qlhgzeal22zxfhk5@gondor.apana.org.au> In-Reply-To: <20190530142734.qlhgzeal22zxfhk5@gondor.apana.org.au> From: Ard Biesheuvel Date: Thu, 30 May 2019 16:28:54 +0200 Message-ID: Subject: Re: [PATCH] crypto: gcm - fix cacheline sharing To: Herbert Xu Cc: Iuliana Prodan , Eric Biggers , "David S. Miller" , Horia Geanta , Sascha Hauer , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List , dl-linux-imx Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 May 2019 at 16:27, Herbert Xu wrote: > > On Thu, May 30, 2019 at 03:55:07PM +0200, Ard Biesheuvel wrote: > > > > > Would this work? > > I see. You need to preserve the original IV. > > > > diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c > > > index c0ece44f303b..2ef2f76a3cb8 100644 > > > --- a/drivers/crypto/caam/caamalg.c > > > +++ b/drivers/crypto/caam/caamalg.c > > > @@ -1832,22 +1832,25 @@ static int skcipher_decrypt(struct > > > skcipher_request *req) > > > struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); > > > int ivsize = crypto_skcipher_ivsize(skcipher); > > > struct device *jrdev = ctx->jrdev; > > > + u8 out_iv[AES_BLOCK_SIZE]; > > > u32 *desc; > > > int ret = 0; > > > > > > - /* allocate extended descriptor */ > > > - edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ); > > > - if (IS_ERR(edesc)) > > > - return PTR_ERR(edesc); > > > - > > > /* > > > * The crypto API expects us to set the IV (req->iv) to the last > > > * ciphertext block. > > > */ > > > if (ivsize) > > > - scatterwalk_map_and_copy(req->iv, req->src, req->cryptlen - > > > + scatterwalk_map_and_copy(out_iv, req->src, req->cryptlen - > > > ivsize, ivsize, 0); > > > > > > + /* allocate extended descriptor */ > > > + edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ); > > > + if (IS_ERR(edesc)) > > > + return PTR_ERR(edesc); > > > + > > > + memcpy(req->iv, out_iv, ivsize); > > > + > > > /* Create and submit job descriptor*/ > > > init_skcipher_job(req, edesc, false); > > > desc = edesc->hw_desc; > > > > Umm never mind > > > > /me hides in shame > > So why doesn't this work? > Because the memcpy() occurs while the buffer is mapped for DMA, so it suffers from the exact same problem.