Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7192270imm; Tue, 24 Jul 2018 09:53:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeg1DLWlvxC3gtXB2dI9sVNeB0m3NhU7+/hVsx+AL4IXW/bOtDMEStjF6hfJfw2bLMUCTI3 X-Received: by 2002:a62:398c:: with SMTP id u12-v6mr18545477pfj.9.1532451229503; Tue, 24 Jul 2018 09:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451229; cv=none; d=google.com; s=arc-20160816; b=OetJhrRksu0pJn4MsLjZe+KcBzaQd7Opwd59HjmXroUW7zggL45qV0PK35vn5EP6RF z2dqyFjrFbFe2G6DBdLOyOCkhnukATJoV+6+bF6oKIYaB4Jnt9rfRzKw8IeDTDXjpaD6 wT8/AecWiWShiz75JuYJqnFxaT7KMjYd3vg3t5eSJiKGZB/G1tpdZm4woP84CN1AH5A+ OiesiZn9rx/NObe+7HDLZ56HJ15p1i/jPT9jHrszZ40JIkIjrZZ7rXYTBt+vYHDwaHAW Y22SwT+7WN+e6XvEREqQluyJ+SXsMnJ/Rz6rtORPOMgsPkSfI8X3YuYXzFV4m/MuY4A+ PVgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ZI2aob70T18+rSqCI2VmsibkGPFJ6uFylB1GNq8x2tU=; b=dXAjXqw/EBwvPXzLNviFXvp/Z04F7KgCMEpRhx7369SarnYZGPMhe7CINDtXwXK9pC E1B3SmXKjrHe4bvUsGkJtVOcfCMP0+3vMLIIS0dloe3JxTOF0SwtYfavqyZ5tEmAUQzX 53vFxINJ+VKrDUT5ZTZL1l8E6ryRMU84uX7ux7Ui6tkeWSv6nFYc90EnnyKQplHsjjJY DgrS0mTCqB3ru7qan9zutkOtNRiZbRmpN4gLZ/o4wTFcR8vpTu877DHZwg300dkuWwUQ drliAwbue4DahV6kEVNcwIcDekShwfFkbT/O+gNH6EY/oaTbzXLG+nXCXgybfuzB4k+N blmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lhaX8SZb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9-v6si12253576pfg.62.2018.07.24.09.53.34; Tue, 24 Jul 2018 09:53:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lhaX8SZb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388766AbeGXR6z (ORCPT + 99 others); Tue, 24 Jul 2018 13:58:55 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:43098 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388654AbeGXR5P (ORCPT ); Tue, 24 Jul 2018 13:57:15 -0400 Received: by mail-pl0-f67.google.com with SMTP id x6-v6so333575plv.10 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=bBKkbWWGMIwu3kpazmJkbdw6zU1g5ZqDioHCzgyT62G+FovDQXyqwL7ZBSbrTvFMjG cKZzSXAmXwnK3pmiHmF3a8BuQ8Mi4O10aVdwP/qQD42lNNVxL+AAorHGCZdIgKqk2Ta0 rN/OLM11G2Gin8wLtHKoZpjDxzzaHY9IeFFm0fJerUJNIWogADmRThw3EF5WGaAnaovv T7JVjYFcPVWWHYmowkzQU86IDJ7JIsHhQ2JqO2ptIhcHI8SaRIKfxolsQvNnSrhcuEU7 Kp3qvuog0oBBZ/yOJ8HbbffbZKreMNK8aSHDNp3IGVNcjPagooKwfYijQFC6gfFpKIut 7PxQ== X-Gm-Message-State: AOUpUlHyE9Cmt+qnHoiPtwbkyjXzMZK8d38a3IeYOEgzjwA5023jB54O m49sMGqCdCd9nz5jflrsDA3sZA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.17.1