Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4884734ybi; Tue, 30 Jul 2019 09:48:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKwbq+LWkcwRuiM2FjcsUAOSe/PS5QsbeGhjyQR2ck3Q1zp373fVn9YunLP1yftm9l+vBa X-Received: by 2002:a17:90a:71ca:: with SMTP id m10mr64663759pjs.27.1564505302224; Tue, 30 Jul 2019 09:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564505302; cv=none; d=google.com; s=arc-20160816; b=aNlDd8GhKgIPh9zZ6LrPXBB3nA1dO4JtlXK94/Drl1xUtmkaPUoBp1NWQaEjcXP5md gz2zVXhzHe8voNHh70hxmp2+3FdOKEP2/tMrNzdm5OVhVhT83S0r52YIFqOLDyB+/Zb1 2s9ErT0nDwgP58dw0ulShgi5S0eA0+KWukTjx0Sx6+grnW3G9skfe1Jp2n2mF4+m9TsJ RXGq/QpjsiJl349L3Nk3/t3OBpDzHfLjZ5r+1bY1xEdzwDr/i/kHO+ChDWitMc5dYR/K 8x0sfRf2zqZbxXRhbTCneONVdeusNMGogukbhajDKiWBQ1T45ZS2i3rzi6yJOyRzktL2 csmw== 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=/ZwjV46DzzHJhvkofLXM/gmucTUxkg9bCdXDKFQw2mg=; b=txpHNJkiLgT+fyxl2FtCoRJK3HMhFAvmMAgQOHEL4Th2MqvjTnM16f+qC4ZP6jDxXc l0jZycGWRgR0Tq7phnU+/XZZCrlOwklzvrQPcQWgKRkWQO+7I7hMWNkSfijP8cpzDvuB LYhY9YqfjnadAsadW1cNvplKeAN4lq2Ctj1/L7TwpTqXLtzb441sCyA+zV75U4w0Xg7C mIYTlkdN3SV8kVy0rYz1G6lYf1UaojFXmWYI5WvvWr+3f6D1S/teTogeu/2Zbn6G9eRG G5YwUQuH/9xetqQIo/FDx1XYdsBV4ijNv+e7YV8fCeW8IGo242VK7A6O3PcDe230/DDM UEiA== 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 k72si33156321pge.95.2019.07.30.09.48.09; Tue, 30 Jul 2019 09:48:22 -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 S1727508AbfG3Qak (ORCPT + 99 others); Tue, 30 Jul 2019 12:30:40 -0400 Received: from inva020.nxp.com ([92.121.34.13]:39082 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbfG3Qak (ORCPT ); Tue, 30 Jul 2019 12:30:40 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E0DA81A0724; Tue, 30 Jul 2019 18:30:38 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D50651A071D; Tue, 30 Jul 2019 18:30:38 +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 8BF89204D6; Tue, 30 Jul 2019 18:30:38 +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 v4] crypto: gcm - restrict assoclen for rfc4543 Date: Tue, 30 Jul 2019 19:30:33 +0300 Message-Id: <1564504233-26186-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 Reviewed-by: Horia Geanta --- Changes since v3: - use ternary operator for return. Patch depends on series: https://patchwork.kernel.org/project/linux-crypto/list/?series=152649 --- crypto/gcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto/gcm.c b/crypto/gcm.c index 2f3b50f..8adf64f 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -1034,12 +1034,14 @@ static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc) static int crypto_rfc4543_encrypt(struct aead_request *req) { - return crypto_rfc4543_crypt(req, true); + return crypto_ipsec_check_assoclen(req->assoclen) ?: + crypto_rfc4543_crypt(req, true); } static int crypto_rfc4543_decrypt(struct aead_request *req) { - return crypto_rfc4543_crypt(req, false); + return crypto_ipsec_check_assoclen(req->assoclen) ?: + crypto_rfc4543_crypt(req, false); } static int crypto_rfc4543_init_tfm(struct crypto_aead *tfm) -- 2.1.0