Received: by 10.213.65.68 with SMTP id h4csp720559imn; Tue, 13 Mar 2018 19:56:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELsIDHpvclwjWwHbO8Lu9dqINX6pdF4d5FxLnCuCgEmPb+MK/3EkwJ8dcTmTkHv6THKYsuMl X-Received: by 10.99.169.10 with SMTP id u10mr2335011pge.163.1520996212903; Tue, 13 Mar 2018 19:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520996212; cv=none; d=google.com; s=arc-20160816; b=MTNGdbAML2y0i5j9yPWadnX6UgBhoDi2SWXm/VchmWvH1BJ0RI5Eh/SBZfdnaUdqGr PAIM0Zg3ONLcVgTr1C0GfslkigKN4c2vYuYGQHaa8VUoVgjidSCtSB6ZFhnJITuLb6hm m8Uczd3jXq7wL6ANlj+ChO8ftOfW6eaFpeVJoisB4KS6EiEk9oX2f8Jc/yTiyfRy9eTb 0Rd7GfU7tEndEBxPvb5B8U6yKA4k7HKt6cVxHYpBrf3/Lj8xLaGFnyqmKwPAzR6Mw3nU N1mBWSi8aSDQp0Ommql4pS9t9gIFAreyEasDKo19iGEaiAd69Uw3Eft/6QfJGL+3Bjxu MGRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=qgI1v0OmCsdrT5/xwuHY6uOidJ1T6N6cbE5m/6zHJmc=; b=orLm0LXLAaiUq9BXzzwjVIY/1yA91X0dMrb8ziyy+KfNAt4/8+dFc+s7ZjZZgAy69m eLPi3nnEmVe8vCqW3XBs+GDrArtwvluo3vSWvM4iQKsmQb8TXNkLl+nZfW8+FckiGGpz LJW3XaQecdPuYR9c6RrTLdlAR0rk6yFGNgOYm8vv5mii+Lp3pCSN8tBWqWKaU43xxXVS MlnKpIVLWhj6vhBi1p4h62rsMpoB8Q8SzvQgXj7lZXxpkBMbC1ZcgwpTGnJNY7e+Kl9o ej3ZMrBCKgm9GKHJd0ap8WOIJdQMBs7TKvtLhQI7dbROS3pjFh4RyXPzunFZlYrOBMit WTyQ== 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 p184si1083392pga.700.2018.03.13.19.56.38; Tue, 13 Mar 2018 19:56:52 -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 S933234AbeCNCzh (ORCPT + 99 others); Tue, 13 Mar 2018 22:55:37 -0400 Received: from anchovy1.45ru.net.au ([203.30.46.145]:47512 "EHLO anchovy1.45ru.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932937AbeCNCzg (ORCPT ); Tue, 13 Mar 2018 22:55:36 -0400 Received: (qmail 10158 invoked by uid 5089); 14 Mar 2018 02:55:33 -0000 Received: by simscan 1.2.0 ppid: 10079, pid: 10080, t: 0.0513s scanners: regex: 1.2.0 attach: 1.2.0 clamav: 0.88.3/m:40/d:1950 Received: from unknown (HELO ?192.168.0.122?) (preid@electromag.com.au@203.59.235.95) by anchovy1.45ru.net.au with ESMTPA; 14 Mar 2018 02:55:33 -0000 Subject: Re: [PATCH 4/4] gpio: Remove VLA from stmpe driver To: Laura Abbott , Linus Walleij , Kees Cook , Patrice Chotard Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com References: <20180310001021.6437-1-labbott@redhat.com> <20180310001021.6437-5-labbott@redhat.com> <9175611d-049d-ec28-0716-e45fccfd579f@electromag.com.au> <4e64bbae-e91b-f0c5-ff79-3dde8fbe2119@redhat.com> From: Phil Reid Message-ID: <9ffedffb-5dd1-a67a-7266-eb480b07a384@electromag.com.au> Date: Wed, 14 Mar 2018 10:55:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-AU Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/03/2018 09:16, Laura Abbott wrote: > On 03/13/2018 05:18 PM, Laura Abbott wrote: >> On 03/13/2018 02:13 AM, Phil Reid wrote: >>> On 10/03/2018 08:10, Laura Abbott wrote: >>>> The new challenge is to remove VLAs from the kernel >>>> (see https://lkml.org/lkml/2018/3/7/621) >>>> >>>> This patch replaces a VLA with an appropriate call to kmalloc_array. >>>> >>>> Signed-off-by: Laura Abbott >>>> --- >>>>   drivers/gpio/gpio-stmpe.c | 7 ++++++- >>>>   1 file changed, 6 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c >>>> index f8d7d1cd8488..b7854850bcdb 100644 >>>> --- a/drivers/gpio/gpio-stmpe.c >>>> +++ b/drivers/gpio/gpio-stmpe.c >>>> @@ -369,10 +369,14 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev) >>>>       struct stmpe *stmpe = stmpe_gpio->stmpe; >>>>       u8 statmsbreg; >>>>       int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); >>>> -    u8 status[num_banks]; >>>> +    u8 *status; >>>>       int ret; >>>>       int i; >>>> +    status = kmalloc_array(num_banks, sizeof(*status), GFP_ATOMIC); >>>> +    if (!status) >>>> +        return IRQ_NONE; >>>> + >>>>       /* >>>>        * the stmpe_block_read() call below, imposes to set statmsbreg >>>>        * with the register located at the lowest address. As STMPE1600 >>>> @@ -424,6 +428,7 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev) >>>>           } >>>>       } >>>> +    kfree(status); >>>>       return IRQ_HANDLED; >>>>   } >>>> >>> >>> Doing this in an irq handler seems wrong. >>> Perhaps better if a buffer is pre-allocated in stmpe_gpio >> >> Sure, I can pre-allocate the buffer in the probe. > > Actually I wonder if there would be concurrency problems if we > tried to pre-allocate a global buffer. But the IRQ handler > calls stmpe_block_read which takes a mutex to sleep so I think > doing the (small) kmalloc should be fine and I can change it to > a GFP_KERNEL. > I'm no expert on this driver, but I wouldn't think there'd be any concurrency problem if the buffer is only used by the irq handler. It should never get called concurrently for the same device. As to the impact, I'll admit I've really got no idea how much potential overhead a kmalloc has compared to a mutex for the linux kernel. Just a general rule of thumb, that memory allocations are usually expensive. -- Regards Phil Reid