From 5b5254d28f6419953fe406e84f72f86d7b5b1402 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: May 11 2023 08:25:00 +0000 Subject: powerpc/rtas: use memmove for potentially overlapping buffer copy (bsc#1065729). --- diff --git a/patches.suse/powerpc-rtas-use-memmove-for-potentially-overlapping.patch b/patches.suse/powerpc-rtas-use-memmove-for-potentially-overlapping.patch new file mode 100644 index 0000000..e3ab7e5 --- /dev/null +++ b/patches.suse/powerpc-rtas-use-memmove-for-potentially-overlapping.patch @@ -0,0 +1,57 @@ +From 271208ee5e335cb1ad280d22784940daf7ddf820 Mon Sep 17 00:00:00 2001 +From: Nathan Lynch +Date: Mon, 6 Mar 2023 15:33:41 -0600 +Subject: [PATCH] powerpc/rtas: use memmove for potentially overlapping buffer + copy + +References: bsc#1065729 +Patch-mainline: v6.4-rc1 +Git-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 +033ef338b6e0 ("powerpc: Merge rtas.c into arch/powerpc/kernel"); the +old ppc64 version of this code did not have this problem. + +Use memmove() instead. + +Fixes: 033ef338b6e0 ("powerpc: Merge rtas.c into arch/powerpc/kernel") +Signed-off-by: Nathan Lynch +Reviewed-by: Andrew Donnellan +Signed-off-by: Michael Ellerman +Link: https://msgid.link/20230220-rtas-queue-for-6-4-v1-2-010e4416f13f@linux.ibm.com +Acked-by: Michal Suchanek +--- + arch/powerpc/kernel/rtas.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c +index 31175b34856a..9256cfaa8b6f 100644 +--- a/arch/powerpc/kernel/rtas.c ++++ b/arch/powerpc/kernel/rtas.c +@@ -981,7 +981,7 @@ static char *__fetch_rtas_last_error(char *altbuf) + buf = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC); + } + if (buf) +- memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX); ++ memmove(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX); + } + + return buf; +-- +2.40.0 + diff --git a/series.conf b/series.conf index 93332d0..d72ba61 100644 --- a/series.conf +++ b/series.conf @@ -63307,6 +63307,7 @@ patches.suse/USB-dwc3-fix-runtime-pm-imbalance-on-probe-errors.patch patches.suse/USB-dwc3-fix-runtime-pm-imbalance-on-unbind.patch patches.suse/usb-chipidea-fix-missing-goto-in-ci_hdrc_probe.patch + patches.suse/powerpc-rtas-use-memmove-for-potentially-overlapping.patch patches.suse/xfs-verify-buffer-contents-when-we-skip-log-replay.patch # dhowells/linux-fs keys-uefi