From patchwork Tue Jul 24 16:49:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10542505 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E7FA112E for ; Tue, 24 Jul 2018 16:49:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EA0029063 for ; Tue, 24 Jul 2018 16:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 124FB29097; Tue, 24 Jul 2018 16:49:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44C7829096 for ; Tue, 24 Jul 2018 16:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388669AbeGXR5P (ORCPT ); Tue, 24 Jul 2018 13:57:15 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:32896 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388598AbeGXR5O (ORCPT ); Tue, 24 Jul 2018 13:57:14 -0400 Received: by mail-pl0-f65.google.com with SMTP id 6-v6so2030667plb.0 for ; Tue, 24 Jul 2018 09:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZI2aob70T18+rSqCI2VmsibkGPFJ6uFylB1GNq8x2tU=; b=lhaX8SZbZjzXrl4urHtWAlOw0+5v2jhpiueRSlwInGEIhtnoWEcHkEo2Rti0au0kTK cyoLrc1bLLVPJzhNPhaWg6wGX2PhkP0GsTsho7i9AdEKJ58RD3bnmHsEP+YDd8PDv2qc cWo7fpA1R05gIRDrThrywOkzK8sPxhD1/Sz/4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZI2aob70T18+rSqCI2VmsibkGPFJ6uFylB1GNq8x2tU=; b=fXi6rXEHoUtoWVcFXMxAq68bHkwO1wwVUn8cYzRB7Pguzab8blpfHLswtgSaZVoS/1 3uqJqhzt8Qq0JZgeaVgg4+lf4XFwEB4EsQ60w8B9xcrUcx7uhnKBJ3ZHrAYXmYrkH8HM gVGplleQ7ngq5YmebW+cYTV2LbM/aREklVEJruKEWQFRZvLhotkMwtEQoLWBS3Q53F8j NoxdVZT9QgfscVr/V5CWMLBHzmTGPLgt1XivOkoOnv84d3RtovzJv19/NIMaZa7lMbv9 YMNq+P1fnGslATzV/8bMblXxPfKqzrp3M2nvRAFxU27Kb6x2qs8NL8zikNhA+t7N+PGi 70/A== X-Gm-Message-State: AOUpUlGV8MZv+LleSE/M7X8anWBvY3UKAdPm0txA1GcR93wrWigrr4Ka w7WwadDyAvTEJ9CEbQ9QQgnHIg== X-Google-Smtp-Source: AAOMgpdDfbfeNYrD5Tke9cwk7/M0KCext81YN1e+mYrixCTTS8+Y3+j2yYZwLCcAE6lQGskPdc0BMA== X-Received: by 2002:a17:902:8506:: with SMTP id bj6-v6mr17572390plb.210.1532450993856; Tue, 24 Jul 2018 09:49:53 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id d18-v6sm13530804pgo.74.2018.07.24.09.49.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:47 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Rabin Vincent , Tim Chen , "Rafael J. Wysocki" , Pavel Machek , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Philipp Reisner , Lars Ellenberg , Jens Axboe , Giovanni Cabiddu , Mike Snitzer , Paul Mackerras , Greg Kroah-Hartman , David Howells , Johannes Berg , Tudor-Dan Ambarus , Jia-Ju Bai , Andrew Morton , Geert Uytterhoeven , Josh Poimboeuf , David Woodhouse , Will Deacon , dm-devel@redhat.com, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, qat-linux@intel.com, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 10/18] x86/power/64: Remove VLA usage Date: Tue, 24 Jul 2018 09:49:28 -0700 Message-Id: <20180724164936.37477-11-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724164936.37477-1-keescook@chromium.org> References: <20180724164936.37477-1-keescook@chromium.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the quest to remove all stack VLA usage from the kernel[1], this removes the discouraged use of AHASH_REQUEST_ON_STACK by switching to shash directly and allocating the descriptor in heap memory (which should be fine: the tfm has already been allocated there too). [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook Acked-by: Pavel Machek --- arch/x86/power/hibernate_64.c | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c index 67ccf64c8bd8..f8e3b668d20b 100644 --- a/arch/x86/power/hibernate_64.c +++ b/arch/x86/power/hibernate_64.c @@ -233,29 +233,35 @@ struct restore_data_record { */ static int get_e820_md5(struct e820_table *table, void *buf) { - struct scatterlist sg; - struct crypto_ahash *tfm; + struct crypto_shash *tfm; + struct shash_desc *desc; int size; int ret = 0; - tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC); + tfm = crypto_alloc_shash("md5", 0, 0); if (IS_ERR(tfm)) return -ENOMEM; - { - AHASH_REQUEST_ON_STACK(req, tfm); - size = offsetof(struct e820_table, entries) + sizeof(struct e820_entry) * table->nr_entries; - ahash_request_set_tfm(req, tfm); - sg_init_one(&sg, (u8 *)table, size); - ahash_request_set_callback(req, 0, NULL, NULL); - ahash_request_set_crypt(req, &sg, buf, size); - - if (crypto_ahash_digest(req)) - ret = -EINVAL; - ahash_request_zero(req); + desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm), + GFP_KERNEL); + if (!desc) { + ret = -ENOMEM; + goto free_tfm; } - crypto_free_ahash(tfm); + desc->tfm = tfm; + desc->flags = 0; + + size = offsetof(struct e820_table, entries) + + sizeof(struct e820_entry) * table->nr_entries; + + if (crypto_shash_digest(desc, (u8 *)table, size, buf)) + ret = -EINVAL; + + kzfree(desc); + +free_tfm: + crypto_free_shash(tfm); return ret; }