Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcXLi-0003HK-Iu for mharc-grub-devel@gnu.org; Sat, 23 May 2020 12:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcXLh-0003H6-Ea for grub-devel@gnu.org; Sat, 23 May 2020 12:50:13 -0400 Received: from 64epicks.com ([116.203.107.72]:47760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcXLg-0001Py-IC for grub-devel@gnu.org; Sat, 23 May 2020 12:50:13 -0400 Received: from [85.224.11.194] (c-c20be055.019-252-73746f67.bbcust.telenor.se [85.224.11.194]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by 64epicks.com (Postfix) with ESMTPSA id C9DA831F4175 for ; Sat, 23 May 2020 18:48:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=64epicks.com; s=mail; t=1590252486; bh=Z3Vn3/87gzVEX85kZ0VR9gsjjGRLC0jxIDe2yQLS/PY=; h=To:From:Subject:Date; b=YzhpObWnpAeRSodqWZO03x+os+HaaOHVZdJD0wyYMz/qyI0qA/X9se0JWiREalvIP grGLQYrk8tU6uTF/ygA8adkpNah6wMtG3ETRAyaT/u81doKknvIFJkOOTOq5TKrNGl 6kAVyZIt964s6+U+72tyQBUem+OPOJwOt63BGdedx3RyNaZe9SOaTS8nMq9vYdK77g alZs5dDzLY9Vl3Dnd8QIGFQvXX3gdK9hyKxS+XDWdfBDcZesMufnnXdWoRQRtf0XP7 bAGJnODyp43v5j5+3DiKL+RIgJ/Rf4nu6i2vD5HSdCZQFN5BPNLOV5l/FuzmfC5xDD Bta2EUt3+wXvQ== To: grub-devel@gnu.org From: Jacob Paul Subject: Multiboot 2 Header Alignment: implementation contradicts specification Message-ID: Date: Sat, 23 May 2020 18:50:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=116.203.107.72; envelope-from=jacob.paul@64epicks.com; helo=64epicks.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/23 11:30:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Sat, 23 May 2020 16:50:13 -0000 The Multiboot2 specification specifies that the Multiboot2 header should be 8-byte (64-bit) aligned: >An OS image must contain an additional header called Multiboot2 header, >besides the headers of the format used by the OS image. The Multiboot2 >header must be contained completely within the first 32768 bytes of the >OS image, and must be 64-bit aligned. In general, it should come as >early as possible, and may be embedded in the beginning of the text >segment after the real executable header. However, the implementation of find_header() in multiboot_mbi2.c looks like this: >static struct multiboot_header * >find_header (grub_properly_aligned_t *buffer, grub_ssize_t len) >{ > struct multiboot_header *header; > /* Look for the multiboot header in the buffer. The header should > be at least 12 bytes and aligned on a 4-byte boundary. */ > for (header = (struct multiboot_header *) buffer; > ((char *) header <= (char *) buffer + len - 12); > header = (struct multiboot_header *) ((grub_uint32_t *) header + >MULTIBOOT_HEADER_ALIGN / 4)) > { > if (header->magic == MULTIBOOT2_HEADER_MAGIC > && !(header->magic + header->architecture > + header->header_length + header->checksum) > && header->architecture == MULTIBOOT2_ARCHITECTURE_CURRENT) > return header; > } > return NULL; >} There are multiple things that doesn't look right to me. The comment says that the header should be 4-byte aligned while at the same time, the actual loop only increments header 2 bytes for every iteration (MULTIBOOT_HEADER_ALIGN=8). It seems like this was just copied over from multiboot_mbi.c since they basically are identical with even the same comment. Is there a genuine problem here, or am I missing something? If it actually is just lazy copy-pasting; should it be changed, as some people might actually rely on grub finding the Multiboot2 header even though it isn't 8-byte aligned? Jacob