From patchwork Tue Sep 12 14:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1833065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=r+UKaOfF; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=RynVoW7S; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RlQsc4B4Cz1yhZ for ; Wed, 13 Sep 2023 00:27:48 +1000 (AEST) 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 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 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 10:27:00 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Fam Zheng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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, uint64_t prp1, len -= trans_len; if (len) { if (len > n->page_size) { - uint64_t prp_list[n->max_prp_ents]; + g_autofree uint64_t *prp_list = g_new(uint64_t, n->max_prp_ents); uint32_t nents, prp_trans; int i = 0;