From patchwork Fri Oct 9 10:41:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 7360711 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6C76B9F1D5 for ; Fri, 9 Oct 2015 10:41:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 844D020855 for ; Fri, 9 Oct 2015 10:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78F0F2055D for ; Fri, 9 Oct 2015 10:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754224AbbJIKlQ (ORCPT ); Fri, 9 Oct 2015 06:41:16 -0400 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:50088 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbbJIKlQ (ORCPT ); Fri, 9 Oct 2015 06:41:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=sHklXnIMZ2+OzbxCUQxxi75ouUendT15CIRoIUnHoMI=; b=jMZXc+lp4sa1A7Uh6XkaAa+/uDdi7391tUm5gLRa8kaFZGDpLGU3as/J9jJUN6YcTeWrrWCxHRU23tZFwhfrpbIXyyJjoohNMG4YahEPWLJlUsEt+OxvFa8MxaTrzkyqSapOsBFSIlKV7GKp/KVsJfqtd/1Q56CTepLf7EjZXcg=; Received: from n2100.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:40589) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1ZkV6t-0004rN-P2; Fri, 09 Oct 2015 11:41:11 +0100 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1ZkV6q-0004pw-A4; Fri, 09 Oct 2015 11:41:08 +0100 Date: Fri, 9 Oct 2015 11:41:07 +0100 From: Russell King - ARM Linux To: Herbert Xu Cc: Thomas Petazzoni , "David S. Miller" , linux-crypto@vger.kernel.org Subject: Re: [PATCH 1/3] crypto: ensure algif_hash does not pass a zero-sized state Message-ID: <20151009104106.GM32532@n2100.arm.linux.org.uk> References: <20151009102904.GL32532@n2100.arm.linux.org.uk> <20151009103428.GA1410@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151009103428.GA1410@gondor.apana.org.au> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Oct 09, 2015 at 06:34:28PM +0800, Herbert Xu wrote: > On Fri, Oct 09, 2015 at 11:29:44AM +0100, Russell King wrote: > > If the algorithm passed a zero statesize, do not pass a valid pointer > > into the export/import functions. Passing a valid pointer covers up > > bugs in driver code which then go on to smash the kernel stack. > > Instead, pass NULL, which will cause any attempt to write to the > > pointer to fail. > > > > Signed-off-by: Russell King > > The state size should never be zero for a hash algorithm. Having > a zero state means that the hash output must always be identical. > Such an algorithm would be quite useless. > > So how about adding a check upon hash registration to verify that > the state size is greater than zero? The place to do it would be > shash_prepare_alg and ahash_prepare_alg. Do you mean something like this? As statesize is an unsigned int, testing for zero should be sufficient. diff --git a/crypto/ahash.c b/crypto/ahash.c index 8acb886032ae..9c1dc8d6106a 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -544,7 +544,8 @@ static int ahash_prepare_alg(struct ahash_alg *alg) struct crypto_alg *base = &alg->halg.base; if (alg->halg.digestsize > PAGE_SIZE / 8 || - alg->halg.statesize > PAGE_SIZE / 8) + alg->halg.statesize > PAGE_SIZE / 8 || + alg->halg.statesize == 0) return -EINVAL; base->cra_type = &crypto_ahash_type; diff --git a/crypto/shash.c b/crypto/shash.c index ecb1e3d39bf0..ab3384b38542 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -585,7 +585,8 @@ static int shash_prepare_alg(struct shash_alg *alg) if (alg->digestsize > PAGE_SIZE / 8 || alg->descsize > PAGE_SIZE / 8 || - alg->statesize > PAGE_SIZE / 8) + alg->statesize > PAGE_SIZE / 8 || + alg->statesize == 0) return -EINVAL; base->cra_type = &crypto_shash_type;