Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1165943imm; Wed, 1 Aug 2018 11:16:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeaUoJ/EVV0xN8RPHPdhgaTxNb4pBvS7RnHZwu6eXod2fg7ZwsmVGzFlz78+AwXtHvCKaJ7 X-Received: by 2002:a62:bd4:: with SMTP id 81-v6mr28069780pfl.67.1533147384984; Wed, 01 Aug 2018 11:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533147384; cv=none; d=google.com; s=arc-20160816; b=icLjs/7PFheVoiw/ig4EKfP3fNU+2ZwhSpBsBiRpNOHJxf2/0JrIDOqIM7OU7MxLMZ M0mI+OL8wn/E39CnoZJL65tq8Hapukt/UtwO046tcn6vpLioS7u6qVqoahufHUnkrQas qk/Fy8Cm6B5MPQ/an+LSeSgsFlXyYFMKTLl5HSlf91aSP9AWGJNicTBicOk2LuSIez5M EzmaQNAolvbkruVfu95vKW/NxK0GnhfhFit7GvvNlgVeUt7nwLKciGEdsg5Q8nHmaVRf f5ZQyw7YKjaYGFne4ltlZeM4sATfr9l38ODaY24/taEUkKnObwqPZKchJjeE5dykeQ2O NFYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JZf+3Wa8DA9Ga8arQpixrl91RRiDnk8AusMpZqx/Z8g=; b=DrdD5XlnxQrnCUsDyz73XUccdxA2EYMHhrc5VDSTqmA2aSEWB+/FLWgAX8m+eMz18K vnh60wMjRY+ncXj+QwbyGyTayx2zVpmrCOp0jUeLKvL5CzhiPXyYgXKoavmkdjhA+VRv 5wWGNrzBylQOHIvzxNTG3g/+l2w7B0NiZNnRl1HOGFn429Ez/TFnaDB5LTZP3tA/cPYL +Xk4eBTbABcHK3y6xqV8NPCr1RkIM4gBigNzbWawMRfNh6RCcQsrpZY+a+AJRfL0Kqoc 0RORJffBANT9FypOQPbfPNPHKx5E6lFuaK5I1PC0fkBV+ruexLO36Jz0EbfP6K9xGpMw e98w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b28-v6si17749732pfe.265.2018.08.01.11.16.10; Wed, 01 Aug 2018 11:16:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405421AbeHATHL (ORCPT + 99 others); Wed, 1 Aug 2018 15:07:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49134 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404974AbeHATHK (ORCPT ); Wed, 1 Aug 2018 15:07:10 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7667FD00; Wed, 1 Aug 2018 17:20:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Tobin C. Harding" , Ulf Hansson , Sasha Levin Subject: [PATCH 4.14 174/246] mmc: pwrseq: Use kmalloc_array instead of stack VLA Date: Wed, 1 Aug 2018 18:51:24 +0200 Message-Id: <20180801165020.060774270@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Tobin C. Harding" [ Upstream commit 486e6661367b40f927aadbed73237693396cbf94 ] The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug (kernel Oops) or a security flaw (overwriting memory beyond the stack). Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug. As part of the directive[1] to remove all VLAs from the kernel, and build with -Wvla. Currently driver is using a VLA declared using the number of descriptors. This array is used to store integer values and is later used as an argument to `gpiod_set_array_value_cansleep()` This can be avoided by using `kmalloc_array()` to allocate memory for the array of integer values. Memory is free'd before return from function. >From the code it appears that it is safe to sleep so we can use GFP_KERNEL (based _cansleep() suffix of function `gpiod_set_array_value_cansleep()`. It can be expected that this patch will result in a small increase in overhead due to the use of `kmalloc_array()` [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Tobin C. Harding Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/pwrseq_simple.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/drivers/mmc/core/pwrseq_simple.c +++ b/drivers/mmc/core/pwrseq_simple.c @@ -40,14 +40,18 @@ static void mmc_pwrseq_simple_set_gpios_ struct gpio_descs *reset_gpios = pwrseq->reset_gpios; if (!IS_ERR(reset_gpios)) { - int i; - int values[reset_gpios->ndescs]; + int i, *values; + int nvalues = reset_gpios->ndescs; - for (i = 0; i < reset_gpios->ndescs; i++) + values = kmalloc_array(nvalues, sizeof(int), GFP_KERNEL); + if (!values) + return; + + for (i = 0; i < nvalues; i++) values[i] = value; - gpiod_set_array_value_cansleep( - reset_gpios->ndescs, reset_gpios->desc, values); + gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, values); + kfree(values); } }