* [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two.
@ 2012-10-19 11:59 Florian Fainelli
2012-10-19 16:03 ` Kees Cook
2012-10-22 9:19 ` [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0) Florian Fainelli
0 siblings, 2 replies; 6+ messages in thread
From: Florian Fainelli @ 2012-10-19 11:59 UTC (permalink / raw)
To: cbouatmailru
Cc: ccross, keescook, tony.luck, linux-kernel, Maxime Bizon,
Florian Fainelli, stable
From: Maxime Bizon <mbizon@freebox.fr>
record_size / console_size / ftrace_size can be 0 (this is how you
disable the feature), but rounddown_pow_of_two(0) is undefined. This problem
has been present since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
CC: stable@vger.kernel.org
---
fs/pstore/ram.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 1a4f6da..0c2ae26 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -374,10 +374,14 @@ static int __devinit ramoops_probe(struct platform_device *pdev)
goto fail_out;
}
- pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
- pdata->record_size = rounddown_pow_of_two(pdata->record_size);
- pdata->console_size = rounddown_pow_of_two(pdata->console_size);
- pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
+ if (pdata->mem_size)
+ pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
+ if (pdata->record_size)
+ pdata->record_size = rounddown_pow_of_two(pdata->record_size);
+ if (pdata->console_size)
+ pdata->console_size = rounddown_pow_of_two(pdata->console_size);
+ if (pdata->ftrace_size)
+ pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
cxt->dump_read_cnt = 0;
cxt->size = pdata->mem_size;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two.
2012-10-19 11:59 [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two Florian Fainelli
@ 2012-10-19 16:03 ` Kees Cook
2012-10-22 8:37 ` Florian Fainelli
2012-10-22 9:19 ` [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0) Florian Fainelli
1 sibling, 1 reply; 6+ messages in thread
From: Kees Cook @ 2012-10-19 16:03 UTC (permalink / raw)
To: Florian Fainelli
Cc: cbouatmailru, ccross, tony.luck, linux-kernel, Maxime Bizon, stable
On Fri, Oct 19, 2012 at 4:59 AM, Florian Fainelli <ffainelli@freebox.fr> wrote:
> From: Maxime Bizon <mbizon@freebox.fr>
>
> record_size / console_size / ftrace_size can be 0 (this is how you
> disable the feature), but rounddown_pow_of_two(0) is undefined. This problem
> has been present since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
>
> Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
> Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
> CC: stable@vger.kernel.org
> ---
> fs/pstore/ram.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 1a4f6da..0c2ae26 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -374,10 +374,14 @@ static int __devinit ramoops_probe(struct platform_device *pdev)
> goto fail_out;
> }
>
> - pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
> - pdata->record_size = rounddown_pow_of_two(pdata->record_size);
> - pdata->console_size = rounddown_pow_of_two(pdata->console_size);
> - pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
> + if (pdata->mem_size)
> + pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
Nice catch!
Instead of the == 0 check, what about using !is_power_of_2(size) ?
-Kees
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two.
2012-10-19 16:03 ` Kees Cook
@ 2012-10-22 8:37 ` Florian Fainelli
0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2012-10-22 8:37 UTC (permalink / raw)
To: Kees Cook
Cc: cbouatmailru, ccross, tony.luck, linux-kernel, Maxime Bizon, stable
On Friday 19 October 2012 09:03:12 Kees Cook wrote:
> On Fri, Oct 19, 2012 at 4:59 AM, Florian Fainelli <ffainelli@freebox.fr> wrote:
> > From: Maxime Bizon <mbizon@freebox.fr>
> >
> > record_size / console_size / ftrace_size can be 0 (this is how you
> > disable the feature), but rounddown_pow_of_two(0) is undefined. This problem
> > has been present since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
> >
> > Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
> > Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
> > CC: stable@vger.kernel.org
> > ---
> > fs/pstore/ram.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> > index 1a4f6da..0c2ae26 100644
> > --- a/fs/pstore/ram.c
> > +++ b/fs/pstore/ram.c
> > @@ -374,10 +374,14 @@ static int __devinit ramoops_probe(struct platform_device *pdev)
> > goto fail_out;
> > }
> >
> > - pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
> > - pdata->record_size = rounddown_pow_of_two(pdata->record_size);
> > - pdata->console_size = rounddown_pow_of_two(pdata->console_size);
> > - pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
> > + if (pdata->mem_size)
> > + pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
>
> Nice catch!
>
> Instead of the == 0 check, what about using !is_power_of_2(size) ?
That would work equally well, I will resubmit with this then.
--
Florian
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0)
2012-10-19 11:59 [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two Florian Fainelli
2012-10-19 16:03 ` Kees Cook
@ 2012-10-22 9:19 ` Florian Fainelli
2012-10-22 15:17 ` Kees Cook
1 sibling, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2012-10-22 9:19 UTC (permalink / raw)
To: cbouatmailru
Cc: ccross, keescook, tony.luck, linux-kernel, Maxime Bizon, stable,
Florian Fainelli
From: Maxime Bizon <mbizon@freebox.fr>
record_size / console_size / ftrace_size can be 0 (this is how you
disable the feature), but rounddown_pow_of_two(0) is undefined. As suggested
by Kees Cook, use !is_power_of_2() as a condition to call rounddown_pow_of_two
and avoid its undefined behavior on the value 0. This issue has been present
since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
CC: stable@vger.kernel.org
Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
---
Changes since v1:
- use !is_power_of_2(size) instead of (!size)
fs/pstore/ram.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 1a4f6da..bdd840d 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -374,10 +374,14 @@ static int __devinit ramoops_probe(struct platform_device *pdev)
goto fail_out;
}
- pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
- pdata->record_size = rounddown_pow_of_two(pdata->record_size);
- pdata->console_size = rounddown_pow_of_two(pdata->console_size);
- pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
+ if (!is_power_of_2(pdata->mem_size))
+ pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
+ if (!is_power_of_2(pdata->record_size))
+ pdata->record_size = rounddown_pow_of_two(pdata->record_size);
+ if (!is_power_of_2(pdata->console_size))
+ pdata->console_size = rounddown_pow_of_two(pdata->console_size);
+ if (!is_power_of_2(pdata->ftrace_size))
+ pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
cxt->dump_read_cnt = 0;
cxt->size = pdata->mem_size;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0)
2012-10-22 9:19 ` [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0) Florian Fainelli
@ 2012-10-22 15:17 ` Kees Cook
2012-11-18 1:42 ` Anton Vorontsov
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2012-10-22 15:17 UTC (permalink / raw)
To: Florian Fainelli
Cc: cbouatmailru, ccross, tony.luck, linux-kernel, Maxime Bizon, stable
On Mon, Oct 22, 2012 at 2:19 AM, Florian Fainelli <ffainelli@freebox.fr> wrote:
> From: Maxime Bizon <mbizon@freebox.fr>
>
> record_size / console_size / ftrace_size can be 0 (this is how you
> disable the feature), but rounddown_pow_of_two(0) is undefined. As suggested
> by Kees Cook, use !is_power_of_2() as a condition to call rounddown_pow_of_two
> and avoid its undefined behavior on the value 0. This issue has been present
> since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
>
> CC: stable@vger.kernel.org
> Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
> Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
Thanks for the fix!
Acked-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0)
2012-10-22 15:17 ` Kees Cook
@ 2012-11-18 1:42 ` Anton Vorontsov
0 siblings, 0 replies; 6+ messages in thread
From: Anton Vorontsov @ 2012-11-18 1:42 UTC (permalink / raw)
To: Kees Cook
Cc: Florian Fainelli, ccross, tony.luck, linux-kernel, Maxime Bizon, stable
On Mon, Oct 22, 2012 at 08:17:27AM -0700, Kees Cook wrote:
> On Mon, Oct 22, 2012 at 2:19 AM, Florian Fainelli <ffainelli@freebox.fr> wrote:
> > From: Maxime Bizon <mbizon@freebox.fr>
> >
> > record_size / console_size / ftrace_size can be 0 (this is how you
> > disable the feature), but rounddown_pow_of_two(0) is undefined. As suggested
> > by Kees Cook, use !is_power_of_2() as a condition to call rounddown_pow_of_two
> > and avoid its undefined behavior on the value 0. This issue has been present
> > since commit 1894a253 (ramoops: Move to fs/pstore/ram.c).
> >
> > CC: stable@vger.kernel.org
> > Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
> > Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
>
> Thanks for the fix!
>
> Acked-by: Kees Cook <keescook@chromium.org>
Applied, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-11-18 1:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-19 11:59 [PATCH] pstore/ram: fix undefined usage of rounddown_pow_of_two Florian Fainelli
2012-10-19 16:03 ` Kees Cook
2012-10-22 8:37 ` Florian Fainelli
2012-10-22 9:19 ` [PATCH v2] pstore/ram: fix undefined usage of rounddown_pow_of_two(0) Florian Fainelli
2012-10-22 15:17 ` Kees Cook
2012-11-18 1:42 ` Anton Vorontsov
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.