]> git.baikalelectronics.ru Git - kernel.git/commit
efi: cper: fix snprintf() use in cper_dimm_err_location()
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Wed, 21 Apr 2021 19:46:36 +0000 (21:46 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Sat, 22 May 2021 12:05:37 +0000 (14:05 +0200)
commit1de1da8a42666777945f8d99fc6b6869289ef3ce
treea49a607f9725836b719f1054870d4503b2380a65
parentdcc800515dcc336c00a397ba0bc084f4e9fc4a9f
efi: cper: fix snprintf() use in cper_dimm_err_location()

snprintf() should be given the full buffer size, not one less. And it
guarantees nul-termination, so doing it manually afterwards is
pointless.

It's even potentially harmful (though probably not in practice because
CPER_REC_LEN is 256), due to the "return how much would have been
written had the buffer been big enough" semantics. I.e., if the bank
and/or device strings are long enough that the "DIMM location ..."
output gets truncated, writing to msg[n] is a buffer overflow.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Fixes: 383088ebedb88 ("CPER: Adjust code flow of some functions")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/cper.c