Commit b042e474 authored by Maxime Bizon's avatar Maxime Bizon Committed by Anton Vorontsov

pstore/ram: Fix undefined usage of rounddown_pow_of_two(0)

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: default avatarMaxime Bizon <mbizon@freebox.fr>
Signed-off-by: default avatarFlorian Fainelli <ffainelli@freebox.fr>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent 53f21a8e
......@@ -376,9 +376,13 @@ static int __devinit ramoops_probe(struct platform_device *pdev)
goto fail_out;
}
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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment