EDAC, thunderx: Remove VLA usage
Subsystems (2)
PATCH 1/1 EDAC, thunderx: Remove VLA usage
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
--- drivers/edac/thunderx_edac.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/edac/thunderx_edac.c +9 -5
@@ -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;
Quoted 5 lines · Kees Cook
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.
Quoted 8 lines
[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
Cc David Daney <[email protected]>Cc Jan Glauber <[email protected]>Cc Borislav Petkov <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Kees Cook <[email protected]>
thanks,
Jan
Quoted 58 lines
--- drivers/edac/thunderx_edac.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/edac/thunderx_edac.c +9
-5@@ -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;Signature · 6 lines
2.17.1 -- Kees Cook Pixel Security
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Jan Glauber
Quoted 7 lines · Kees Cook
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
Quoted 8 lines
Quoted 6 lines
Cc David Daney <[email protected]>Cc Jan Glauber <[email protected]>Cc Borislav Petkov <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Kees Cook <[email protected]>Acked-by Jan Glauber <[email protected]>
Applied, thanks.