From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 874A3C433B4 for ; Wed, 19 May 2021 12:51:57 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A02860FD9 for ; Wed, 19 May 2021 12:51:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A02860FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=s8dQSB7SN5nQJVcS/qVlq/p/22EAnVDoB0UscC58784=; b=CUnqRKUP45Lv4XFZcLXDYg8ZM L9Xa0/T7f0GO3sNyuwZStHXB8QFehG1+KopG7Nv8DON7xQTq4Cli+Pkm3UpnHVPcJ6yZWhCXG4Zvu f/8VU8eGDo4XC9LfdcAy6pSVx5VrsGcbaqzQyxRGuVGrXikOD4Gd/YGuM42TOscZpYUrMsLIa8R2r FqsZLXLT9LKUB9+c2dFwqxwjfpguzrquZpJ23oOJ27ReNTLsu8pU9mNbVvWTf3Gmkm7y79rmsoP+j p9mIDHr6jVWoat6/GCytXoGywlqaTJEHjPfUkOoB+ffyOQ8+vBkKSCAPE/oFozTdGVNUAVkskth0W TzeweD27Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljLeZ-003y5W-PW; Wed, 19 May 2021 12:50:24 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljKHp-003kic-G0 for linux-arm-kernel@desiato.infradead.org; Wed, 19 May 2021 11:22:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=k0JpRrbA7Yx9nmrJVdnz1BzOUwNVkq/EHJEwhEZ2UO4=; b=ywQ86rlsK4dyCOKYsRMBDmF7eH capvPmYA9/BRI1OJzpjwCiPNfJmfN08Mm8JrD/ebMEHcMbLlPoQNjq2ii7m/bmXyQ0sZJL0jBvAe6 fQM5zIF/AfF2lVCt+0PB28Hs1lGbjJC+e6mLCAHVzvoYdyHG8YMafqWwJk2fYUYJTjyussM4rONyq rDuvNtDN3SnJtF1Ksp+xmA3DNioWXLHeppyexKBJVBWcP++BsoJ67jeD62S48ie/7WpQ6Y1tI47Ff Ij3NPK6YmYtgIAq2KLGUY2h+UDg9SunUZF4Pe+ugVyUk3Nj9ELG+68HdNFI7+5qw9IzqVKrwCtws6 lMVorEfw==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljKHm-00FP0b-Tx for linux-arm-kernel@lists.infradead.org; Wed, 19 May 2021 11:22:48 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210519_042247_005254_AFBEA8D4 X-CRM114-Status: GOOD ( 12.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel