Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp861537ybl; Wed, 11 Dec 2019 08:36:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzaO6gcO6mpPi61IhkPixxu93VBbJxyKhENa4jGYmA84bnpOmmrCuAwXHwly8Hk3Ois+ZTA X-Received: by 2002:a05:6830:1c81:: with SMTP id v1mr3010410otf.83.1576082213900; Wed, 11 Dec 2019 08:36:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576082213; cv=none; d=google.com; s=arc-20160816; b=0f+0Q3LCLlFM9P4MuGKFI2hrBOB3UXQki/PZBSrZKrRq/R0z5BhHm+KXKAoWS+qHdR 7g5NlvfWX7GxxmeN6GAMesMTsBqhhcTWgD5aMdPbxj3uaPERj8Igkgakv+gzr7d6u/Eu vHA1+gJYhc1ZcRDJEdD9+9pfBKrQ7e8/hCjyO+MkDkZ+OFSHAyEa4HyHdAzsjjOeXhoD MdInRIw68ve3RPyMYwRGxj5NyS6u8wqkeM0pXpDw2ynKONbm7KwtVwl8oA93bPxHK5Gz Tptqg6r6MB2QuZUqQrQMBWqetNHvtSJKdFzDfmX+FhWstXTHjgjhdc/sovLcJiSsDc1c MWIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=nZKIGCg2nTl1Ul0c6BYVG+oIIW13Px0JgNscQ8/wdtI=; b=0QrzEZBxieEuzGuX8op+6O33nAMHtn9UGAAmz5qjMRjpVzRtrIQfdxvaXgVqMezeBs tzhFhE+J6QvpLEGc0VsqFjPLJR2jdQ3bAw+R0riYnttho5O2TwxVrFQefyYqQYrdp89m 2+wCPHhEl2G/k55HqB4kQr16LUhhfWu6/YFTvn204Vom+kesDBgcEXwQChcoj05SPZ8c ADwcoAOwbo335etRM4islGt/Ok/a0PRpp+LKFpJf33FRu78n696XZhDcNhAsObGY3a9C yNDrnqxDd8olBy0upzNwdVVgMiyBFVrqQyZTPOqQDz0iBjCn8RVg8rlGDHr447DDQIR9 Vlcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XPTYMVZu; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z8si1395088oto.36.2019.12.11.08.36.37; Wed, 11 Dec 2019 08:36:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@gmail.com header.s=20161025 header.b=XPTYMVZu; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730134AbfLKQgA (ORCPT + 99 others); Wed, 11 Dec 2019 11:36:00 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34939 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729522AbfLKQf7 (ORCPT ); Wed, 11 Dec 2019 11:35:59 -0500 Received: by mail-wr1-f65.google.com with SMTP id g17so24759785wro.2 for ; Wed, 11 Dec 2019 08:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nZKIGCg2nTl1Ul0c6BYVG+oIIW13Px0JgNscQ8/wdtI=; b=XPTYMVZu6ZZumapGWcZcB9eesRMIPb9iqUL/ehdutneob/Qg3DSIxrDDynB4gh7ZT+ 8d66ZnwyGhpacLwyGN469unKN+mgVKt9ln6iTkAN+kKHqNRkeNTPkXl1m/2lD0fU65jy sPCoNz/6yt3Xf84lQidLbDuDZCBp0pGtvQXeX7AcZ9o3AEQaYPmuVHMPwfZ1Q+A+PZnT 7cNP3soXEeMuigotR8uYGaEwUQzRLcRnRBeyUqaiU6bW4aojrH97ammW/j7/1m646Lxt IrbBl39cAeqU9HD/AYF+E/29zugj8uaKBl/tg1LYXEs3Lo2IMopqC2du9NgJtym7W+jX txFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nZKIGCg2nTl1Ul0c6BYVG+oIIW13Px0JgNscQ8/wdtI=; b=kyFvRB2OL9/wTZWyEhxOkpFVG80ud4/DBXmTq6G0H3bJuV+YjLxtbW3rz0bprt0RDR ftPeFHpm9noHgluzzaGs1gFbwYW/uB/8JrJBHy5pgJelqFF2i1x6NLUZt8AqEtno3Pm+ 3vdI9+73vUvJTTTHVA2P+8BQTyeCfBtP8rFrFN9yOu39GXZvR0rEcdgFtz5/W5mzPSdV uWatoeGTeYygfoFlFHbZ1Bcos6P+qXsAWfteLrSnVSy1fmQqWKznAT2J7ISMKjBvWoz4 Umo6ke93wQ4mA3vT2M2bz75V7xsOhGp3a+oHARAjWkGqxEI59E/Ojwv5/QC6II0DmEUs H0sw== X-Gm-Message-State: APjAAAU107Ab690CA9992EgNv4s65DzErwYgV4EtJI5n7gj8Cqnkz3Ik m2pk84PgMQ88q3ebD4V4/icxO5+bri2LHA== X-Received: by 2002:adf:e6c5:: with SMTP id y5mr729257wrm.210.1576082158046; Wed, 11 Dec 2019 08:35:58 -0800 (PST) Received: from localhost.localdomain.com ([31.149.181.161]) by smtp.gmail.com with ESMTPSA id o19sm2162405wmc.18.2019.12.11.08.35.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2019 08:35:57 -0800 (PST) From: Pascal van Leeuwen X-Google-Original-From: Pascal van Leeuwen To: linux-crypto@vger.kernel.org Cc: antoine.tenart@bootlin.com, herbert@gondor.apana.org.au, davem@davemloft.net, Pascal van Leeuwen Subject: [PATCH 2/3] crypto: inside-secure - Fix hang case on EIP97 with zero length input data Date: Wed, 11 Dec 2019 17:32:36 +0100 Message-Id: <1576081957-5971-3-git-send-email-pvanleeuwen@rambus.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576081957-5971-1-git-send-email-pvanleeuwen@rambus.com> References: <1576081957-5971-1-git-send-email-pvanleeuwen@rambus.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The EIP97 hardware cannot handle zero length input data and will (usually) hang when presented with this anyway. This patch converts any zero length input to a 1 byte dummy input to prevent this hanging. Signed-off-by: Pascal van Leeuwen --- drivers/crypto/inside-secure/safexcel_cipher.c | 40 ++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c index b76f5ab..db26166 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -782,16 +782,31 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring, memcpy(ctx->base.ctxr->data, ctx->key, ctx->key_len); - /* The EIP cannot deal with zero length input packets! */ - if (totlen == 0) - totlen = 1; + if (!totlen) { + /* + * The EIP97 cannot deal with zero length input packets! + * So stuff a dummy command descriptor indicating a 1 byte + * (dummy) input packet, using the context record as source. + */ + first_cdesc = safexcel_add_cdesc(priv, ring, + 1, 1, ctx->base.ctxr_dma, + 1, 1, ctx->base.ctxr_dma, + &atoken); + if (IS_ERR(first_cdesc)) { + /* No space left in the command descriptor ring */ + ret = PTR_ERR(first_cdesc); + goto cdesc_rollback; + } + n_cdesc = 1; + goto skip_cdesc; + } /* command descriptors */ for_each_sg(src, sg, sreq->nr_src, i) { int len = sg_dma_len(sg); /* Do not overflow the request */ - if (queued - len < 0) + if (queued < len) len = queued; cdesc = safexcel_add_cdesc(priv, ring, !n_cdesc, @@ -803,27 +818,16 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring, ret = PTR_ERR(cdesc); goto cdesc_rollback; } - n_cdesc++; - if (n_cdesc == 1) { + if (!n_cdesc) first_cdesc = cdesc; - } + n_cdesc++; queued -= len; if (!queued) break; } - - if (unlikely(!n_cdesc)) { - /* - * Special case: zero length input buffer. - * The engine always needs the 1st command descriptor, however! - */ - first_cdesc = safexcel_add_cdesc(priv, ring, 1, 1, 0, 0, totlen, - ctx->base.ctxr_dma, &atoken); - n_cdesc = 1; - } - +skip_cdesc: /* Add context control words and token to first command descriptor */ safexcel_context_control(ctx, base, sreq, first_cdesc); if (ctx->aead) -- 1.8.3.1