Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4513000ybp; Mon, 14 Oct 2019 05:59:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqybalVeytXEq1n55dqxUAq2RIZxNDFPTL2DMKGWINm5eFV8CdhQp2Y9+9DaWnhkLv7kp/gW X-Received: by 2002:a05:6402:17a6:: with SMTP id j6mr27396772edy.99.1571057971535; Mon, 14 Oct 2019 05:59:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571057971; cv=none; d=google.com; s=arc-20160816; b=qO81aeNYqxGj/uXTeBlkb2zyB/qexuCa0hgmfDZDW18s+zl59p/0TLLLLL0olRStMq FG2fcLrzXt3Fblr3s5iU0kK6mMV1Gp/UBdRLWUGrUglshdNKsqOwJedZxp40OWfg9Yzg pjzmScGW7282oFZ4LNClRaG3gDK1jO26A26sPAHAazoTMVZ0TMyUVpAW3bfImnwbZxqZ RpizZQY0JorYDfOruIHnZAk7m4kBRppJ3UmIt3/pqeN7Viqul4zKyL4eXOFDcEL2hOWp SJS/FsP78qqcprV84eUaJilQ5pVnIeCgQU6CYIkwK29uPaD8FMX2+8hEisxn7lBCxThO +1+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n1CZfuSwOBWiTJLsXGGXKsTYggjtyZaieumQoTW6nsw=; b=Lzmb73IH56S4nOfw57QsNSrMp0W56PKJGuc5pTwdkPaVXNHDhT/IvDm6X6uILe4NUL tTZkSH2CNqdgheozs800aNkTTGRKQ5j74VpM16r3kkV6yyPsWaWlS3l3ZgbJxjYSC/rZ Wf/JlgajOSBwDVsV9Jtz3RWyPigrVoalVxbxxOyzy069b1ybvpLVfGsMv/JwE2DgFpzZ QXPDii/pN5QcgI30pFV3hYbmM80DchgcPyWPAwUEdvrG3yn3sW1TJtFwohEdkLRLPLqS 0cF0649EME1rfhZRjE+be2y9t2kwKyrNGZufBfRBY/UrZ+N78E6UHhurDc5/3gZeRSiR Sdzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WQDpJP0A; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si10876080eja.226.2019.10.14.05.59.07; Mon, 14 Oct 2019 05:59:31 -0700 (PDT) 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=@linaro.org header.s=google header.b=WQDpJP0A; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729903AbfJNMTn (ORCPT + 99 others); Mon, 14 Oct 2019 08:19:43 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46699 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729858AbfJNMTn (ORCPT ); Mon, 14 Oct 2019 08:19:43 -0400 Received: by mail-wr1-f65.google.com with SMTP id o18so19423767wrv.13 for ; Mon, 14 Oct 2019 05:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n1CZfuSwOBWiTJLsXGGXKsTYggjtyZaieumQoTW6nsw=; b=WQDpJP0AB2+YAQR1rinmfn2OHo20KqKocZkKU1P4qbhMNSqnEQxDm7ujDtekTGWoKg iAbuFNCd7tNmXbdKJX/sQIpUbX06YbYtmwjKKZ3WZ922rxEvoe509/iRhkeFegq2XU+c IWfX6G9vZULPAHKXRvwYvuAq+JWfw+Cg0qn5gTclmfQd7d2jOLvBLptWubPpSGrPuJtm MyKVwdi30mvGTTs/ZDV4HKJRklkhKJoE5lqO9h85PuH6siyR4oBfyBHLdVyvcJMpgWSj wk2N1Fq9cHSSberQMlsNRrCGweZ3ZGhJUzYCN5i5C50rx1IkrHVOp1M4Y8HDMpyanxtd Poww== 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:mime-version:content-transfer-encoding; bh=n1CZfuSwOBWiTJLsXGGXKsTYggjtyZaieumQoTW6nsw=; b=nIVD00BkTMhZwgansST4YDkf9g7AMOoCgc2qDWlETJ9aMv6evpkZuT2B/Wbjl3FN1Q sx2p1L3zyt2M1M38VpveGZH0YPhjimAeatRTqRVI4kmbPksyulPa83TUz75YiZ9Z9dds LMOfSM7e+P8ygA9u7hGsIrKoilpkfP/ejL0iFvSXf1IFL7nNzSZFZ4DXfFon12eNsDUy C/ozLqndzgHDDijvSZWMgLrrMVKGAmejqnfZpvqLssjbtk74HqFsrhYW0xQuC65bnBw+ jO/pa099C8PmHBedN4/DGTi/9e+bat8ReTkuN/Nr+3JvdlgTpOYoD15hKQK/Y+C05bst E7YQ== X-Gm-Message-State: APjAAAW20BW2SVd5gouDHA94FNhOU79PPz5Xi7E/yW79aRvGGD7+OX0s UscKTXlr8W66uU/WEUlSNRVtpftXRGapog== X-Received: by 2002:adf:dbcf:: with SMTP id e15mr26156311wrj.134.1571055579522; Mon, 14 Oct 2019 05:19:39 -0700 (PDT) Received: from localhost.localdomain (91-167-84-221.subs.proxad.net. [91.167.84.221]) by smtp.gmail.com with ESMTPSA id i1sm20222470wmb.19.2019.10.14.05.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 05:19:38 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , "David S. Miller" , Eric Biggers , linux-arm-kernel@lists.infradead.org, "Michael S. Tsirkin" , Jason Wang , Gonglei , virtualization@lists.linux-foundation.org Subject: [PATCH 02/25] crypto: virtio - deal with unsupported input sizes Date: Mon, 14 Oct 2019 14:18:47 +0200 Message-Id: <20191014121910.7264-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014121910.7264-1-ard.biesheuvel@linaro.org> References: <20191014121910.7264-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Return -EINVAL for input sizes that are not a multiple of the AES block size, since they are not supported by our CBC chaining mode. While at it, remove the pr_err() that reports unsupported key sizes being used: we shouldn't spam the kernel log with that. Fixes: dbaf0624ffa5 ("crypto: add virtio-crypto driver") Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Gonglei Cc: virtualization@lists.linux-foundation.org Signed-off-by: Ard Biesheuvel --- drivers/crypto/virtio/virtio_crypto_algs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_algs.c b/drivers/crypto/virtio/virtio_crypto_algs.c index 65ec10800137..82b316b2f537 100644 --- a/drivers/crypto/virtio/virtio_crypto_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_algs.c @@ -105,8 +105,6 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg) *alg = VIRTIO_CRYPTO_CIPHER_AES_CBC; break; default: - pr_err("virtio_crypto: Unsupported key length: %d\n", - key_len); return -EINVAL; } return 0; @@ -489,6 +487,11 @@ static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req) /* Use the first data virtqueue as default */ struct data_queue *data_vq = &vcrypto->data_vq[0]; + if (!req->nbytes) + return 0; + if (req->nbytes % AES_BLOCK_SIZE) + return -EINVAL; + vc_req->dataq = data_vq; vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_sym_req->ablkcipher_ctx = ctx; @@ -509,6 +512,11 @@ static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req) /* Use the first data virtqueue as default */ struct data_queue *data_vq = &vcrypto->data_vq[0]; + if (!req->nbytes) + return 0; + if (req->nbytes % AES_BLOCK_SIZE) + return -EINVAL; + vc_req->dataq = data_vq; vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_sym_req->ablkcipher_ctx = ctx; -- 2.20.1