From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nathan Lynch Date: Mon, 06 Mar 2023 15:33:41 -0600 Subject: [PATCH 2/8] powerpc/rtas: use memmove for potentially overlapping buffer copy MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230220-rtas-queue-for-6-4-v1-2-010e4416f13f@linux.ibm.com> References: <20230220-rtas-queue-for-6-4-v1-0-010e4416f13f@linux.ibm.com> In-Reply-To: <20230220-rtas-queue-for-6-4-v1-0-010e4416f13f@linux.ibm.com> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org, Tyrel Datwyler , Scott Cheloha , Andrew Donnellan , Nick Child , Laurent Dufour , Nathan Lynch X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1678138471; l=1353; i=nathanl@linux.ibm.com; s=20230206; h=from:subject:message-id; bh=iWkx+OV9QpoHxF/qvBxckPhdHb72VXY4C4EjDwgRbNo=; b=i8fE9w68n3B/oGU9/B8fTt+wTYwinlIQ64WdShpt/OV/8YPE2G5kbZ3OFxpa6UqcLuzoc7qGu POX1zbZuGLlBmSQiOSAMjDzZFeEXYPVuyMI0Lhh4Iab84Ir9y2X2zrD X-Developer-Key: i=nathanl@linux.ibm.com; a=ed25519; pk=6daubz/ymoaMF+8voz7UHwnhluEsmDZuqygIIMWpQQY= X-Endpoint-Received: by B4 Relay for nathanl@linux.ibm.com/20230206 with auth_id=27 List-Id: B4 Relay Submissions 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 --- 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.39.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17EF8C61DA4 for ; Mon, 6 Mar 2023 21:41:40 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PVsTt3sj8z3fcg for ; Tue, 7 Mar 2023 08:41:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mQalm81r; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=145.40.68.75; helo=ams.source.kernel.org; envelope-from=devnull+nathanl.linux.ibm.com@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mQalm81r; dkim-atps=neutral Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4PVsKp2bVPz3bjb for ; Tue, 7 Mar 2023 08:34:37 +1100 (AEDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0893BB8113A; Mon, 6 Mar 2023 21:34:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id C3F07C4339C; Mon, 6 Mar 2023 21:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678138472; bh=yjTcU/4O54QXaOp7kD6dImYu6+xNwXi4eA/qEkkPwEk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mQalm81rD7wUE6QNY+8RtKrUaCDGV0FjQeOBFtAPCDCiqem12E/PBuDFC4fqlwI1A N8j4MbdC3MRaFoq95q+bad3MkjkQZqRt+DGo6aMIiGPVHjwhJWIjEc+nrPwIo/MY8t x5UgYsKBJ8Gf36BFgOEPOgimQ+HFkcV8uzICsoHfhyiDB03f7vVFKjUov0eSaFwgYo C76Ys/lgjZcuwg6wUvx/2Jv7Ks8TxanKKSefnbC/tz/YDjloQdSocZxOwAYvr92/Og imarrZx07G7ocbzrb0UZxH4VSj30as5z21yKFFJ4FhEw0vhWrfU44yoMVJPifGUAux FqJxt0aTWnepg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B051EC61DA4; Mon, 6 Mar 2023 21:34:32 +0000 (UTC) From: Nathan Lynch via B4 Relay Date: Mon, 06 Mar 2023 15:33:41 -0600 Subject: [PATCH 2/8] powerpc/rtas: use memmove for potentially overlapping buffer copy MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230220-rtas-queue-for-6-4-v1-2-010e4416f13f@linux.ibm.com> References: <20230220-rtas-queue-for-6-4-v1-0-010e4416f13f@linux.ibm.com> In-Reply-To: <20230220-rtas-queue-for-6-4-v1-0-010e4416f13f@linux.ibm.com> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1678138471; l=1353; i=nathanl@linux.ibm.com; s=20230206; h=from:subject:message-id; bh=iWkx+OV9QpoHxF/qvBxckPhdHb72VXY4C4EjDwgRbNo=; b=i8fE9w68n3B/oGU9/B8fTt+wTYwinlIQ64WdShpt/OV/8YPE2G5kbZ3OFxpa6UqcLuzoc7qGu POX1zbZuGLlBmSQiOSAMjDzZFeEXYPVuyMI0Lhh4Iab84Ir9y2X2zrD X-Developer-Key: i=nathanl@linux.ibm.com; a=ed25519; pk=6daubz/ymoaMF+8voz7UHwnhluEsmDZuqygIIMWpQQY= X-Endpoint-Received: by B4 Relay for nathanl@linux.ibm.com/20230206 with auth_id=27 X-Original-From: Nathan Lynch X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: nathanl@linux.ibm.com Cc: Nathan Lynch , Tyrel Datwyler , Nick Child , Andrew Donnellan , Scott Cheloha , Laurent Dufour , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Nathan Lynch 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 --- 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.39.1