From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mf8HQ-0003ps-Ak for mharc-grub-devel@gnu.org; Mon, 25 Oct 2021 18:17:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mf8HN-0003pG-Uc for grub-devel@gnu.org; Mon, 25 Oct 2021 18:17:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mf8HK-00048c-PG for grub-devel@gnu.org; Mon, 25 Oct 2021 18:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635200232; 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=afS1MIdJ+NMzqj2YJhyhOJdMP2nKbumY5PW0Q4VROfE=; b=P9Z7XO0JMHEWC/KwvomsoMOxkHjDUIt5Q5VCsDbmhUeIoYPQhcBcu9X/Z0DrGacctIAsfS f3588bJX4FyXUFbFf9hpcXURMfikp1tGQ1nc8f4Z34+yOWA3jMcy3ZnjJ+tl35mbwfdAmS lutNQVKJucfCK5jQW2AbIFY/jj+mSzM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-cnzR9fNXPNSQaAGpAHIGHw-1; Mon, 25 Oct 2021 18:17:11 -0400 X-MC-Unique: cnzR9fNXPNSQaAGpAHIGHw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CFCB8018AC for ; Mon, 25 Oct 2021 22:17:10 +0000 (UTC) Received: from eesha.redhat.com (unknown [10.22.50.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A60F60BF1; Mon, 25 Oct 2021 22:17:05 +0000 (UTC) From: Robbie Harwood To: grub-devel@gnu.org Cc: Robbie Harwood Subject: [PATCH v3] Print module name on license check failure Date: Mon, 25 Oct 2021 18:17:03 -0400 Message-Id: <20211025221703.168221-1-rharwood@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=rharwood@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=rharwood@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_H2=-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: Mon, 25 Oct 2021 22:17:18 -0000 Before performing the license check, resolve the module name so that it can be printed if the license check fails. Prior to this change, grub would only indicate that the check had been failed, but not by what module. This made it difficult to track down either the problem module, or debug the false positive further. Signed-off-by: Robbie Harwood --- grub-core/kern/dl.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 48f8a7907..363bacc43 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -457,14 +457,21 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) Be sure to understand your license obligations. */ static grub_err_t -grub_dl_check_license (Elf_Ehdr *e) +grub_dl_check_license (grub_dl_t mod, Elf_Ehdr *e) { Elf_Shdr *s = grub_dl_find_section (e, ".module_license"); - if (s && (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0 - || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0 - || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0)) + if (!s) + return grub_error (GRUB_ERR_BAD_MODULE, + "no license section in module %.64s", mod->name); + + if (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0) return GRUB_ERR_NONE; - return grub_error (GRUB_ERR_BAD_MODULE, "incompatible license"); + + return grub_error (GRUB_ERR_BAD_MODULE, + "incompatible license in module %.64s: %.64s", mod->name, + (char *) e + s->sh_offset); } static grub_err_t @@ -641,8 +648,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) constitutes linking) and GRUB core being licensed under GPLv3+. Be sure to understand your license obligations. */ - if (grub_dl_check_license (e) - || grub_dl_resolve_name (mod, e) + if (grub_dl_resolve_name (mod, e) + || grub_dl_check_license (mod, e) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) || grub_dl_resolve_symbols (mod, e) -- 2.33.0