Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2160226lqb; Mon, 27 May 2024 09:38:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7ZZWJY0zaTSCeiDiBA5jQHHPYbDNEh8/1O3bpycjFjXoOJNZ6CLq5dN2u2KH/zmwhE15cISZtoWeskNeQlr3lflnUbfjwQXbE0Z60Ng== X-Google-Smtp-Source: AGHT+IG4inYma0N5aK2ZemFi5dyvX6VsO5bF53uF2sxnEIjwZDk5S8Y5/KcbCo5DaNH+pmzUTCg7 X-Received: by 2002:a17:903:32cb:b0:1f3:52fe:4497 with SMTP id d9443c01a7336-1f4487438d7mr173587695ad.32.1716827895855; Mon, 27 May 2024 09:38:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716827895; cv=pass; d=google.com; s=arc-20160816; b=IymKvUsU8BpFodwmCUhrCxgYpTMYfIuGakGNWPxlBKtA7y2rBF6UXAeMrll90kuyWo TSFlFJysRJgNsZsPuZGzo0K0QLoM1Rfq2Rc22FXiyukcw/xujvSguN+CgZl65iSh3lmL wOLeEj52OXGNWb81z1kgnGkh5f4pMBGCTzYm7aw7U3y3se6+8K2J85xFdvcBvKRxRxcp nYm44wLFTSUXg31aJA+wC6OFMek+bNDpths3PU9Z1Vxm+GhYImPeKtbMyYUvpsuttup8 jlrFtPjgpu/rMyzjEVpCmDI7GAHU7XOlAEfX34Nf/vXip14JaRexyhB4qa79cy42vY4y yKRA== 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=rQbqXN5/1uEbsvbIftgL25T3KtvxZcCQ5FrYH5ugmYc=; fh=7pStqH1Z6XafqRQjKQbZVEIoSUvZnaX1VJ8IlTe+uDQ=; b=kiiMFNoRa0/WgJLFjdOTdU1/cAn8yopemlPI9pkTMu6GL6QvWkqWaUj+naNuhNI4nT 1kgZZxC5UhSZhT4rD5jyrKC4ZF00gKnstgaSvUnGgLl8aouirt7Epbz20n06M+91BDNA Aq0lGJ+7k6RMNdR2qicu+ZfAMCF1B0Fw+0CbpZwfI3nMilaXVa+hPUNY+wCcPBxHhaRE zkv/VyIL4YqaDQWHQx7/8atnTkkcMiKB4A5b6oo0y/SCQVRQ2lFZ3Lisg84KfdZnwE5X uL0d1qp/Cmfo7ArHRjV7SxhfIzasNwdsBuT26/7Ln+08CCgepcYlsASS69Ki6e4iBv0B xArw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oB5VPO6E; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191154-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. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c78ca7csi62152335ad.102.2024.05.27.09.38.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 09:38:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oB5VPO6E; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191154-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 E71AE28489C for ; Mon, 27 May 2024 16:03:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03B3816C84F; Mon, 27 May 2024 15:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oB5VPO6E" 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 2762915A863; Mon, 27 May 2024 15:56:29 +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=1716825390; cv=none; b=I5H3b1iPXcilgoJr3VViRzyEU9Jd187dGFodRKCPZZJ7D2zEC6fTk5Oej6Ak2u02cQRYiPz2rT/XWp0eiAx6xc38RiGwnI17+fP3u5kktEkdm6xdvAGF5XMgk6lKkluNynLPxcJOA2zFukcZVp1QWyW+rmzVaVJMuLFn6Ufzkso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825390; c=relaxed/simple; bh=FYdKHX7ogvtZzsFRwh54xV4K0TGRo+rs6W7bFcVA10I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cJmAvF05gaThy3ykDJ/1a8nev/C5QvU1cInKb6bmsXAo0QIGqSd7MhtcMndyvEhjcnFVW73qUvKfuOKpzv4VkeuJMVak3O0QLknnKxZafdjGBy9OFPFFjZnVnOXbFm1AjgA1Zgwsv0Q4MMtTcIQlimPIFzcFN87I6slnxgj9e84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oB5VPO6E; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CC8DC2BBFC; Mon, 27 May 2024 15:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716825389; bh=FYdKHX7ogvtZzsFRwh54xV4K0TGRo+rs6W7bFcVA10I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oB5VPO6EOU55IfhMFUe55w28vGtVG5Y/R9lYeQIE/vg4fj7bq+xYtTJR1wOcWWbfS hHHoi+ypOgGy+Cp4cH2BYlIkZlw4APrzuRRadiiVjwyl7IiGvVvbGBiu3/Lnoq67nE 07jwO7l9uWhn+teONryzksKWCcslDc923ObQ/rU9KVt8ttz3yM93a0nJPlZVWgO3VD hZL6S9bnY2S1yjYitAaneZ99Uu7vfLXpqCbErdOsZwccRRUhyqFspJAZbFVPTvekOd LhQg+VAaqOH1D4/gxddFZMwtLw/aDB4Y6w5x9j3OQIE8zAPlLk0N+3YNJu87MQnvQI 4QXVSVeJPcO3g== 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, amachhiw@linux.vnet.ibm.com, sshegde@linux.ibm.com, jniethe5@gmail.com, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.6 12/16] powerpc/pseries: Enforce hcall result buffer validity and size Date: Mon, 27 May 2024 11:55:03 -0400 Message-ID: <20240527155541.3865428-12-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527155541.3865428-1-sashal@kernel.org> References: <20240527155541.3865428-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.6.32 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 c099780385dd3..a36610bc63651 100644 --- a/arch/powerpc/include/asm/hvcall.h +++ b/arch/powerpc/include/asm/hvcall.h @@ -494,7 +494,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 @@ -508,7 +508,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 @@ -519,8 +519,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