Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9982458ybi; Wed, 24 Jul 2019 13:30:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUe0bvb19F3cA30+z4jJWcLeuEJY7tHEV9BxF4XfLsSI9SY2T/mcfn/we3ghJxHpJqcfzM X-Received: by 2002:a17:902:2a27:: with SMTP id i36mr86090130plb.161.1564000235688; Wed, 24 Jul 2019 13:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000235; cv=none; d=google.com; s=arc-20160816; b=ifQuwwa0IiV6gCSYhIB2Wn7IX/PGhURR8KZZWpMzmnInMHRz+jKto0ITEOSieJml3Y 5ZZ9cD/vy4vi9xNJvx9BlZRVV4fJBEfisfNl8hL2eHitIbxVQ1jcI1MoLeFzderqaRMt lOa7kpIc1228q31ZHDW4aPpWLvzlahrcsM+rZSA2SMCFChoM8bC0l4A0+xBkr1bt8b3w 1AFkAW6cXKOxma27fvkI4MXCx/k1WnGLUv64jOd1bdF66hRe0dr+xtl4zySdlpqv838p DZqIwG9pHIrqZmX6EUej5smdjSd64OfXx6VJCs3Uve3iL+xmYKCzw/1ncplRtI1GfOF+ pDUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LA43Y+qJpSIwh4EzSlDVS2LeMD9bA7fSDFLTQ2y2EX0=; b=K4xHvmrzqERyT7FyiZ0uLfuys6Eb0gCgweEwk+KfwrKLHH+UtR/iW6aNBUDpSgW/RG ERsMXkjjujup/LMNI8RbzVfVtmcPxMrFu7e/u3aafHrmB2Ci/pkZEKGtyzaP4lMSEe/z akMgaDwsm01KHSojzetyc/acRfZ/CjmFiS8cXHMAgUI+rzQA9xIB+cEXZkTORHRruLia 4vOJVZzh7GnsTim+c948orPALzM/yfiA00Z4VlovM80AtqV/h4TpgvNkfKLeGv13UCkS 1W3Oeq/W0OMh4lJk2V1AYFtnfaJ0czjmK+s2IlkvRgaTKd86NQwa98i92z5HepMIVvCl rj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BtfoiRHJ; 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 j23si15608860pgh.535.2019.07.24.13.30.21; Wed, 24 Jul 2019 13:30:35 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=BtfoiRHJ; 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 S2388880AbfGXU1v (ORCPT + 99 others); Wed, 24 Jul 2019 16:27:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:60262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389201AbfGXTf0 (ORCPT ); Wed, 24 Jul 2019 15:35:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C47B421951; Wed, 24 Jul 2019 19:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996925; bh=4g3R6gamTRzQOqVc+zMXK0Qvwcpv4izx9jeryaWRd/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BtfoiRHJnAizXLZuButMETl0kn7uqbo9V+E4sI2z7iT7Shh815LUz9gSgKhq1WAFp E+GAB8tF4Sl/XHwKwqMEsY9Gc8tZrSd66QOhW5Jjpb+B60z/6K6thYJY2Efovlt+Ne aORVxJVx0VhKhzcQIqGpMKJtmL/TLA5G91zshUhw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Horia Geanta , Iuliana Prodan , Sascha Hauer , Ard Biesheuvel , Herbert Xu Subject: [PATCH 5.2 264/413] crypto: caam - limit output IV to CBC to work around CTR mode DMA issue Date: Wed, 24 Jul 2019 21:19:15 +0200 Message-Id: <20190724191755.063425339@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit ed527b13d800dd515a9e6c582f0a73eca65b2e1b upstream. The CAAM driver currently violates an undocumented and slightly controversial requirement imposed by the crypto stack that a buffer referred to by the request structure via its virtual address may not be modified while any scatterlists passed via the same request structure are mapped for inbound DMA. This may result in errors like alg: aead: decryption failed on test 1 for gcm_base(ctr-aes-caam,ghash-generic): ret=74 alg: aead: Failed to load transform for gcm(aes): -2 on non-cache coherent systems, due to the fact that the GCM driver passes an IV buffer by virtual address which shares a cacheline with the auth_tag buffer passed via a scatterlist, resulting in corruption of the auth_tag when the IV is updated while the DMA mapping is live. Since the IV that is returned to the caller is only valid for CBC mode, and given that the in-kernel users of CBC (such as CTS) don't trigger the same issue as the GCM driver, let's just disable the output IV generation for all modes except CBC for the time being. Fixes: 854b06f76879 ("crypto: caam - properly set IV after {en,de}crypt") Cc: Horia Geanta Cc: Iuliana Prodan Reported-by: Sascha Hauer Cc: Signed-off-by: Ard Biesheuvel Reviewed-by: Horia Geanta Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/caam/caamalg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -999,6 +999,7 @@ static void skcipher_encrypt_done(struct struct skcipher_request *req = context; struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); + struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); int ivsize = crypto_skcipher_ivsize(skcipher); #ifdef DEBUG @@ -1023,9 +1024,9 @@ static void skcipher_encrypt_done(struct /* * The crypto API expects us to set the IV (req->iv) to the last - * ciphertext block. This is used e.g. by the CTS mode. + * ciphertext block when running in CBC mode. */ - if (ivsize) + if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC) scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen - ivsize, ivsize, 0); @@ -1843,9 +1844,9 @@ static int skcipher_decrypt(struct skcip /* * The crypto API expects us to set the IV (req->iv) to the last - * ciphertext block. + * ciphertext block when running in CBC mode. */ - if (ivsize) + if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC) scatterwalk_map_and_copy(req->iv, req->src, req->cryptlen - ivsize, ivsize, 0);