Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1maCFI-0006vS-Bn for mharc-grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCFD-0006rT-DR for grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:41 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:36398) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maCFA-0006P6-D3 for grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:38 -0400 Received: by mail-pj1-x1030.google.com with SMTP id qe4-20020a17090b4f8400b0019f663cfcd1so1253055pjb.1 for ; Tue, 12 Oct 2021 00:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4M9sfM1VSWlAV8PDICSrP58KXKM8jR5Z5wOJo7kBR5k=; b=JOfzRUuC6XXUS8L2PPPSf5JguokB717nKHe3bsopN2IBZSXm3W27VJvVqsbNqpVD8F iUXdW2USiYp5NbviCDUJHDAN/l+TULl/gW4Qygh8MPGHHRvQ4KbK6ybAekAiRNzIOQrC 2tUUSYqob18GzWftNDmo9n5x267sAnl33wrzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4M9sfM1VSWlAV8PDICSrP58KXKM8jR5Z5wOJo7kBR5k=; b=GF65SUwpSw3et3UPn+lok93GItwGNnDpiVP2zQqMRIUZC83dEvR4Nwt8fBpMy78rtv xibnF4CotUWalcaKhy6p9h13qwnJIprXf8+8lbi1BjwvhSNbmrgBWlhl4o5ip0u0OHSu H0ea+XFZUub6wf1Hxao2t3KRD7dTfOBIU2V97EaD8wb4aC9sG5pGzXdeVnoc76sk7NVy E14irZllHlMh+HI2iFLifxX1deiZLAyJrVG73Lp1+5ljIjvdxbkOUL0hryN7slj2H3vz Pzizgw2ZFh6gbZ+DYH01uG0XJYfw+fwfh3daCLaGIDuFz/fn93EnZ/Tt4i6owGS8SiRA NBSg== X-Gm-Message-State: AOAM532M1Cy29IBPlm82rUChwnfm3cOV4z6dz7jSZNISBB9qbX3A5KAf rfFIG1HglPI1CPDbJihXGhlKQUZ5+9iBGg== X-Google-Smtp-Source: ABdhPJw25gYJ7TamGweceRAfkOYZcxkP0al4UL/zv6jiSFUNDnZLPkgwiccYHfA8jMic1VnTT/sHaA== X-Received: by 2002:a17:90a:5895:: with SMTP id j21mr4199027pji.99.1634023834698; Tue, 12 Oct 2021 00:30:34 -0700 (PDT) Received: from localhost ([2001:4479:e300:600:41fe:d15:934f:4029]) by smtp.gmail.com with ESMTPSA id oj1sm1763266pjb.49.2021.10.12.00.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 00:30:34 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl, Daniel Axtens Subject: [PATCH 04/19] mm: assert that we preserve header vs region alignment Date: Tue, 12 Oct 2021 18:29:53 +1100 Message-Id: <20211012073008.4059133-5-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211012073008.4059133-1-dja@axtens.net> References: <20211012073008.4059133-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=dja@axtens.net; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 07:30:42 -0000 grub_mm_region_init() does: h = (grub_mm_header_t) (r + 1); where h is a grub_mm_header_t and r is a grub_mm_region_t. Cells are supposed to be GRUB_MM_ALIGN aligned, but while grub_mm_dump ensures this vs the region header, grub_mm_region_init() does not. It's better to be explicit than implicit here: rather than changing grub_mm_region_init() to ALIGN_UP(), require that the struct is explictly a multiple of the header size. Signed-off-by: Daniel Axtens --- include/grub/mm_private.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h index e80a059dd4e4..533b47173e18 100644 --- a/include/grub/mm_private.h +++ b/include/grub/mm_private.h @@ -20,6 +20,7 @@ #define GRUB_MM_PRIVATE_H 1 #include +#include /* Magic words. */ #define GRUB_MM_FREE_MAGIC 0x2d3c2808 @@ -82,4 +83,11 @@ typedef struct grub_mm_region extern grub_mm_region_t EXPORT_VAR (grub_mm_base); #endif +static inline void grub_mm_size_sanity_check(void) { + /* Ensure we preserve alignment when doing h = (grub_mm_header_t) (r + 1) */ + COMPILE_TIME_ASSERT((sizeof(struct grub_mm_region) % + sizeof(struct grub_mm_header)) == 0); + +} + #endif -- 2.30.2