diff options
author | Maxime Bizon <mbizon@freebox.fr> | 2012-10-22 05:19:28 -0400 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-11-17 20:40:57 -0500 |
commit | b042e47491ba5f487601b5141a3f1d8582304170 (patch) | |
tree | 3dd470e6eef9dc87c478a047850b3da718794ab2 /fs/pstore | |
parent | 53f21a8ea1d76a002103ce20abd168fe83b20ee7 (diff) |
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: 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>
Diffstat (limited to 'fs/pstore')
-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 2b6ebbca3521..8741cea6253c 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c | |||
@@ -376,10 +376,14 @@ static int __devinit ramoops_probe(struct platform_device *pdev) | |||
376 | goto fail_out; | 376 | goto fail_out; |
377 | } | 377 | } |
378 | 378 | ||
379 | pdata->mem_size = rounddown_pow_of_two(pdata->mem_size); | 379 | if (!is_power_of_2(pdata->mem_size)) |
380 | pdata->record_size = rounddown_pow_of_two(pdata->record_size); | 380 | pdata->mem_size = rounddown_pow_of_two(pdata->mem_size); |
381 | pdata->console_size = rounddown_pow_of_two(pdata->console_size); | 381 | if (!is_power_of_2(pdata->record_size)) |
382 | pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size); | 382 | pdata->record_size = rounddown_pow_of_two(pdata->record_size); |
383 | if (!is_power_of_2(pdata->console_size)) | ||
384 | pdata->console_size = rounddown_pow_of_two(pdata->console_size); | ||
385 | if (!is_power_of_2(pdata->ftrace_size)) | ||
386 | pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size); | ||
383 | 387 | ||
384 | cxt->dump_read_cnt = 0; | 388 | cxt->dump_read_cnt = 0; |
385 | cxt->size = pdata->mem_size; | 389 | cxt->size = pdata->mem_size; |