Re: [PATCH 4/5] x86/setup/crash: Check memblock_reserve() retval

From: Dave Young
Date: Thu Oct 15 2015 - 05:20:54 EST


On 10/15/15 at 10:20am, Borislav Petkov wrote:
> From: Borislav Petkov <bp@xxxxxxx>
>
> memblock_reserve() can fail but the crashkernel reservation code
> doesn't check that and this can lead the user into believing that the
> crashkernel region was actually reserved. Make sure we check that return
> value and we exit early with a failure message in the error case.
>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Andy Lutomirski <luto@xxxxxxxxxxxxxx>
> Cc: Dave Young <dyoung@xxxxxxxxxx>
> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: jerry_hoemann@xxxxxx
> Cc: Jiri Kosina <jkosina@xxxxxxx>
> Cc: Joerg Roedel <jroedel@xxxxxxx>
> Cc: Juergen Gross <jgross@xxxxxxxx>
> Cc: Mark Salter <msalter@xxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: WANG Chao <chaowang@xxxxxxxxxx>
> Cc: x86-ml <x86@xxxxxxxxxx>
> Signed-off-by: Borislav Petkov <bp@xxxxxxx>
> ---
> arch/x86/kernel/setup.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index d4788719a1e2..3f75297d5fd0 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -531,7 +531,11 @@ static int __init reserve_crashkernel_low(void)
> return -ENOMEM;
> }
>
> - memblock_reserve(low_base, low_size);
> + ret = memblock_reserve(low_base, low_size);
> + if (ret) {
> + pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
> + return ret;
> + }
>

Seems there's no checking for other callback to memblock_reserve in setup.c
Need another cleanup?

BTW, a further cleanup is reasonable to me, there's a lot of below patter:
memblock_find_in_range
error checking
memblock_reserve
error checking

So a new function memblock_reserve_in_range is reasonable.

Thanks
Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/