Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lavYc-0002VG-C0 for mharc-grub-devel@gnu.org; Mon, 26 Apr 2021 03:21:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lavYX-0002Um-6P for grub-devel@gnu.org; Mon, 26 Apr 2021 03:21:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lavYT-0005xy-5q for grub-devel@gnu.org; Mon, 26 Apr 2021 03:21:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619421675; 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=e3lIqFG4sIDBpJbmODzwWChNIvZEargF1bP7gveKOgw=; b=AuJCH3xobDrtfzemgL18OwDP09wtXX4HpX6KyrZcqbPo9ju79sS8UnRnMlE1qv4wVE3v/R LZOQHAnwUSb+nNL5JeFHkFmnKr6bZJ6o4sWeDfGWbgq0cy429wW5Smk6m8HyFJ6VLsazJd Av9Y0asl8Q88JQvJBojeNDaWc/1uzO0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-wmNeRouxPYCSeSrQ8qqC0g-1; Mon, 26 Apr 2021 03:21:13 -0400 X-MC-Unique: wmNeRouxPYCSeSrQ8qqC0g-1 Received: by mail-wm1-f72.google.com with SMTP id g67-20020a1cb6460000b029014297bda128so29062wmf.1 for ; Mon, 26 Apr 2021 00:21: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=e3lIqFG4sIDBpJbmODzwWChNIvZEargF1bP7gveKOgw=; b=jlExi3p0+B/ZUaf41MJq0g/psXsTOQIDIUsyrphENBgANPcsS5VaVLZAZ32X0ENTv5 P0pXRWHDkaB2EKzsWLoRAcI4IVCu5NgHE5gyh/kahq5ObU2F7SesOfJAGhCnEnW1+liX eYFxzTYaGnd5QIO6wF+5cUNCJZw5nFG82r6TMEXuhutlQEoW7KesFM/JmkmAvTMdno+r pOqc7OWcYcRuY6Mij+IEIr/voCp3QGIG1bUdlpQ3ElzL7O77vcgOyVmnRvHYPUiO4i8N VKCjye6yl+Wdwi1IjMnglgeLBzcX7X8kZgCk7LXt61oUOILlAVjGTk9sBzUW1t0jNbJx e+Pw== X-Gm-Message-State: AOAM530yDnJSPhJKPSX3BnB8dSG8kdNp06wD3TSqWe0L9jnlJQv8az5+ Bu4um8U7S3LoGeeBC9tsgfxCiDGPFWEWE561UTYkx4Oz6ccQbfDZakd8SlNuzXObbQqVTBwB1+r XSwOp6YibtYrAqoEmhESsGamQzb977cDp8UJWic8qgPm5sAOcPcA1DXq/WaAbdQ== X-Received: by 2002:adf:e60d:: with SMTP id p13mr11334732wrm.326.1619421671893; Mon, 26 Apr 2021 00:21:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvqorLxQPmtUE2kBEIeDYuNpCr21a64qEHNdZWNHbd2/LYaeWCIH0MDRE7V4ovfKyRqpCEzg== X-Received: by 2002:adf:e60d:: with SMTP id p13mr11334703wrm.326.1619421671645; Mon, 26 Apr 2021 00:21:11 -0700 (PDT) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id t206sm16393144wmb.11.2021.04.26.00.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 00:21:11 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , John Paul Adrian Glaubitz , Javier Martinez Canillas Subject: [RFC PATCH v2] util/mkimage: Fix wrong PE32+ section sizes for some arches Date: Mon, 26 Apr 2021 09:21:02 +0200 Message-Id: <20210426072102.1531425-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.01, RCVD_IN_MSPIKE_WL=-0.01, 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: Mon, 26 Apr 2021 07:21:21 -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 --- 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 00f49ccaaaf..73646f12f14 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -2388,6 +2388,11 @@ 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 + image_target->vaddr_offset, + image_target->section_align) + - image_target->vaddr_offset; } else { -- 2.31.1