]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Jun 2021 10:41:35 +0000 (12:41 +0200)
commitacc1b80d0d4b9821b4a1b29c4b22419fe279de01
treec8e03ef755a06423efbf8043969eb1d36f4a6bc5
parentfc074db66f4e239b9138205560736f5268f30d45
efi: cper: fix snprintf() use in cper_dimm_err_location()

[ Upstream commit 942859d969de7f6f7f2659a79237a758b42782da ]

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: 3760cd20402d4 ("CPER: Adjust code flow of some functions")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/firmware/efi/cper.c