From: Jan Glauber <jglauber@cavium.com>
To: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@alien8.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: EDAC, thunderx: Remove VLA usage
Date: Fri, 6 Jul 2018 13:42:16 +0200 [thread overview]
Message-ID: <20180706114216.GA31180@wintermute> (raw)
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 <david.daney@cavium.com>
> Cc: Jan Glauber <jglauber@cavium.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: linux-edac@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Jan Glauber <jglauber@cavium.com>
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
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Jan Glauber <jglauber@cavium.com>
To: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@alien8.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] EDAC, thunderx: Remove VLA usage
Date: Fri, 6 Jul 2018 13:42:16 +0200 [thread overview]
Message-ID: <20180706114216.GA31180@wintermute> (raw)
In-Reply-To: <20180629184850.GA37464@beast>
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 <david.daney@cavium.com>
> Cc: Jan Glauber <jglauber@cavium.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: linux-edac@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Jan Glauber <jglauber@cavium.com>
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
next reply other threads:[~2018-07-06 11:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-06 11:42 Jan Glauber [this message]
2018-07-06 11:42 ` [PATCH] EDAC, thunderx: Remove VLA usage Jan Glauber
-- strict thread matches above, loose matches on Subject: below --
2018-07-09 9:38 Borislav Petkov
2018-07-09 9:38 ` [PATCH] " Borislav Petkov
2018-06-29 18:48 Kees Cook
2018-06-29 18:48 ` [PATCH] " Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180706114216.GA31180@wintermute \
--to=jglauber@cavium.com \
--cc=bp@alien8.de \
--cc=keescook@chromium.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.