Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4609219ybi; Tue, 30 Jul 2019 05:08:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRIOh1AdHFqprVo+ZcqT7df6O2a2maiDgiUpfI+YxA6rJWjjz3MgHDALDK8JZuU3QbweOK X-Received: by 2002:a17:902:8649:: with SMTP id y9mr112997170plt.289.1564488503030; Tue, 30 Jul 2019 05:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564488503; cv=none; d=google.com; s=arc-20160816; b=xeunsNxw7D/flP07nbqy0EwSboL5pdGLQVArLWPfxyzrQjKDfnt+ajALltLa5T96Bz tLSXxrPP/HqcwDNfeY2dmIesNHs/h56O5A7c/cma6dgpSin2H9u9f1o1ruRsDcjH0Z4q GECptDtm9RmX4a9/2jiCsb/V2Bya4knglS4b3ba0s1uSxuTwqG0IuK1XlcS3UZGDgmvd /WJzCdhcNhc7ltv5BPFBu1LWAqbTshBxlK9sadXYaG1u1ObfyagqxlmFOPcczDBuZqUA jbtBUqfSzY3km0W2wOfP83BN57VRh5SJ0+W1DtFV2RSKA23KRYLu3qWwhvOsJ7Ruv6LT ytmA== 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=PRDxzkEbV0V5JUVvRQU6R3vs8U2uNUW4SoRjB1sPpxM=; b=onVcXGUP/9aWZXqRsw24ZFOW/vnpbL+g20ELnIkcNozKF2Kq0DGnwBGqeFCsvRCVNn kkrKk2Ie1NIqni8+cu3k2C08sc/ZPr7ZQ7Ym0G7MdpKyx3MKBANITsJItQp7g42ZB4Dn ff6PvMN0A48atuwgNYeCR0wvuuP2+Ia0P5YDVcvL7OPvd51xISG67IHsgbqw3fpPdnUg a6ULrbuaW3DA8LJDBytZXQWcMxy0POM4wKU6fQpdkeSTIW18ydtK49eqSxhvLhjV1gYI 37dQwEWwfYx1+/YdMWC28lAFxE4SmX1aosuD6miLEvMdYBC/F5NXWMYswyfhOoZCGkB7 2rtw== 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 f15si27657861plr.260.2019.07.30.05.08.09; Tue, 30 Jul 2019 05:08:23 -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 S1728960AbfG3LDH (ORCPT + 99 others); Tue, 30 Jul 2019 07:03:07 -0400 Received: from inva021.nxp.com ([92.121.34.21]:51554 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725974AbfG3LDH (ORCPT ); Tue, 30 Jul 2019 07:03:07 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 99F9E20065E; Tue, 30 Jul 2019 13:03:05 +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 8DE20200186; Tue, 30 Jul 2019 13:03:05 +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 2E711204D6; Tue, 30 Jul 2019 13:03:05 +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 v3] crypto: gcm - restrict assoclen for rfc4543 Date: Tue, 30 Jul 2019 13:54:37 +0300 Message-Id: <1564484077-27727-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 v2: - use, newly renamed, helper functions added in crypto API, in series: https://patchwork.kernel.org/project/linux-crypto/list/?series=152649 crypto/gcm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crypto/gcm.c b/crypto/gcm.c index 2f3b50f..7eb5ced 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -1034,11 +1034,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 = crypto_ipsec_check_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 = crypto_ipsec_check_assoclen(req->assoclen); + if (err) + return err; + return crypto_rfc4543_crypt(req, false); } -- 2.1.0