Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2138750lqb; Mon, 27 May 2024 09:03:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWt1xPUgYl0y7t2zxgpbPTGu6k4/wS3zCyWhIla6R9EXDnnJ9ZF62lsKdsNhPROGzFm5MuquAVRC+rXjTNnDad8ieUkmSFPRGfTWckQqg== X-Google-Smtp-Source: AGHT+IFRDA4Cg4nIET60hu3f/qwlxLmoAUCkRmfjXzQdPeDWvifQJKNmFxyIhS+7qkVMrxvEugjd X-Received: by 2002:a17:903:8c3:b0:1e2:c8f9:4cd7 with SMTP id d9443c01a7336-1f4497e587fmr121560225ad.64.1716825782679; Mon, 27 May 2024 09:03:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716825782; cv=pass; d=google.com; s=arc-20160816; b=tT8ukW8A2aHPo7XLCqKJaPezwxZp1FcvPKoZ8IkE5lHcGZGJKy4+wnbEtePLHbFZzd uzcFXc9bmPgQ9i7GL0MitjXB0E/zDvOi5KGB52Q8JCuUoPSASf29QAmSJMQLVjAKJqzk nL2Pm3VnxHZ9dLkqyeCROiexer57yot7WS/cBmHncHaniHoaSv4adAaWeFgSjIh3QYin NqO5CdF1VFdO/FQpZ0ov6DjvUO6U7J0ity3GIjg9f8wZH9bnzH6vs0YDPwRo3/XN+hso E3meOj043B7Sg1lXMbZ4v1kd4a/w0ZB/NQgukbkCBe8UUAlr/TV4+jplPlLtZW4wsfKI qBRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=P7ZUacBLI1biCOdHmS9LipymMqaFYQ7KMpgvjwurGSc=; fh=4e3+Vammx9mp0UKw8rxGK7lV4yFzZT/4RInRaFNDJMc=; b=Wx7VUSXTGZYXYmDqxVzjV5kf6/9J48tmZU0RdUBfyOhgThkt5MdKxND679YrwFoqG5 +gvLAk/chmd1MVo1icXf9RAlyqzZNCrpg1fV08ehhU3ORc4dr79fz5s808w8duLkh5X1 g4OgDLFh8Uo4DLwJouZ+8Zfm6pRZ2dHqv9d+bLrIiTukAW6ZAmlMJVlO9MUtP3vVwql1 S2jRo/0bI2QgMUIaoR8SRNbLxBuO1Ph1e6LNurM/AYw31CDZyRXfJK1v0KXH/d4YDmsJ mbgjrk1cGQ2fcOh8p7i+h/rr/tlUai7Wmc2cT4XAUpvCGU+faMz2MUWMFuxYemehiKO2 y/2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OXz4bQle; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f48bd18d13si27564305ad.216.2024.05.27.09.03.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 09:03:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OXz4bQle; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0E90D281805 for ; Mon, 27 May 2024 15:55:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 035B8161913; Mon, 27 May 2024 15:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OXz4bQle" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2399A155CB4; Mon, 27 May 2024 15:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825163; cv=none; b=JHr2rRTVWxJxdl3cltXAkfSZFcfdB6xfBDwKWLS+xUm2Rhcmyi3Wge8TXyicJrI5tjLcHTO9rZWHIKny3N7nvA9HYZEGvPhlry/NNEdeD8XPcQxtipN6Z/M38f0o33gUpE6Fgy5taERuRyKOb4wL2KiOqzFBjis73LOFG7SrDGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825163; c=relaxed/simple; bh=3SmlgS7uzCZyp3qIvmlKEKCak6Qut8+f73ynLbkP9IM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=krQlSb8HIL2kxov8njqkw8lJQRnepbumhT++KcBzW4WUkcDQ58XtTV3kiz4BY2YQKKIt07T1dqdXShQzofiOvTd3k6JW6ouyo3n6FekgZoZO95m83hyO/wh18gjv4RCkSpOZaVeTlAP5O2V/+PIPBMwX1eNNH+bxueDgz2PW/Z4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OXz4bQle; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AC07C32781; Mon, 27 May 2024 15:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716825163; bh=3SmlgS7uzCZyp3qIvmlKEKCak6Qut8+f73ynLbkP9IM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXz4bQleBft3zYeRZTcnuXa7+f4aVFhmoubxHfKd/BquxcRnTfCLnsQ+7FaUex+83 SSrZpd+AE8th+n8yL2Gpnt2J5T8NE9LBVIWF38PMZfG00HsykFo6Wha6ji915bLYvQ C4qsL7+vCFikSO2cHa0ftMZam0Jz5QrvqR6R7SIaVC3X1mleg9UbQvJzbML9PjRg6P I3wuWMcUiyfmJlK0Qztjh52GYgVVH8tupo9mgXO3w0MwaHD+KP0qK+YAEojvzqPo7t LUWFNRU+cgeXCBQKX0LQF1MjM6LwmbXYaY3gqqKD4ew374GWC7+yzJsG2WvMJeegoo kUwEjE20KDFyQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nathan Lynch , Michael Ellerman , Sasha Levin , nathan@kernel.org, vaibhav@linux.ibm.com, gautam@linux.ibm.com, amachhiw@linux.vnet.ibm.com, jniethe5@gmail.com, sshegde@linux.ibm.com, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.9 19/23] powerpc/pseries: Enforce hcall result buffer validity and size Date: Mon, 27 May 2024 11:50:20 -0400 Message-ID: <20240527155123.3863983-19-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527155123.3863983-1-sashal@kernel.org> References: <20240527155123.3863983-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.2 Content-Transfer-Encoding: 8bit From: Nathan Lynch [ Upstream commit ff2e185cf73df480ec69675936c4ee75a445c3e4 ] plpar_hcall(), plpar_hcall9(), and related functions expect callers to provide valid result buffers of certain minimum size. Currently this is communicated only through comments in the code and the compiler has no idea. For example, if I write a bug like this: long retbuf[PLPAR_HCALL_BUFSIZE]; // should be PLPAR_HCALL9_BUFSIZE plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, ...); This compiles with no diagnostics emitted, but likely results in stack corruption at runtime when plpar_hcall9() stores results past the end of the array. (To be clear this is a contrived example and I have not found a real instance yet.) To make this class of error less likely, we can use explicitly-sized array parameters instead of pointers in the declarations for the hcall APIs. When compiled with -Warray-bounds[1], the code above now provokes a diagnostic like this: error: array argument is too small; is of size 32, callee requires at least 72 [-Werror,-Warray-bounds] 60 | plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, | ^ ~~~~~~ [1] Enabled for LLVM builds but not GCC for now. See commit 0da6e5fd6c37 ("gcc: disable '-Warray-bounds' for gcc-13 too") and related changes. Signed-off-by: Nathan Lynch Signed-off-by: Michael Ellerman Link: https://msgid.link/20240408-pseries-hvcall-retbuf-v1-1-ebc73d7253cf@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/hvcall.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h index a41e542ba94dd..39cd1ca4ccb9c 100644 --- a/arch/powerpc/include/asm/hvcall.h +++ b/arch/powerpc/include/asm/hvcall.h @@ -524,7 +524,7 @@ long plpar_hcall_norets_notrace(unsigned long opcode, ...); * Used for all but the craziest of phyp interfaces (see plpar_hcall9) */ #define PLPAR_HCALL_BUFSIZE 4 -long plpar_hcall(unsigned long opcode, unsigned long *retbuf, ...); +long plpar_hcall(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL_BUFSIZE], ...); /** * plpar_hcall_raw: - Make a hypervisor call without calculating hcall stats @@ -538,7 +538,7 @@ long plpar_hcall(unsigned long opcode, unsigned long *retbuf, ...); * plpar_hcall, but plpar_hcall_raw works in real mode and does not * calculate hypervisor call statistics. */ -long plpar_hcall_raw(unsigned long opcode, unsigned long *retbuf, ...); +long plpar_hcall_raw(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL_BUFSIZE], ...); /** * plpar_hcall9: - Make a pseries hypervisor call with up to 9 return arguments @@ -549,8 +549,8 @@ long plpar_hcall_raw(unsigned long opcode, unsigned long *retbuf, ...); * PLPAR_HCALL9_BUFSIZE to size the return argument buffer. */ #define PLPAR_HCALL9_BUFSIZE 9 -long plpar_hcall9(unsigned long opcode, unsigned long *retbuf, ...); -long plpar_hcall9_raw(unsigned long opcode, unsigned long *retbuf, ...); +long plpar_hcall9(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE], ...); +long plpar_hcall9_raw(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE], ...); /* pseries hcall tracing */ extern struct static_key hcall_tracepoint_key; -- 2.43.0