From patchwork Sun Mar 27 08:25:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1609864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=V4gD8QBa; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=JA1JySFa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KR86K58VCz9s0r for ; Sun, 27 Mar 2022 19:25:45 +1100 (AEDT) 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=kr3MpVDeU5DcqGbQ7Kc+yn+7zKt+nyufw8VZ/r77RBc=; b=V4gD8QBaXcqPB+ DB06Vj5jfCsNXYeVQ1ggPQEoHIeYA/Kuws8Jbe3Y8KeEu14x3s4N4OxHTuoaNIfrHDiF3iYRVU3ZY 9JwLL/Tb42JplEUWEazIF+9bg+WW2Y+2OKL7SEWWOXtlYPOz8nvQHyhgywlap6ggwJfdCIqbLCNTF MEKKW715Oz5UoOj1OgKl3oIEk2W/azHE66kjitlvALq8Gmml4WqUitMZBVzQ8tttltV4NmCncHiLo IGwtpWEqimSnMpGRsuo3qIpkJPkB6EAfM6VSz8JtMUZqsa3roaHKEl3x4UaXs2uTPQDkpap91wJ9F aALOYGa0O1rjyGNvPyIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYODK-005LHl-US; Sun, 27 Mar 2022 08:25:30 +0000 Received: from mail-m965.mail.126.com ([123.126.96.5]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYODH-005LGz-H5 for opensbi@lists.infradead.org; Sun, 27 Mar 2022 08:25:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=m2RXW dhLOUWefIkOaVA2b7f+cp6/79F7dj6tLnz1cx8=; b=JA1JySFa4bpSz57NqWTKt Bg4l7D5gXNgpbx8EiSVpXvMNAoDHfO6JIdFtj7rdCdlmBfEcNI8TWYKCqGXpT2bf DmvLdYplZ3E2h+4BN/Xsr508iIl9k4jQ7qwT5tjHa+ihNOzi7AOOjzAA3tNjLKjH Qxi3EBF6toO92+AOMFA2sM= Received: from x390.lan (unknown [210.22.74.144]) by smtp10 (Coremail) with SMTP id NuRpCgDniUZzH0BiniyrDQ--.298S2; Sun, 27 Mar 2022 16:25:24 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: anup@brainfault.org, Xiang W Subject: [PATCH V4] include: Add check for offset fw_dynamic_info Date: Sun, 27 Mar 2022 16:25:20 +0800 Message-Id: <20220327082520.66613-1-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CM-TRANSID: NuRpCgDniUZzH0BiniyrDQ--.298S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFWUtr1kAw1DCr4xZw48Crg_yoW8ur4fpr n5Aay3ua1UWFyxu3WfGa97ZFsIvF1I9FW5Ja9rur4ftFy5WFn0gF4DGan8CF1rJan5A3yU W343tFW5uF1UAF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRPrchUUUUU= X-Originating-IP: [210.22.74.144] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xLQOl53YZxsGAABsO X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220327_012527_936227_D194A6E0 X-CRM114-Status: UNSURE ( 5.88 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) 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: Add static detection to prevent the modification of struct fw_dynamic_info from forgetting the modification of FW_DYNAMIC_INFO_xxx_OFFSET Signed-off-by: Xiang W --- V4 change: * comment style change Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [123.126.96.5 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] 0.0 RCVD_IN_MSPIKE_L5 RBL: Very bad reputation (-5) [123.126.96.5 listed in bl.mailspike.net] -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 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.0 RCVD_IN_MSPIKE_BL Mailspike blacklisted 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 Add static detection to prevent the modification of struct fw_dynamic_info from forgetting the modification of FW_DYNAMIC_INFO_xxx_OFFSET Signed-off-by: Xiang W --- V4 change: * comment style change include/sbi/fw_dynamic.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/sbi/fw_dynamic.h b/include/sbi/fw_dynamic.h index dea207b..d007b05 100644 --- a/include/sbi/fw_dynamic.h +++ b/include/sbi/fw_dynamic.h @@ -74,6 +74,40 @@ struct fw_dynamic_info { */ unsigned long boot_hart; } __packed; +/** + * Prevent modification of struct fw_dynamic_info from affecting + * FW_DYNAMIC_INFO_xxx_OFFSET + */ +_Static_assert( + offsetof(struct fw_dynamic_info, magic) + == FW_DYNAMIC_INFO_MAGIC_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_MAGIC_OFFSET"); +_Static_assert( + offsetof(struct fw_dynamic_info, version) + == FW_DYNAMIC_INFO_VERSION_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_VERSION_OFFSET"); +_Static_assert( + offsetof(struct fw_dynamic_info, next_addr) + == FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET"); +_Static_assert( + offsetof(struct fw_dynamic_info, next_mode) + == FW_DYNAMIC_INFO_NEXT_MODE_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_NEXT_MODE_OFFSET"); +_Static_assert( + offsetof(struct fw_dynamic_info, options) + == FW_DYNAMIC_INFO_OPTIONS_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_OPTIONS_OFFSET"); +_Static_assert( + offsetof(struct fw_dynamic_info, boot_hart) + == FW_DYNAMIC_INFO_BOOT_HART_OFFSET, + "struct fw_dynamic_info definition has changed, please redefine " + "FW_DYNAMIC_INFO_BOOT_HART_OFFSET"); #endif