Skip to content

Commit

Permalink
EDAC, thunderx: Remove VLA usage
Browse files Browse the repository at this point in the history
In the quest to remove all stack VLA usage from the kernel[1], switch to
using a kmalloc-allocated buffer instead of stack space. This should be
fine since the existing routine is allocating memory too.

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Jan Glauber <jglauber@cavium.com>
Cc: David Daney <david.daney@cavium.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/20180629184850.GA37464@beast
Link: https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com [1]
Signed-off-by: Borislav Petkov <bp@suse.de>
  • Loading branch information
Kees Cook authored and Borislav Petkov committed Jul 9, 2018
1 parent 6c974d4 commit 6663484
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions drivers/edac/thunderx_edac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -437,6 +440,7 @@ static ssize_t thunderx_lmc_inject_ecc_write(struct file *file,
}
}

kfree(tmp);
__free_pages(lmc->mem, 0);

return count;
Expand Down

0 comments on commit 6663484

Please sign in to comment.