Skip to content

Commit

Permalink
pstore/ram: Fix undefined usage of rounddown_pow_of_two(0)
Browse files Browse the repository at this point in the history
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 1894a25 (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>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
  • Loading branch information
Maxime Bizon authored and Anton Vorontsov committed Nov 18, 2012
1 parent 53f21a8 commit b042e47
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,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;
Expand Down

0 comments on commit b042e47

Please sign in to comment.