Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lbKuW-0008L9-UO for mharc-grub-devel@gnu.org; Tue, 27 Apr 2021 06:25:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbKuS-0008H3-Ao for grub-devel@gnu.org; Tue, 27 Apr 2021 06:25:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbKuC-00040C-FK for grub-devel@gnu.org; Tue, 27 Apr 2021 06:25:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619519114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gK58fXp4J7FQSpvIpMyfwM5QmVWsPmf6vb7Lm7CEx1U=; b=jTJC5xxNU9P6ALyfc/z0ds5RWmmVVO2PeCbJmgWef4msDdAxe1E2QBUcC4PbtxkJNoL8ah 7UrdxQXVFA/VmpiTUDdd6KWfWqd5P+aer73Vviq/3DCLnF6XG6adUs161i5FCDinTiSaOW DbwUd0LfEIhGAFbhQvEg9Q7uD2ibP+8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-CzM-T4MlMvS1UfrTidXwXw-1; Tue, 27 Apr 2021 06:25:13 -0400 X-MC-Unique: CzM-T4MlMvS1UfrTidXwXw-1 Received: by mail-wr1-f70.google.com with SMTP id v2-20020a0560001622b0290106e28f8af8so17811686wrb.9 for ; Tue, 27 Apr 2021 03:25:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gK58fXp4J7FQSpvIpMyfwM5QmVWsPmf6vb7Lm7CEx1U=; b=rAY9IMIPZTWiaUL0lEx1m9coVxZh7wP+YgcCIxDZ9cUxkVGzlHp4HBOeLNSiVV0O5x MOWYudPFmtkWf+Bvs+Ne/kITvvWIPJrJbBqSWSpNwI7aWAQCC58ciogIIk5nnfHg5q6p a7uJR5cSkX9Fp4cymJQ5erCNEn/IEwnUbkVFC5R/ksKpBVP+YEJJKw4+7jgHVzOKVh41 srRCM+zt1MUyofO3zaMTlZwPG6lO5HxszKcQJz4RrVRzp0v8l5ElDGsds/UuSgok/ivI gHbu4PWfWNySjjGArlf7Q7RvSOveVdVeVqAEmRKprajDa3FNV3stJN5kVzGpLmcIiHQO dMCA== X-Gm-Message-State: AOAM5316eC0zHIV4Up9LgIUoXa4LtceQ1Bi4CfkZEvxBiBL0JY1NZ+ez IHZ1mu9KAwNLK+NneVV5OFtx5F0xHl4F3E3bxOJ1RCxpTQ1igmx0/NaMAfxEaCcO7rpk7s//4CL 7UlCiKFqyB1w5zDRz6iTO41XbVmoWUsO9dtpr+qsYDX951V1pqoM4/6L5pooPIQ== X-Received: by 2002:a1c:9a83:: with SMTP id c125mr3502475wme.62.1619519111792; Tue, 27 Apr 2021 03:25:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBJTkl/r8mbKodnfvRPlzuwPOlVKf75zTeRKi03Ntz0TS/0hrPJaMpJjALsLWluGMRJV4ZOg== X-Received: by 2002:a1c:9a83:: with SMTP id c125mr3502459wme.62.1619519111526; Tue, 27 Apr 2021 03:25:11 -0700 (PDT) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id l9sm3469534wrz.7.2021.04.27.03.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 03:25:11 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: John Paul Adrian Glaubitz , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v3] util/mkimage: Fix wrong PE32+ section sizes for some arches Date: Tue, 27 Apr 2021 12:25:08 +0200 Message-Id: <20210427102508.1721280-1-javierm@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=javierm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=216.205.24.124; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.219, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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, 27 Apr 2021 10:25:40 -0000 Commit f60ba9e5945 (util/mkimage: Refactor section setup to use a helper) added a helper function to setup PE sections. But it also changed how the raw data offsets were calculated since all the section sizes are aligned. However, for some platforms, i.e ia64-efi and arm64-efi, the kernel image size is not aligned using the section alignment. This leads to the situation in which the mods section offset in its PE section header does not match its real placement in the PE file. So, finally the GRUB is not able to locate and load built-in modules. The problem surfaces on ia64-efi and arm64-efi because both platforms require additional relocation data which is added behind .bss section. So, we have to add some padding behind this extra data to make the beginning of mods section properly aligned in the PE file. Fix it by aligning the kernel_size to the section alignment. That makes the sizes and offsets in the PE section headers to match relevant sections in the PE32+ binary file. Reported-by: John Paul Adrian Glaubitz Signed-off-by: Javier Martinez Canillas --- Changes in v3: - Drop the RFC prefix since I'm confident now about the solution. - Improve commit message (suggested by Daniel Kiper). - Don't use virtual memory addresses to calculate the kernel size, but instead use the raw data sizes (suggested by Daniel Kiper). Changes in v2: - Align up for any arch in the is_relocatable (image_target) patch and not only for MKIMAGE_ELF64 or EM_AARCH64 (suggested by Daniel Kiper). util/grub-mkimagexx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 00f49ccaaaf..d78fa3e5330 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -2388,6 +2388,10 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, layout->kernel_size += ALIGN_UP (layout->got_size, 16); } #endif + + if (image_target->id == IMAGE_EFI) + layout->kernel_size = ALIGN_UP (layout->kernel_size, + GRUB_PE32_FILE_ALIGNMENT); } else { -- 2.31.1