Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10940820ybi; Thu, 25 Jul 2019 07:22:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqznVSKSMwA8RqPOA7p1pGQYZJeDVHgUN03qczrhagW4UR0ffsUtNZD09WP4vupW9Tf4dSoN X-Received: by 2002:a63:c006:: with SMTP id h6mr52881454pgg.290.1564064572138; Thu, 25 Jul 2019 07:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564064572; cv=none; d=google.com; s=arc-20160816; b=MgBfraMzhXK3Zvxuz2FkKSkSbZoaAyIAplyTkxZYmKm7At9lRA3MnQ4FdXmIBCQ8G1 5LrfV9/DiFP7Rs1wDV+r/9bXEW1TDLm+nFAwKvJxOjG1IP0x7ue5Mlc+D7bY9jECdUKO M0WmM98eUPL2GaBqqXU5Mjng5HzbMCeh/APd0cJrZTafsKq/iMgFGBQJu4bAUnhnrTC+ 9fDu/yJG81YcBCbsKLS6JQJBUKMo4/X0IAGD3WGw6MmFDIJttW4ZgjL3JDBuVaboguBI PrZxd2m9gMGYUvH3k5KCiKVSax+1t6RMcw6RSZpN+/ydQrzPxo7bnQ9doWfFERvfabKo VfSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=gyDZqVawvlD67WAnEp/kDL6QcCaLMvS8ipF/LLDvqSI=; b=VSkGWkXa3y6FRhTjwf2ibDXUoHS8+Z4BZt/ezOjGP2dPp7NjaZLxX0MJTGzyIVapRD qd1idF/VdfaiPrntM9YRo6jUaZ54INMd//F6og2sLXStPvkbNQa+NIk0en4k3wjNdRA7 p4Ymy5hHbUKok6fJmEN9m2G2DjvcnxyKxEbjXwGx3nJSJeWbU2BtX50Q/KmIj4cwlvzB rc2yJR3p8HEMTXzgfHhMzf47NIKTv80aAIu4e/ygwJHSzz3HPHZAdmsB94IQ1sWzjZsP Pxqm8S1ODFvAfQBYaWgNx38VQP+7z9QRht1lWYUUraVrdSvO7os5dNpOuE5XLtCZiHju ndtQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17si17075820plo.46.2019.07.25.07.22.38; Thu, 25 Jul 2019 07:22:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388113AbfGYNuL (ORCPT + 99 others); Thu, 25 Jul 2019 09:50:11 -0400 Received: from inva021.nxp.com ([92.121.34.21]:49876 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387579AbfGYNuK (ORCPT ); Thu, 25 Jul 2019 09:50:10 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 2176020071C; Thu, 25 Jul 2019 15:50:09 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 1421D200716; Thu, 25 Jul 2019 15:50:09 +0200 (CEST) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id C76CA205EE; Thu, 25 Jul 2019 15:50:08 +0200 (CEST) From: Iuliana Prodan To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx Subject: [PATCH v2] crypto: gcm - restrict assoclen for rfc4543 Date: Thu, 25 Jul 2019 16:49:59 +0300 Message-Id: <1564062599-8965-1-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Based on seqiv, IPsec ESP and rfc4543/rfc4106 the assoclen can be 16 or 20 bytes. From esp4/esp6, assoclen is sizeof IP Header. This includes spi, seq_no and extended seq_no, that is 8 or 12 bytes. In seqiv, to asscolen is added the IV size (8 bytes). Therefore, the assoclen, for rfc4543, should be restricted to 16 or 20 bytes, as for rfc4106. Signed-off-by: Iuliana Prodan --- Changes since v1: - use helper functions added in crypto API, in series: https://patchwork.kernel.org/project/linux-crypto/list/?series=150651 crypto/gcm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crypto/gcm.c b/crypto/gcm.c index f69c251..3346e1f 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -1037,11 +1037,23 @@ static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc) static int crypto_rfc4543_encrypt(struct aead_request *req) { + int err; + + err = check_ipsec_assoclen(req->assoclen); + if (err) + return err; + return crypto_rfc4543_crypt(req, true); } static int crypto_rfc4543_decrypt(struct aead_request *req) { + int err; + + err = check_ipsec_assoclen(req->assoclen); + if (err) + return err; + return crypto_rfc4543_crypt(req, false); } -- 2.1.0