From nobody Mon May 13 06:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694528888633539.6877498749421; Tue, 12 Sep 2023 07:28:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qg4M8-0001Wr-In; Tue, 12 Sep 2023 10:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg4M4-0001VH-9F; Tue, 12 Sep 2023 10:27:04 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg4M1-0006FV-Vm; Tue, 12 Sep 2023 10:27:03 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 81CFC3200034; Tue, 12 Sep 2023 10:26:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 12 Sep 2023 10:27:00 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 10:26:57 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm3; t=1694528819; x=1694615219; bh=oiN0GeCq/ks9Q7gseTFkhe2yF Z2NQWahiVOVHZ3K6HE=; b=Ccmrng3NaZWLJtA3QSMafH/inciAZb7VsWra0qEsa mH0i0jj5goRy0WUItU+eGwPe8fO4nuUY+AfukyWY00H4AlDK1CoTeVX8t+dMYDe9 G0UjSFVSNUpvu49TXHpMLs14OItJLSIZzoteozBJo8tBvwLzoamtk8rXopLlq98w e6eVCoNPQnGzxQ+JKpWR1Fj0W7GeXQydblF6LYf0+KGdHlHxY5PbfAFyeNhR0YRa 3hKq0ia6dFg7bv6Lw2ENilje2n47DjJHvbZ1iufwpndD21t/pvGDh0w02GyZfJOA jN4MW1GMyn3WnRxvtjG7oEqCif8sAt52vzGBaUu/YGv9g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1694528819; x=1694615219; bh=oiN0GeCq/ks9Q7gseTFkhe2yFZ2NQWahiVO VHZ3K6HE=; b=iBl/sDf6EH/OBg0uHwVsZjJvvC0XKHChc0s7iHolqdf+G9Rzbzk anW+pKHXty40BuG+bUdUyyLrBJpkm5HzYACmPGqzQIrncCqYaDZ7VYxTG9lSj8jC MNqHeEJ9/3Ya3ha7nCZ5T2hci6A5cPUWib22+/9yeb12TF68tL91UtjHbnYTNaM+ AEFaifbZrQApW6BHzUPrItmbw4zCMVetMgaaRIckU4DSZm3ik30gO5YO+s+1Dupy 4C6QBJ8aDdpnHNlNWAfEernisULDaImTmwaNe0xAsCBA7K3JJqc4t88t9BqH96nc klLtlU1iJ2SHRy6KcwDAAI5EmZ4+di6p3RQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgr uhhsucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrg htthgvrhhnpeefvedtueetueduffevgffgtdeftdeuleffhfeigeffkeegfeejfeffteej iefhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Fam Zheng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , Klaus Jensen , Kevin Wolf , Keith Busch , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Klaus Jensen Subject: [PULL 1/2] hw/nvme: Use #define to avoid variable length array Date: Tue, 12 Sep 2023 16:26:51 +0200 Message-ID: <20230912142649.11002-5-its@irrelevant.dk> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912142649.11002-4-its@irrelevant.dk> References: <20230912142649.11002-4-its@irrelevant.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=openpgp-sha256; l=1587; i=k.jensen@samsung.com; h=from:subject; bh=E7DjdRj14im2VetumRoAJOcha10LzkLK3x/G/8tlZSg=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGUAdSr6/qYO46V3EqWovW+IbGsg1gu0edN6q 5TRTBw14ybxnYkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJlAHUqAAoJEE3hrzFt Tw3pmTkIAKDoVQIHzlcjatjeXVTO9cX8C0kb2HrFURVHNSVYqE8UJZyAMVb3nvGBuRGAOP3hj2G vQrdRNIo22vwU1JjhTzdxsmP7iv6QRmn87l5iJyCGsNMYMptWer/fcPRjQ5t840syI1RTcKnVA1 CuVOlx9CiOOWHgBmwBKdv1Kht9PizzaFAPX59OhQFWq0mK7vlMFOOn4V8YeaUikQA91AHfwBUmL vOm7jil2MLJGzyGH6llHWCQh4BfTi8IMIpyiscI3X0lZWfkO16/19sY7Le1a+omrItmzp53zur5 ObGEIXsHHgvtANeLv2+3lOEyL70bAuGBM04Uk3k84FVqq/DT9LOcgKXg X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1694528890497100005 From: Philippe Mathieu-Daud=C3=A9 In nvme_map_sgl() we create an array segment[] whose size is the 'const int SEG_CHUNK_SIZE'. Since this is C, rather than C++, a "const int foo" is not a true constant, it's merely a variable with a constant value, and so semantically segment[] is a variable-length array. Switch SEG_CHUNK_SIZE to a #define so that we can make the segment[] array truly fixed-size, in the sense that it doesn't trigger the -Wvla warning. The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527). [PMM: rebased (function has moved file), expand commit message based on discussion from previous version of patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Maydell Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 539d27355313..d99a6f5c9a2e 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -1045,7 +1045,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg,= NvmeSglDescriptor sgl, * descriptors and segment chain) than the command transfer size, so i= t is * not bounded by MDTS. */ - const int SEG_CHUNK_SIZE =3D 256; +#define SEG_CHUNK_SIZE 256 =20 NvmeSglDescriptor segment[SEG_CHUNK_SIZE], *sgld, *last_sgld; uint64_t nsgld; --=20 2.42.0 From nobody Mon May 13 06:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694528867681738.2222221953688; Tue, 12 Sep 2023 07:27:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qg4MF-0001a4-KG; Tue, 12 Sep 2023 10:27:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg4M8-0001XB-MI; Tue, 12 Sep 2023 10:27:08 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg4M6-0006Fv-Fc; Tue, 12 Sep 2023 10:27:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 22814320098B; Tue, 12 Sep 2023 10:27:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 12 Sep 2023 10:27:04 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 10:27:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1694528822; x= 1694615222; bh=T5/wSFH5UysJriXBNU9TNxkLsFcDhOioChngTaRpK3Q=; b=r +UKaOfFmRHyyKX4TeQay5uu+FLIM6px5K0cDkbN02JZTpT34mR9sqhnc6afpthV6 cT/rZMXepDEP9LGkVpbwQf8hJzBg41z0Rd7vcyfhXmkN5KX7deJZdlEorygi5yxA Atqi/KEfecdtz47L69uojEIdoyrYSWwM3X+NgF5U7vLOVOcdoNjXDcYCsXiDnCGz 3qPrKPwfRG0hlCI1I92iJZ+4dfvKn61GO7KBcBv1pRABOMaxwBUFjFvSXnsdnuLp VCioXKeDqC64uhRon9QUiJMBXw557Ok/h4TNni0S3aaKyizqFaKa7kBge0gIDH1q lFesa4iPIz83WYXr6+IwQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1694528822; x= 1694615222; bh=T5/wSFH5UysJriXBNU9TNxkLsFcDhOioChngTaRpK3Q=; b=R ynVoW7S6tMus41nELXFqG362gTwDaHvk2T8dc6vKtMzas1NvdgseYAaEdgHTzIYS 1oWSBVYl5btZDiYNu2730sITKv8rfQkf8+Z/JtUEkZfWQO1vLLEsREFuoICBKVcr 9ZmxOeOCgZMVN89VqXvORILzD7y72qcPP7ze+pKcfvlWSA4o+67fX9W78E2K0Qbp jG3Ut3dO1e2oZcbulRL3dvS2+m1yJCrnFErbevfeN1SkCvwNM7COWCHj129OP2Ma OCHJ9aklJp1rHZkDNaBVgTCD4F7Nx2DeLG8Gk3PeUJiVzhxXl3nWZD9vearCQtH4 O2El84+LplqiOd9oHH+9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Fam Zheng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Hanna Reitz , Klaus Jensen , Kevin Wolf , Keith Busch , Klaus Jensen Subject: [PULL 2/2] hw/nvme: Avoid dynamic stack allocation Date: Tue, 12 Sep 2023 16:26:52 +0200 Message-ID: <20230912142649.11002-6-its@irrelevant.dk> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912142649.11002-4-its@irrelevant.dk> References: <20230912142649.11002-4-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1072; i=k.jensen@samsung.com; h=from:subject; bh=k8Y7iQz7gOK9fuxUsAHHCrYcflluV+Qz2N+9aldrpJE=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGUAdSrjujEk+l6HiX1de5lsZ3HThXQrBQkwU Xa9JxrwkYN8EIkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJlAHUqAAoJEE3hrzFt Tw3pGFIH/ijZb901m/wUU0yApw6ONIxcyLqh4GM3mnHwFukiBb7iAEyhUVWbwl1hfq6uxB61Vkc giEcT+l5FSxZp8bfMlNeNKwmx0fs+qyx1HNmMuUYC0nyAawyC/QZnwDIQCap5geVCmZYCdNPoU/ SrphZxi4qQ6Oj1/YOmeoGy31vJSRB2DJvXOOiX3roqk+P0M9F7N4A2jyx8Qa8qDxRy/ymGnaoHv yKHtVsW3POY/0X+akDXLVTTJlle/oitBqEqYqPpIpLVj4NGzq23/tJYQHElAZQ9X/FF7SNp+lz0 QKaRrXX1P3BabH7NXJEeorjbC1sf9rmDvCvd3WAw2/UwZPIlql3QV6hD X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1694528869490100001 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Instead of using a variable-length array in nvme_map_prp(), allocate on the stack with a g_autofree pointer. The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527). Signed-off-by: Peter Maydell Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index d99a6f5c9a2e..90687b168ae1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -894,7 +894,7 @@ static uint16_t nvme_map_prp(NvmeCtrl *n, NvmeSg *sg, u= int64_t prp1, len -=3D trans_len; if (len) { if (len > n->page_size) { - uint64_t prp_list[n->max_prp_ents]; + g_autofree uint64_t *prp_list =3D g_new(uint64_t, n->max_prp_e= nts); uint32_t nents, prp_trans; int i =3D 0; =20 --=20 2.42.0