]> git.baikalelectronics.ru Git - kernel.git/commit
powerpc/rtas: use memmove for potentially overlapping buffer copy
authorNathan Lynch <nathanl@linux.ibm.com>
Mon, 6 Mar 2023 21:33:41 +0000 (15:33 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 May 2023 09:35:50 +0000 (11:35 +0200)
commit2bb60e7ab281f20fee10bda04ed9a73fb5bc5a8f
treeb39d015c45151abfb9b6dcb8b39f54d7358c53a1
parent74970ad8e7f657216112a511034586e0cf31e593
powerpc/rtas: use memmove for potentially overlapping buffer copy

[ Upstream commit 271208ee5e335cb1ad280d22784940daf7ddf820 ]

Using memcpy() isn't safe when buf is identical to rtas_err_buf, which
can happen during boot before slab is up. Full context which may not
be obvious from the diff:

if (altbuf) {
buf = altbuf;
} else {
buf = rtas_err_buf;
if (slab_is_available())
buf = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);
}
if (buf)
memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX);

This was found by inspection and I'm not aware of it causing problems
in practice. It appears to have been introduced by commit
dbb3d2cc0533 ("powerpc: Merge rtas.c into arch/powerpc/kernel"); the
old ppc64 version of this code did not have this problem.

Use memmove() instead.

Fixes: dbb3d2cc0533 ("powerpc: Merge rtas.c into arch/powerpc/kernel")
Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230220-rtas-queue-for-6-4-v1-2-010e4416f13f@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/kernel/rtas.c