From patchwork Thu Aug 1 12:48:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlos_L=C3=B3pez?= X-Patchwork-Id: 1967666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Af66RfVC; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=S8X9t4/J; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZTMP02mmz1ybV for ; Thu, 1 Aug 2024 22:50:09 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=36UFx59zLLJNv57GzNg+l2Wp+syhFMFUU7L+UiUhHA8=; b=Af66RfVCEldV8Q 2T9Q56m+jDfAJ6CPsFURu6xBUK6eHrsPiXMsIou5nz6FIqNHAVdL6znvdbMU4iGUYzvT3MSzGBqZH yfzSet1qYIzQ6kVRCJq2f6cOLxYq9TVe7Czqj4vHAjBIZHvkeWIk4O9v297E0KdGFHof5Gsz8fmm+ M0Hcz0lluFJ78LbZhqswvxjJoM79A07wUNjb9OJduj1fC/cBPMudYizOE3RBWwHfXeHHd6A5ZhoAj DHlKRtXSAfnzwjRegHeDRFLDjNnOf5brpDAmCX1o2ukj6fPKb6fbiGO7qaIP+s+jyBod+Gf31ftPX mnelixKH0QuGHAZeTXMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVFo-00000005GRf-3crd; Thu, 01 Aug 2024 12:50:00 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVFl-00000005GQF-3UKv for opensbi@lists.infradead.org; Thu, 01 Aug 2024 12:49:59 +0000 Received: by mail-wm1-x341.google.com with SMTP id 5b1f17b1804b1-428e3129851so4397045e9.3 for ; Thu, 01 Aug 2024 05:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722516596; x=1723121396; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/ss1XD+d9qw5+34ptIheR1tpVP6WCOp9Ci3xPWxL49w=; b=S8X9t4/Jrt4c8WR9V4mWMzWHKyh0MH5Oz6zi/8cgiI8ByD23v8JzNoAy3EyuqB5kxH t1AH/n3azC80nMcMySTdUUb1ihRkBxoXbsV2Nn3Z2LZPvhQ2iCOjCvrSO9ffX5klRGpz /v6k0gsRSgGYbgaI6nTtnaJkoCDJuetUOknPTiX1PbtLE3EKVEo9SmS4B7r6sBNPBOdI i80Fgmwl10s4xGhkue6UF90k3nv4uJ2/s77vX2cm2d7LlT7gUCt/t/gMoamgyz8ecgEt +ZTO4VyDwzbxRTtvckENg0TyJxqL8tXOvewKnd7OdKX6hcqUyuGrJ6GdfeceYFQU52+p MkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722516596; x=1723121396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/ss1XD+d9qw5+34ptIheR1tpVP6WCOp9Ci3xPWxL49w=; b=qowutzC7X94c5FiQS/ygarv1DgP0H9x5yeAwWKMWmpzvdFej/fRIGZ30zD7345Fq/W GWmilln4BvCDVMXOe2Md0dMYEap+L/wKUZ+GFWXvC+nJ2L9BP5nlH23lXusqU8F2LY9y buMDz0osIgmjViDKDS0LNzg6Uk6VxUAI/TsqxGcTadmjrc9ZIb0rH0T46fd3K/SLq85b +rFqu5WSkRcMSWrPCwJfYz7j0w8KLtfMcQX+5+iL74KdnzJ2DPFK64+5bEUhFt+zKwF2 zGPJuTjmJLDSJphIjin00Js2ShhBtv3gjSzXeX9iw7t2anJ0POslm3HXW1/f9uol6SRK 9/Wg== X-Gm-Message-State: AOJu0YyAA5tvr/Zq8J/tB6pOHGpwDehODb4YoT+FxWNNuXLiH8ZSLuye GHql1oEdm0xsv90B79Xe/urSyXNMFJpnciqAXZzz90M41weA4NcPvS+l+a8qpgY= X-Google-Smtp-Source: AGHT+IEoDrGoG4E8vjTRaDCRoC+2wnshxqpY1fUV1sVXZ5k0cl7PZ/Rp7Gc1vcZLe8IqlnATRu3DEA== X-Received: by 2002:a05:6000:1043:b0:368:3194:8a85 with SMTP id ffacd0b85a97d-36baacb62f9mr1565876f8f.7.1722516596007; Thu, 01 Aug 2024 05:49:56 -0700 (PDT) Received: from debian.myguest.virtualbox.org (182.red-79-153-116.dynamicip.rima-tde.net. [79.153.116.182]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36b36857f6bsm19365922f8f.76.2024.08.01.05.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 05:49:55 -0700 (PDT) From: =?utf-8?q?Carlos_L=C3=B3pez?= To: opensbi@lists.infradead.org Cc: =?utf-8?q?Carlos_L=C3=B3pez?= Subject: [PATCH] lib: sbi: fwft: fix incorrect size passed to sbi_zalloc() Date: Thu, 1 Aug 2024 14:48:11 +0200 Message-Id: <20240801124811.5249-1-carlos.lopezr4096@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_054957_900270_1766ECAF X-CRM114-Status: GOOD ( 14.06 ) X-Spam-Score: -1.8 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The fwt_hart_state struct inciludes a flexible array member, so its allocation size will be that of the struct itself, plus that of each of the members in the array. When calculating this size, instea [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [carlos.lopezr4096(at)gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [carlos.lopezr4096(at)gmail.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The fwt_hart_state struct inciludes a flexible array member, so its allocation size will be that of the struct itself, plus that of each of the members in the array. When calculating this size, instead of taking the size of the struct, the size of a pointer to it was taken, which is incorrect. Luckily, this happenned to not produce memory corruption because the size of the non-flexible members of the struct is the same as the size of a pointer. Signed-off-by: Carlos López Reviewed-by: Anup Patel --- lib/sbi/sbi_fwft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index f1ae915..ef881ef 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -251,7 +251,7 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) fhs = fwft_get_hart_state_ptr(scratch); if (!fhs) { - fhs = sbi_zalloc(sizeof(fhs) + array_size(features) * sizeof(struct fwft_config)); + fhs = sbi_zalloc(sizeof(*fhs) + array_size(features) * sizeof(struct fwft_config)); if (!fhs) return SBI_ENOMEM;