diff options
author | Maxime Bizon <mbizon@freebox.fr> | 2012-10-22 11:19:28 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-17 08:45:58 -0800 |
commit | a8a491ca60238bc7c031f7731a5730aa06b6dda7 (patch) | |
tree | 640bffcdbaf15a81f775d65e4896115430504993 /fs | |
parent | b82212de08b20b70efe679cd4c8579c13771e610 (diff) |
pstore/ram: Fix undefined usage of rounddown_pow_of_two(0)
commit b042e47491ba5f487601b5141a3f1d8582304170 upstream.
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).
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/pstore/ram.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 1a4f6da58ea..bdd840d5df9 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; |