Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1132638imm; Fri, 29 Jun 2018 11:59:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfbYoXWqFCmtnAkoEDXs13JcHD7Ej0jhCDJUIa7OWSSR6Rgk3+9bQXkqSFMHq1sJnEbMSel X-Received: by 2002:a62:494f:: with SMTP id w76-v6mr15630385pfa.152.1530298778653; Fri, 29 Jun 2018 11:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530298778; cv=none; d=google.com; s=arc-20160816; b=AoQxE9yRmL7ra1R3h+UIZCbMNkeho/THzXDOCvGrYnxCNHB04oeBNK30uOp9xbXPvH h/0V6kSiVwEXTSuhcsKsg16q2snW/ddvdKWwR5eLLeQz1EHy3VNut1SOytyc4pYb3RWT nPtycdf7Xz/QntVgLSjuB5XVZb1T6gExYZ/Pd0/+YTzAz7Q+LUwsBcrJjhWYyI8OP37e JA6PzwcaeIT+xqgReEzHClKl5TYsPBYpNJBuyJWlOkIIQKHH/YDaWHkFkDyj6osxQI0i ZlDGFczIrdB++YUd+VZCI3LGMkil9CLdGRU9zilyq6X7XKO7z2mTxVuz8ad6BYbeHkTt 0Bhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=9JSsLFN7pKBad8rj/9rpVXN9GZ6bOBjPe/JLuyiijzg=; b=c0X+X6c+S/HM0KjCDCHCrsvEh6UT3Ek8jhvuD0n2MU/5sdZPUshcWDFtfrJu00VxSl ZupvpoRlsdOAM+zWkZgermXirl8+sJ880JfwC6c8jm2vLO+Ki3l90jr0l4UFEoySaA8U sis6USUCmWpQs5ZyUOK8sS5FLgxFLVINms0xc37K190fX+9X7DaYTdmHg4JCJh3elSI/ UB36xRcBYdBPxjsAyGc93gMXDFHtIjkcgJLcIa7wEAapYVLK0hYrXm0fTtDDWopJx2w6 N4gghzywY3QhERm+UpGiaxx8shb6h8KWAdgLcyxqAlWjD/ATDWFZfZNsoOuoX7BDLq5X wuFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YAUq8kbh; 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 r69-v6si1125683pfl.260.2018.06.29.11.59.24; Fri, 29 Jun 2018 11:59:38 -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=YAUq8kbh; 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 S936558AbeF2Ssz (ORCPT + 99 others); Fri, 29 Jun 2018 14:48:55 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:33239 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933723AbeF2Ssw (ORCPT ); Fri, 29 Jun 2018 14:48:52 -0400 Received: by mail-pl0-f67.google.com with SMTP id 6-v6so4873406plb.0 for ; Fri, 29 Jun 2018 11:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=9JSsLFN7pKBad8rj/9rpVXN9GZ6bOBjPe/JLuyiijzg=; b=YAUq8kbhttQry2lNA2SPwPbF+/Q6RNairzvOQfEQFe5hwBkKNbc7IuzdpHpnNCiVuL gxxIDKHkszGiJGKkGnwSv2Dd4+qeWWnjri6psCiDjTrKsxrVgMJU+m3y6qcgOrmItXdE YZN1TSE9Yve1g+ebhvEVPbNHrQiwyS+Pxx9fM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=9JSsLFN7pKBad8rj/9rpVXN9GZ6bOBjPe/JLuyiijzg=; b=km7WkvaE1mQiCTBQgx2eai30JSYZOWAuB3UUG3IkUZQMFyXMXxi7SJfhYodZRrQC4G 3YabmWh+301zINQzDEJEfp6i60rTel/p4zaapSK2UPO1ATB1smtEhHx3ZQ66ChbjzaGQ pRNHI/gZLfbLx4z1GwkOfv1wCSUxreesYbOni8atPaJ5kawI+/JWepJpyd2GOBMH3lXP 33t630gENlXk4Wtb+L90lAltmU7/WdA87f/cCRH8OgGQKQkG2JjfvkV5AL2120qp9auV tFrglTCvdPTNDAvjqOnMGSwd/9Q0NvjZNDYTaBXM7GXCUyoPVBtvTW4GRXxPBDPLGyMt 9yXA== X-Gm-Message-State: APt69E1dlnMot6+OMI89APQoe+oj7JIUqWATfix0bcaJzmwFmAWbkgwp rGk5fLu0od2qZAH9172E7TpuHQ== X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr14845806plb.297.1530298132151; Fri, 29 Jun 2018 11:48:52 -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 h13-v6sm14646427pgp.13.2018.06.29.11.48.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jun 2018 11:48:51 -0700 (PDT) Date: Fri, 29 Jun 2018 11:48:50 -0700 From: Kees Cook To: David Daney Cc: Jan Glauber , Borislav Petkov , Mauro Carvalho Chehab , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] EDAC, thunderx: Remove VLA usage Message-ID: <20180629184850.GA37464@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 --- 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