Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BC51C3B18C for ; Thu, 13 Feb 2020 16:38:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 486FE2467C for ; Thu, 13 Feb 2020 16:38:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="mR8M3+tF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728055AbgBMQi0 (ORCPT ); Thu, 13 Feb 2020 11:38:26 -0500 Received: from frisell.zx2c4.com ([192.95.5.64]:38055 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727778AbgBMQi0 (ORCPT ); Thu, 13 Feb 2020 11:38:26 -0500 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id a4256e13; Thu, 13 Feb 2020 16:36:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=UIUcVigLyhuwbihDTXLa/xFiI A4=; b=mR8M3+tFggkWNkyaj50+0PSDdURdniICmfP9TwV24o9rcc79j4XE0dbf+ mcpwdoT1FpsfQmtfW9hUMd/s3ye5OBwx+3NHfSOaFIT0gJOVX1CFJctVg5A/iU0r zAHbB+QrYxXBY/8SO03DSeiQmH3Y7QAzzCwWrYXsA8iwVuUUtjcUXXfIFXAHL1VA j588D9HDIAJQ2q0wRJc50+fZjg14aOdp3wU4ObtmLzNLsjov/l2bGsPkpI0Kqjy8 iMXK3U26BlNye9VEoZQeIVt+lCQziEtREXe9tQoZxfGfX76A/GVQbJ2ORFDHlJc5 HQkef458NmcADTG8FRdFJRcP3TKJA== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 88524b21 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Thu, 13 Feb 2020 16:36:25 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-crypto@vger.kernel.org Cc: "Jason A. Donenfeld" , Ard Biesheuvel , stable@vger.kernel.org Subject: [PATCH] crypto: chacha20poly1305 - prevent integer overflow on large input Date: Thu, 13 Feb 2020 17:38:13 +0100 Message-Id: <20200213163813.3210-1-Jason@zx2c4.com> In-Reply-To: <20200213114647.cupaio6zmodix3fq@gondor.apana.org.au> References: <20200213114647.cupaio6zmodix3fq@gondor.apana.org.au> 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 This code assigns src_len (size_t) to sl (int), which causes problems when src_len is very large. Probably nobody in the kernel should be passing this much data to chacha20poly1305 all in one go anyway, so I don't think we need to change the algorithm or introduce larger types or anything. But we should at least error out early in this case and print a warning so that we get reports if this does happen and can look into why anybody is possibly passing it that much data or if they're accidently passing -1 or similar. Fixes: d95312a3ccc0 ("crypto: lib/chacha20poly1305 - reimplement crypt_from_sg() routine") Cc: Ard Biesheuvel Cc: stable@vger.kernel.org # 5.5+ Signed-off-by: Jason A. Donenfeld Acked-by: Ard Biesheuvel --- Due to the "stable" in the subject line prior, this patch missed Herbert's filters. So, I'm simply resending it here so that they can get picked up. Note that this is intended for the crypto-2.6.git tree rather than cryptodev-2.6.git. lib/crypto/chacha20poly1305.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/crypto/chacha20poly1305.c b/lib/crypto/chacha20poly1305.c index 6d83cafebc69..ad0699ce702f 100644 --- a/lib/crypto/chacha20poly1305.c +++ b/lib/crypto/chacha20poly1305.c @@ -235,6 +235,9 @@ bool chacha20poly1305_crypt_sg_inplace(struct scatterlist *src, __le64 lens[2]; } b __aligned(16); + if (WARN_ON(src_len > INT_MAX)) + return false; + chacha_load_key(b.k, key); b.iv[0] = 0; -- 2.25.0