Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1422573ybv; Thu, 6 Feb 2020 03:53:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxw7QyMaywHA0eyfegRgLfO5Rg8uEQbLZ3iXoeMDmaWFywu3L1OUX6DHoEzxyqrOC5cA1q7 X-Received: by 2002:a54:4086:: with SMTP id i6mr6737264oii.65.1580989989599; Thu, 06 Feb 2020 03:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580989989; cv=none; d=google.com; s=arc-20160816; b=WhJ7N8tAOuLGrNRFV8h8nGv/U6XhSHBAqytnXVkIwwUlgIPa41WqTvk/va14f/3VJE wWDoYqFpHwp2yiQP9YSpdWIkzRGOwnV2qPmBZjGEPe3l71iG/HtRor7JMHMjOTUC53cR IqccVGshqipExrXSh2oAibJfSdr9K+JOsFgP1uWIufNrp1UCMsYCzWSKN/g+d5xRbmE7 R5BMOlOb9phVxL31e1blcjzw5ri3jbLXll7yQJz8RW+xfIlZDJwTu7gQBEBD/D4IuIFt ZzXw3orY+s7uov/IA9VmJr9o9lbEaHbl7iTjLgUFUjSxgi9lNA1La2cCGNI5PB8pRdot PZsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KveIEjp3HbjihFmRx/reDDqbhCsUHinvQ25+hm8C1tk=; b=CKt6GhXHK5mfWQ6eKHsRFSD4fjnXzz6fAuseuxGafG6t8gxtlfJbprZHnqXaY85yRW ZT/dct0o+WVoMGnCO1bV/Zs1aJJHxmQPSw6Yda2SLYHS/fvd/QPJHzF/7SpNe8i9VgkR iX+ROkEdSvIKvINAjB9bzqnPXhgVzNa2f6gNxbps0sPpkPahP4k8Wrwg4kaV5ImJNv+o e1PAli8hdfGcgG8Hq+NrMKAc+BSn6+yavhusvHcWTepLcptIxt+VR4afecpJa72E16As T1AeZM6pfMaoXRyJ+c1UchGvN2AdO/4b2oMLWR6BNC40Kc6DpDKVjHHfvNt1p3CF+KZU hdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YydT7Nnq; 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 l19si1871277oii.54.2020.02.06.03.52.58; Thu, 06 Feb 2020 03:53:09 -0800 (PST) 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=YydT7Nnq; 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 S1727472AbgBFLr1 (ORCPT + 99 others); Thu, 6 Feb 2020 06:47:27 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35157 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726538AbgBFLr0 (ORCPT ); Thu, 6 Feb 2020 06:47:26 -0500 Received: by mail-wm1-f65.google.com with SMTP id b17so6730341wmb.0 for ; Thu, 06 Feb 2020 03:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KveIEjp3HbjihFmRx/reDDqbhCsUHinvQ25+hm8C1tk=; b=YydT7NnqGWyCRETCnbqdZJelhTj3IjqHBm3cOFxMglAa5HD8pV5kRCUc+0VIvBGvYw a/DaOnEA1ohejoUwsAb0hJtvS1iQMeo9SgNZGcaSHPBhgJ+4I0nMSzeC7xZSSM7wFqOA T1Btc68A7zYHLjxEGIWOFOnq+JutvVu1EMvtUTmhgeQLMvzo/sgvZ8vDg+mOalqiZZne D+3z10BLeC6D6Wta8BlWq+cSkD+WQjna5r9GKka5AHRieWMp2ZouSYy1DV5LQJqLIF6v TDKd7xBbOd+/Vrx/rQLOoUGKprU02AkUEAx7dhpxSHo94aLPlHHisOsUlUp8HUtJWnSs iK3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KveIEjp3HbjihFmRx/reDDqbhCsUHinvQ25+hm8C1tk=; b=aTUHV/1p1jYMkN2OPlwDNuwpt4YRECDqwLke98NUKSOKZoJ1R4F1FT/HfbwSdPNi+/ J631x37lPX+ZLBYMqhTRlGXO/BajAOKelk4iGcR/ypUqVijlcZpHYEGQrHeSECiGeWmP pYIpeDUo3w9NEPgn+2yV8kyj9M/6hCMyrb/XbEUc+vl0pFNSIlat6iaH/KIOAswota86 pNL5qH8dh7tFMF2mX/nFzO3ifjusy2d863nCwdb83+wGzhCS7+RR4O4xYum3KpfUB/fN 7sFbv3Qmrjf8Fpwzyr1qouMQPoPoBpj6TCx+8chjtSnF8fLPDYbpG6k396lnvdspA32S 0qLw== X-Gm-Message-State: APjAAAXhxBhXdpeBQdw31gXpSzlfFXt6p2SFzwPv21rJPfMxzpdz2yf+ mn6askrSfw7XQ7OWLTyyO0hbESyjd6SBezt9n6D0Gw== X-Received: by 2002:a05:600c:248:: with SMTP id 8mr4140541wmj.1.1580989645523; Thu, 06 Feb 2020 03:47:25 -0800 (PST) MIME-Version: 1.0 References: <20200206114201.25438-1-Jason@zx2c4.com> In-Reply-To: <20200206114201.25438-1-Jason@zx2c4.com> From: Ard Biesheuvel Date: Thu, 6 Feb 2020 11:47:14 +0000 Message-ID: Subject: Re: [PATCH stable] crypto: chacha20poly1305 - prevent integer overflow on large input To: "Jason A. Donenfeld" Cc: "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Ard Biesheuvel , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 6 Feb 2020 at 11:42, Jason A. Donenfeld wrote: > > 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 > --- > 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 >