Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1547530lkv; Wed, 19 May 2021 12:29:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/TFlZo1hFcWiO7XO5FXP/F6LLV1saVeUFoht2Yb0P3BZJLlBet+PvCmd2zVDWC2Eu5EAt X-Received: by 2002:a05:6e02:152b:: with SMTP id i11mr592402ilu.230.1621452556602; Wed, 19 May 2021 12:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621452556; cv=none; d=google.com; s=arc-20160816; b=ucOvq9LoBgP5n9/NBBotJIhkQXu3bWo9E1nKoM5AJmSRmZK8wefuc1NNZyoR+b60Ad NlHkaGMEN7hr6LRC6MrR7Q7+7qLhY1mFoi1w8iXq9ZRDcUz3s7DuFsVAvpgY57JmM/xm PvuFDspvb56H66p22qgMVb5poLpdmUWg1k8Pbmn4ZjuPVLppgyPtfUrEWE4f9aYGOTUB qB/SMNONZMOP6Wx5z6XuTHETf2jo6M+FzCOsyfIZDBdhDsaTI6zwyIczodSkgLFypK3l fpQbkdyQzEdduIFDGt82HvIWy8id+LT/m/lNYFJQiO1NBNAXzY6U1E7xk3LM75ndWyk1 QF7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k0JpRrbA7Yx9nmrJVdnz1BzOUwNVkq/EHJEwhEZ2UO4=; b=EnF/q9H9eY1ZBG4nO/TtitLNHXHxLD76OrFFoDdprn6+l+E1Fj7oAt9VsrRQrZ4RT1 BOG6k3tqV+UOvLFMrWo+f+TyPT+2mHZ3ertEmHwvSUUzK1CwZVAL3xVs0jtCTSHmPYEO y9oHY7EcJrqqK55KtieiJDER655DHQq+w6df2gKv7PbzcU0lhIpjb7iL+siQCUu0u8iZ FLp7CNTUSNPFN2X3D8b5XorFihlgkid9e81whyChQHo1Q/69X4H9pLHwzMBw1bMS1jHL YJjEyCu6VJHEebQ0YHuL6FOjpjAZ5fSL9QuNTXYF7n05kKd2xhcTDNZC0C6JzN9ZzS15 E9Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pR9EMifB; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si413875ilm.150.2021.05.19.12.29.01; Wed, 19 May 2021 12:29:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pR9EMifB; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350363AbhESLYM (ORCPT + 99 others); Wed, 19 May 2021 07:24:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:52810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241088AbhESLYG (ORCPT ); Wed, 19 May 2021 07:24:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B7B36135C; Wed, 19 May 2021 11:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621423366; bh=CK0UATbAPMGBHgoaDVlRXBZQWLHrCBzSLKEOlHdqK3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pR9EMifBdNm9VnjqseEQeyy7e7khDLujLSGYj3BEK7SJkZzal89ucJD79BFNPZ9fp mphW7fmgsPvK/4hxDyX+9Q4DlSiJAbAFfS65rAnJ3MmZpAFSmNLx3xrH7iRR5axCRh JcNaDRQ9Na30tdBacaP13rZKZ5FOWOZ1ry+y4293Ht87bRBHsi2OsByD7alJ+lxGrr 5OxqJlpY2wqdcRJQ1m5cMIlyQdpk7H3NjzLAZrvzg+OBrM0Jupj1m2hrhdqjst3O/4 pMamzajDD/dbExpcEFjDKFfT9ElzHvIA1vdkAQkH5uD0D8KA/LR+2senmfJhZp77FP cb9RpXZ2CXQkw== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, ebiggers@kernel.org, herbert@gondor.apana.org.au, will@kernel.org, kernel-team@android.com, Ard Biesheuvel Subject: [PATCH v4 1/7] crypto: skcipher - handle zero sized inputs correctly Date: Wed, 19 May 2021 13:22:33 +0200 Message-Id: <20210519112239.33664-2-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210519112239.33664-1-ardb@kernel.org> References: <20210519112239.33664-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org There are corner cases where skcipher_walk_aead_encrypt() may be invoked with a zero sized input, which is not rejected by the walker code, but results in the skcipher_walk structure to not be fully initialized. This will leave stale values in its page and buffer members, which will be subsequently passed to kfree() or free_page() by skcipher_walk_done(), resulting in a crash if those routines fail to identify them as in valid inputs. Fix this by setting page and buffer to NULL even if the size of the input is zero. Note that for AEAD encryption in particular, a zero sized input could be a valid and meaningful use of the API, given the support for associated authenticated data (AAD), which gets reflected in the authentication tag as well. For symmetry, apply the same fix to the plain skcipher walker code, even though in that case, no meaningful usage scenarios are known for zero sized inputs. Signed-off-by: Ard Biesheuvel --- crypto/skcipher.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/skcipher.c b/crypto/skcipher.c index a15376245416..ed2deb031742 100644 --- a/crypto/skcipher.c +++ b/crypto/skcipher.c @@ -455,6 +455,8 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk, walk->nbytes = 0; walk->iv = req->iv; walk->oiv = req->iv; + walk->buffer = NULL; + walk->page = NULL; if (unlikely(!walk->total)) return 0; @@ -511,6 +513,8 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk, walk->nbytes = 0; walk->iv = req->iv; walk->oiv = req->iv; + walk->buffer = NULL; + walk->page = NULL; if (unlikely(!walk->total)) return 0; -- 2.20.1