Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp632825pxm; Fri, 25 Feb 2022 15:44:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSkD1IwJIztCBvbSfVjz4lCZNM1h4pJAwPIposE9wonLQyST7cd3IlH2p5YUej9cwTOcsF X-Received: by 2002:a17:906:27db:b0:6ce:6f8:d0e3 with SMTP id k27-20020a17090627db00b006ce06f8d0e3mr7962317ejc.455.1645832683832; Fri, 25 Feb 2022 15:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645832683; cv=none; d=google.com; s=arc-20160816; b=qTY4sq1WY7brkxzS3p89clK81ehtFy6HP6AtQguCBAcXJ27SZncfeU8nlprs49KYWO vZKEhfoL+Jfr9t/2fFb3eXNLf/TvLA0wnnApG0FSMNnrI7S8rw17VcPuJy5it/26AwKB xkjo1hXjCJW9Z9Q0CNux4V4udKd3zVFb6jaJF3kNbwAoprsLEVmn2fvzotXzB8+Qmkzi XxSYvy+vmTzYr7IwxeAHRRuRYzSyA2OgTbBouzA9T1KwL6s3Ud+iW5h3KcakhIsH6Neg XNU8C3OHs4l8UEyM6D+eOXy2vnCQfm/Ivui+R3CNHRow4EL+mQRRoItVKI2ykycB/XvZ 2lrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QcmRgDWTrgD77TzWpSEPODR7wlYhwcC2QdFY3o+pCKc=; b=Dmq5rLAsHptfv/B6/o5eKl/xrp12c1/5B8B0XjtBRS341yr2VX0plv7GlHMKp0cR5S 3jQoYxUY4gvgUSNimrbm8baD8YUYWD1RSCyp4Sb53rdaH9y3bbn7sCEeMags+mGgOlrp WxMNFnebyW3tFVHQMr/O0V7o+8apqGLcnAI9m+E49mcQSXJ5ujHp52A1lV8vxYbYchJ9 8pbz2QN8roCaKVc4qTs5uBjnfs5nCAf8z25Hr9oFLNgxGcPhQwFlXIH1Y+X28hi1sunh at+u9aoWVnT5zmQkEKunJKkPyz/v5zVARcQPVhEyCWSsFzf1/SdM4p7B4Dq0bzXcwPVq jzgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o274dGRV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a05640205d100b00410f20467d3si2334783edx.131.2022.02.25.15.44.15; Fri, 25 Feb 2022 15:44:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o274dGRV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S236369AbiBYUUC (ORCPT + 99 others); Fri, 25 Feb 2022 15:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbiBYUUA (ORCPT ); Fri, 25 Feb 2022 15:20:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E911DAC7F; Fri, 25 Feb 2022 12:19:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6463F618C7; Fri, 25 Feb 2022 20:19:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CEB6C340E7; Fri, 25 Feb 2022 20:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645820365; bh=fbarxrQUlsGe8CHhhQ16VAA753AXYK0Ur+BWrj3mZkE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o274dGRVGX/tJ1WwuE2TkQfm7QzqdhkLhorTR7EB994GBGz0wFONL4gtzbY6qjLLQ s5txAR554G8DMgeCqOG8eRI+w2sTXZTm550FIy1nscfmx0f0ZDpb0NK6+DxjRvAmZW h6HT/5G55SYCPa+aSM6XxPTTqyOdlT6g+dSfK2CstoiHNu8aCUZ4WALuLiHBGIVqEK sIEc6tRoUFSeJ6OKQHvQ3CdlvsDTaftxGgvOwmk1vUauEZ9xMYptl2P9VtI9sL+WMa h6FqDJsqiH7eJfHB5xIGdBOQILQTKdJrp58O3M/S1LSVZSUkb9ULn6V+QNcfR7ZRiA 13fkzGrlUmMpA== Date: Fri, 25 Feb 2022 12:19:24 -0800 From: Eric Biggers To: Jia-Ju Bai Cc: herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] crypto: drbg: check the return value of crypto_shash_init() Message-ID: References: <20220225074623.17276-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220225074623.17276-1-baijiaju1990@gmail.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 24, 2022 at 11:46:23PM -0800, Jia-Ju Bai wrote: > Then function crypto_shash_init() in drbg_kcapi_hash() can fail, but > there is no check of its return value. To fix this bug, its return value > should be checked with new error handling code. > > Fixes: 541af946fe13 ("crypto: drbg - SP800-90A Deterministic Random Bit Generator") > Reported-by: TOTE Robot > Signed-off-by: Jia-Ju Bai > --- > crypto/drbg.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/crypto/drbg.c b/crypto/drbg.c > index 177983b6ae38..51feb9538701 100644 > --- a/crypto/drbg.c > +++ b/crypto/drbg.c > @@ -1725,8 +1725,11 @@ static int drbg_kcapi_hash(struct drbg_state *drbg, unsigned char *outval, > { > struct sdesc *sdesc = (struct sdesc *)drbg->priv_data; > struct drbg_string *input = NULL; > + int ret = 0; > > - crypto_shash_init(&sdesc->shash); > + ret = crypto_shash_init(&sdesc->shash); > + if (ret) > + return ret; > list_for_each_entry(input, in, list) > crypto_shash_update(&sdesc->shash, input->buf, input->len); > return crypto_shash_final(&sdesc->shash, outval); What about the call to crypto_shash_update() right below it? - Eric