Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lZH7e-0005u7-P4 for mharc-grub-devel@gnu.org; Wed, 21 Apr 2021 13:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZH7d-0005u1-TB for grub-devel@gnu.org; Wed, 21 Apr 2021 13:58:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZH7b-0000At-KB for grub-devel@gnu.org; Wed, 21 Apr 2021 13:58:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619027922; 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=rtjfoqvUuVPQnhxc+I0fd3CEZeYQmNtNehkktC/Dvoo=; b=MUHXpPWhgfmPDg5nfyyWMa+xtAMz2N00uUWdLFwrcUatHe915Mee5gdIPoAMwJI+PpZfCX k8pdbl1RgX6ZRKNFUUFRGRJiC3VxPQYPgcvcVgvNcT/c+wYsLymoLgcU5xmM+IdOgOWI8a at+fiQMBk3GSA424rvoFdXpsF8Xdvv0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-68-mjKz6m-sMIm2AbO8yp862A-1; Wed, 21 Apr 2021 13:58:40 -0400 X-MC-Unique: mjKz6m-sMIm2AbO8yp862A-1 Received: by mail-wr1-f71.google.com with SMTP id 91-20020adf92e40000b029010470a9ebc4so11907013wrn.14 for ; Wed, 21 Apr 2021 10:58:40 -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=rtjfoqvUuVPQnhxc+I0fd3CEZeYQmNtNehkktC/Dvoo=; b=EBdlUGO05lAZCgVyl+BsaXL5V25/OrMvDokWsqiIWPm2TViRLTP9R++vaezvkyKbMQ mmRFZL+/O+f4zpG7oei6g6nNSwIMvnlgmI1vRnR88MsaIUdlShxgVtUviOF+ycKCaHva 6gm81WIGC0+w0OExW5Ph0RPByteRjVpqLsCF43KlrJXLKQjXKXHFZKw2C2d5oazXf496 bNSobNj+GOksp46XDdSVa7bSc8L8k9+UBzgevYIWKXoXhJfzHokEETgHIOblSCwth2aZ KyIJ9j7Uf5Lq0tJwuVBrUJ9DNOKWVpQEceC8jk4BjDjiqtMlyuGk1iVTlV5zLFr8phTI TmZw== X-Gm-Message-State: AOAM533+BsaxEMw/bCELERjvUDbxVDnlCx/9RnnZQazNbF5DVEAj++Cv XNCTmvBo87YIH0FCwIzomoAiDdee8meXWl3ju5HhF/5pcCtOifT8SOCCvEqkla1VBiYCB5VSI9h F+kIP2c9sMSMhrjXTa0A/izqWLUUIgXVuGpG4ylZQ+GYVUMzCnGRk23ZSQ/tT6A== X-Received: by 2002:a5d:4707:: with SMTP id y7mr29386481wrq.396.1619027919018; Wed, 21 Apr 2021 10:58:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRIbNch9AodhCGdBqCgSRTqAWsy+DVD4Vpx62dHqitnPhzug005adMYs8+xL1fpyoxMig3bg== X-Received: by 2002:a5d:4707:: with SMTP id y7mr29386444wrq.396.1619027918717; Wed, 21 Apr 2021 10:58:38 -0700 (PDT) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id l14sm84790wmq.4.2021.04.21.10.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 10:58:38 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , John Paul Adrian Glaubitz , Javier Martinez Canillas Subject: [RFC PATCH] util/mkimage: Fix wrong PE32+ section sizes for some arches Date: Wed, 21 Apr 2021 19:58:36 +0200 Message-Id: <20210421175836.985011-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=170.10.133.124; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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=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: Wed, 21 Apr 2021 17:58:46 -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. But for some platforms (i.e: ia64 and aa64) the kernel image size wasn't aligned using the section alignment, which causes the PE section headers to not match the actual section sizes in the PE32+ binary file. This caused problems on ia64 EFI machines, since the .data section size is bigger than the actual section in the PE32+ binary, overlapping with part of the mods section. That leads to GRUB not being able to load any built-in module. Fix it by aligning the kernel_size to the section alignment, that makes the sizes and offsets in the PE section headers to match the sections in the PE32+ binary file. Reported-by: John Paul Adrian Glaubitz Signed-off-by: Javier Martinez Canillas --- Hello, this is an RFC because I want someone else more familiar with this to double check that this approach is sane. It would be also useful if someone can test on an aarch64 machine, I have compared the generated EFI binaries and are the same in both cases. But still it seems to me that an explicit alignment is needed for EM_AARCH64. Best regards, Javier util/grub-mkimagexx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 00f49ccaaaf..2d0c9a0cb6b 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -2375,6 +2375,10 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, layout->got_off = layout->kernel_size; layout->kernel_size += ALIGN_UP (layout->got_size, 16); + + if (image_target->id == IMAGE_EFI) + layout->kernel_size = ALIGN_UP (layout->kernel_size, + image_target->section_align); } if (image_target->elf_target == EM_AARCH64) { @@ -2386,6 +2390,11 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, layout->got_off = layout->kernel_size; layout->kernel_size += ALIGN_UP (layout->got_size, 16); + + + if (image_target->id == IMAGE_EFI) + layout->kernel_size = ALIGN_UP (layout->kernel_size, + image_target->section_align); } #endif } -- 2.31.1