Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1679654imm; Fri, 6 Jul 2018 04:43:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpchvtYQaHR9feMpJMzPjMAPFaNpaKkf19iKgpKngY2sf2/I/W0Asl4xvDV4HRO+Ku7SWmYd X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr9797246pln.197.1530877393799; Fri, 06 Jul 2018 04:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530877393; cv=none; d=google.com; s=arc-20160816; b=PnOMdzAMXKfwhqzdY132VOdd3hj8O1BNr+i4Ma8fQnaBwLXzCn24/t7EcoOQOO/4Wn LbI6rM3bOFvgBIXA2cLFXDnSvweY7BaEcTOl0vHUoCldTa+pQ7EgIy9kiiY7pcM/JWCQ r53ZvY5LD5HaK17dcEIDKwDYVTuWAEckKX3TMYW2ra338HNxM11VC2kVH4woi//3G4Si bTclqLQLNukYmYjTVk7htBw/MwGaapEQRDamvvZ3zTa089puzVq94aJJin1oVilD1Y7E j7t9DXCpdgVQltJBxDUTxhsASHWc2T4Tts+erCZSxH1XQXLEd+2SqkUDoEJYrwSvr2hO NApw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature:arc-authentication-results; bh=BxTBb1dOk8aT5MZMFGJakb+Gi/SKyYeUKHIP0onHjU4=; b=e50zI8cYo4sZEZeeEiVjxBsJZhkaGqO/ggVH3ad3nOr4OnHCAxcs9bA/J9OxtFrRsX BEKg99CrY8feHMZ5IyBicKhoBsST+/5gGra4EZAgeXTrA9cPr5Uow6Xic4deIOw2FApR CtZfLjm7UyuQPuA4x2zd6CSZXpxGXVdp6an+fwfz5tkWK5MKui3nvU4G1QKxaz61rGaN DzqklIDdluB+0hYdQibBHvXI3ecGa+4KZzyB3fOs6qKDtFmsoSLOhaZaaRQKwjBr5HQF CDpp4BNoipRAOeoU4q34HIzkobBvSpFqP85ZfRrz+1zNsLYU7zSB/GmJB5S0dvqGtEg5 kkAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=soqwDxas; 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 o6-v6si7933925plh.158.2018.07.06.04.42.58; Fri, 06 Jul 2018 04:43:13 -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=fail header.i=@gmail.com header.s=20161025 header.b=soqwDxas; 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 S932681AbeGFLmV (ORCPT + 99 others); Fri, 6 Jul 2018 07:42:21 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:55904 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932325AbeGFLmU (ORCPT ); Fri, 6 Jul 2018 07:42:20 -0400 Received: by mail-wm0-f66.google.com with SMTP id v16-v6so14609622wmv.5; Fri, 06 Jul 2018 04:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BxTBb1dOk8aT5MZMFGJakb+Gi/SKyYeUKHIP0onHjU4=; b=soqwDxasWDVUlye/9XEu+t2+uGVsYvJeV96Q8LJwwwHknmhDxz03OoPKfH/czKfPZ/ 6zJpMn9+VQTpxnu3TMyhJ2kKSYx6d/Ym0onPZLD9YBYFYmUuT6mhPh8F3CF3/OMe0wLj sQGLCp8lA88m/eodDuVbRrgONAxvS6WCfVS89w7yNq8/eiJ8gAnGXnumwprR/lpVO8XS hBlCI3+44m4P/YGhR2FlKnu4qfRbRe1B5efQKMKwbU4xFrM+Sd2JwwMvISiP6pwiQnW6 Vee3XF2TibK8sK5oM0lNbd0eP8SATGV4kXZ7Ov1oGwdH1y1iFMd340DxK6Gk3ByNHsTZ 4GSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=BxTBb1dOk8aT5MZMFGJakb+Gi/SKyYeUKHIP0onHjU4=; b=Zhvkr93lO2CIM5RV27F+ktRTjMR+xItmS4de8AxSWvNv+QU/EpccPbPoJuLn3Oz8Lx YgI5VUJxp+1QJTPe1T+Z63PGpm9FSc7KJUDNgJgs6W2EyRHi0jYJ13xACQ0ZmlofU2mA 3+VjZvisV6fUz/rLWRoO3YQTJrFWFyxcQvNYV5937WaB9Dl8Ti9+MKv54hHs4ud30Q4q 4FM898NcD+fq1pOJyGmc3PflypEnS/aSRzeO5tMwXgvgSODsrGyZnrYNSKB3Z+Qybzu1 nk0q4lWmPshbd666GNn3RpmXIqJWvsABgyfsBMIfI/MShb1T+ayvvLHk3PI8cj5XDq98 Rvpw== X-Gm-Message-State: APt69E3F4qxErozTZ8A6ukoeK6wkM6vjuAk1XNnJwhQXC0zuL5GlwB5V /r5CeaAAvCakbREJiTUpyhQ+2k3l X-Received: by 2002:a1c:1748:: with SMTP id 69-v6mr754999wmx.75.1530877338672; Fri, 06 Jul 2018 04:42:18 -0700 (PDT) Received: from wintermute (HSI-KBW-078-043-112-026.hsi4.kabel-badenwuerttemberg.de. [78.43.112.26]) by smtp.gmail.com with ESMTPSA id e12-v6sm5913588wrn.34.2018.07.06.04.42.17 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Jul 2018 04:42:17 -0700 (PDT) From: Jan Glauber X-Google-Original-From: Jan Glauber Date: Fri, 6 Jul 2018 13:42:16 +0200 To: Kees Cook Cc: Borislav Petkov , Mauro Carvalho Chehab , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] EDAC, thunderx: Remove VLA usage Message-ID: <20180706114216.GA31180@wintermute> References: <20180629184850.GA37464@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180629184850.GA37464@beast> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 29, 2018 at 11:48:50AM -0700, Kees Cook wrote: > In the quest to remove all stack VLA usage from the kernel[1], this > switches to using a kmalloc-allocated buffer instead of stack space. > This should be fine since the existing routine is allocating memory > too. > > [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > > Cc: David Daney > Cc: Jan Glauber > Cc: Borislav Petkov > Cc: Mauro Carvalho Chehab > Cc: linux-edac@vger.kernel.org > Signed-off-by: Kees Cook Acked-by: Jan Glauber thanks, Jan > --- > drivers/edac/thunderx_edac.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/edac/thunderx_edac.c b/drivers/edac/thunderx_edac.c > index 4803c6468bab..c009d94f40c5 100644 > --- a/drivers/edac/thunderx_edac.c > +++ b/drivers/edac/thunderx_edac.c > @@ -408,26 +408,29 @@ static ssize_t thunderx_lmc_inject_ecc_write(struct file *file, > size_t count, loff_t *ppos) > { > struct thunderx_lmc *lmc = file->private_data; > - > unsigned int cline_size = cache_line_size(); > - > - u8 tmp[cline_size]; > + u8 *tmp; > void __iomem *addr; > unsigned int offs, timeout = 100000; > > atomic_set(&lmc->ecc_int, 0); > > lmc->mem = alloc_pages_node(lmc->node, GFP_KERNEL, 0); > - > if (!lmc->mem) > return -ENOMEM; > > + tmp = kmalloc(cline_size, GFP_KERNEL); > + if (!tmp) { > + __free_pages(lmc->mem, 0); > + return -ENOMEM; > + } > + > addr = page_address(lmc->mem); > > while (!atomic_read(&lmc->ecc_int) && timeout--) { > stop_machine(inject_ecc_fn, lmc, NULL); > > - for (offs = 0; offs < PAGE_SIZE; offs += sizeof(tmp)) { > + for (offs = 0; offs < PAGE_SIZE; offs += cline_size) { > /* > * Do a load from the previously rigged location > * This should generate an error interrupt. > @@ -437,6 +440,7 @@ static ssize_t thunderx_lmc_inject_ecc_write(struct file *file, > } > } > > + kfree(tmp); > __free_pages(lmc->mem, 0); > > return count; > -- > 2.17.1 > > > -- > Kees Cook > Pixel Security