Re: [PATCH] efi: fix out-of-bounds null overwrite vulnerability

From: Matt Fleming
Date: Fri Jan 08 2016 - 05:13:35 EST


On Thu, 07 Jan, at 02:05:30PM, Insu Yun wrote:
> snprintf's return value is not bound by size value.
> (https://www.kernel.org/doc/htmldocs/kernel-api/API-snprintf.html)
> if printed value is larger than buffer size, it can overwrite
> null byte in out-of-bounds buffer.

But this function doesn't use snprintf(), it uses scnprintf() which
returns the number of characters written into buf and, because
scnprintf() largely follows vnsprintf(), it will never write more than
'size' bytes into the buffer.

> Signed-off-by: Insu Yun <wuninsu@xxxxxxxxx>
> ---
> drivers/firmware/efi/cper.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
> index d425374..77aa75f 100644
> --- a/drivers/firmware/efi/cper.c
> +++ b/drivers/firmware/efi/cper.c
> @@ -267,7 +267,6 @@ static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg)
> "DIMM location: not present. DMI handle: 0x%.4x ",
> mem->mem_dev_handle);
>
> - msg[n] = '\0';
> return n;
> }
>

Calling this a vulnerability is a little extreme. These fields come
from firmware and if you can't trust the firmware you've got bigger
issues.

I'm not even sure this is a bug. Tony?