From nobody Fri Oct 3 15:33:18 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 464B831159A for ; Fri, 29 Aug 2025 10:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756464877; cv=none; b=fE5VSEr6++jbc56u9+8qN5sWFJZf68ACjQ8xYeurg46fZKvaTQZ5L5NXrvVFeYn6LvhVmGOSH97D8aI/owu2EYMYM+PCuuqS59hUPdJdIbS8u83e+x5KAACRlHAINIl1m5zL9m0aB41uX19sJhVTPkdO2QbLonH2nXchPo3Rl84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756464877; c=relaxed/simple; bh=XdwddMlnNDe/bejk9AlmOKSmzkod84XNORyHGHdp5tQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UZCsRz8IpjDIMGZ9ky0Xqjtltk+94yVVBO1oag7OVJfWeFW5GCOYHLdqDM3uCTmhY0w440ssoPPv0tkIp50LziuuukQuhvo4fd1LdsAkYgI5qLQ82eZ1VJVUKdJyvXFA61oo1SMriVfD5CKJqzTeV7W9+hti/IPiwaIh1DRFHhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sidnayyar.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FVQZPi02; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sidnayyar.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FVQZPi02" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b0511b3so11380825e9.1 for ; Fri, 29 Aug 2025 03:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756464874; x=1757069674; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BZkdXrnu4rlNqr6nvqy7s2PHRCwIZIrYjOI0uDxkuo0=; b=FVQZPi02OrLY+h9w6d9mz/U2t/rLyG+ylXdwMosWOMbdcZ+D8FuWI9/iOm+E+BfE7s iddbFq8vl0Dd6aWZp6PWGhlltRGX8NCZFYRF0SQmvwYYCdljU851Lq82h8UwsIasU7H9 Xcyk3OJ1YlFJz++Gvev1cW9vzt52jsBv479Uki5WORzgUn0l2m6t3KkQAY3FcTrE9+qz w6JALXp8GB+LYZtcY+PwDp8c0jdVr70w5Saz33Jwde5yc34NZKNnFS6H5JEc9g3acN8c rNPGftRRi+fdCNF7w8KW6Mb2tC5qSxOZNIP3mLMcyHcUwWxbMlL9pw4pISElY5Wkddt3 aa9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756464874; x=1757069674; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BZkdXrnu4rlNqr6nvqy7s2PHRCwIZIrYjOI0uDxkuo0=; b=SUpJnm8PRTiEqMXRiVvmwbf9nan3TeTQR35m828gyDyJc1k6bGhHsT71rLz1DiTOgz q4pGFz0cG3v1+qOdJyey9WtcbfxAsoOBXG6IC7AknvGeMbjCHez1JNUQZasnFeLnprm6 9XM4+UBhE9vrL/YhFs4gN5zMR+sVVDxaJtoBMTTRZg0jxlD8NQuoTpkx+gxvF0Oc1GIw 1yR620eMQH9jYgt17GsBnQKU3laUrp7CKvBWRsYPGVXmI/rrfUGaCztd4r11xD5i3nmr A5EI19rpxVy+mX5jqLg9o5oIEif/loSqhr/M1KF8kcmnZzRey1rtGyyMRh5128rJIpjh Hz+A== X-Forwarded-Encrypted: i=1; AJvYcCVmVvJobrji0pTJCBqR5MA2/QGWd5LiqzKpl5PITbvPhc2tB6TQ29roV9YOPAjQ1ruWp+BDHL68XncVVr0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4+vwBlK8YjVGtHR4j20kMeWAq7vo3R5CcbUUBjirbwpQBejgd u4Qh0GM+WOy3TIFSWhDpbTZfb+s1BsTktXUiyQpoopbGcQenWvwHX5mjIR4p16GQWJvCSL2LgvN xEvFizsMSY3nObxaZCw== X-Google-Smtp-Source: AGHT+IETLQhhj0TWH9cTHkmUejWaasllcxIG4MgQGiEsNA2+oYnEukedB/VKaaNhilCldwAcOXfj5vhFRG0qg14= X-Received: from wmbee21.prod.google.com ([2002:a05:600c:6415:b0:459:dd4e:4446]) (user=sidnayyar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:19d4:b0:45b:6365:794e with SMTP id 5b1f17b1804b1-45b70ee5db1mr92752335e9.24.1756464873773; Fri, 29 Aug 2025 03:54:33 -0700 (PDT) Date: Fri, 29 Aug 2025 10:54:12 +0000 In-Reply-To: <20250829105418.3053274-1-sidnayyar@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250829105418.3053274-1-sidnayyar@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250829105418.3053274-5-sidnayyar@google.com> Subject: [PATCH 04/10] module loader: use kflagstab instead of *_gpl sections From: Siddharth Nayyar To: Nathan Chancellor , Luis Chamberlain , Sami Tolvanen Cc: Nicolas Schier , Petr Pavlu , Arnd Bergmann , linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, Siddharth Nayyar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Read __kflagstab section for vmlinux and modules to determine whether kernel symbols are GPL only. Signed-off-by: Siddharth Nayyar --- include/linux/module.h | 1 + kernel/module/internal.h | 1 + kernel/module/main.c | 47 ++++++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 3319a5269d28..9ba6ce433ac3 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -415,6 +415,7 @@ struct module { /* Exported symbols */ const struct kernel_symbol *syms; const u32 *crcs; + const u8 *flagstab; unsigned int num_syms; =20 #ifdef CONFIG_ARCH_USES_CFI_TRAPS diff --git a/kernel/module/internal.h b/kernel/module/internal.h index 618202578b42..69b84510e097 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -57,6 +57,7 @@ extern const struct kernel_symbol __start___ksymtab_gpl[]; extern const struct kernel_symbol __stop___ksymtab_gpl[]; extern const u32 __start___kcrctab[]; extern const u32 __start___kcrctab_gpl[]; +extern const u8 __start___kflagstab[]; =20 #define KMOD_PATH_LEN 256 extern char modprobe_path[]; diff --git a/kernel/module/main.c b/kernel/module/main.c index c66b26184936..400d59a7f44b 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -87,7 +88,7 @@ struct mod_tree_root mod_tree __cacheline_aligned =3D { struct symsearch { const struct kernel_symbol *start, *stop; const u32 *crcs; - enum mod_license license; + const u8 *flagstab; }; =20 /* @@ -364,19 +365,21 @@ static bool find_exported_symbol_in_section(const str= uct symsearch *syms, struct find_symbol_arg *fsa) { struct kernel_symbol *sym; - - if (!fsa->gplok && syms->license =3D=3D GPL_ONLY) - return false; + u8 sym_flags; =20 sym =3D bsearch(fsa->name, syms->start, syms->stop - syms->start, sizeof(struct kernel_symbol), cmp_name); if (!sym) return false; =20 + sym_flags =3D *(syms->flagstab + (sym - syms->start)); + if (!fsa->gplok && (sym_flags & KSYM_FLAG_GPL_ONLY)) + return false; + fsa->owner =3D owner; fsa->crc =3D symversion(syms->crcs, sym - syms->start); fsa->sym =3D sym; - fsa->license =3D syms->license; + fsa->license =3D (sym_flags & KSYM_FLAG_GPL_ONLY) ? GPL_ONLY : NOT_GPL_ON= LY; =20 return true; } @@ -387,36 +390,31 @@ static bool find_exported_symbol_in_section(const str= uct symsearch *syms, */ bool find_symbol(struct find_symbol_arg *fsa) { - static const struct symsearch arr[] =3D { - { __start___ksymtab, __stop___ksymtab, __start___kcrctab, - NOT_GPL_ONLY }, - { __start___ksymtab_gpl, __stop___ksymtab_gpl, - __start___kcrctab_gpl, - GPL_ONLY }, + const struct symsearch syms =3D { + .start =3D __start___ksymtab, + .stop =3D __stop___ksymtab, + .crcs =3D __start___kcrctab, + .flagstab =3D __start___kflagstab, }; struct module *mod; - unsigned int i; =20 - for (i =3D 0; i < ARRAY_SIZE(arr); i++) - if (find_exported_symbol_in_section(&arr[i], NULL, fsa)) - return true; + if (find_exported_symbol_in_section(&syms, NULL, fsa)) + return true; =20 list_for_each_entry_rcu(mod, &modules, list, lockdep_is_held(&module_mutex)) { - struct symsearch arr[] =3D { - { mod->syms, mod->syms + mod->num_syms, mod->crcs, - NOT_GPL_ONLY }, - { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, - mod->gpl_crcs, - GPL_ONLY }, + const struct symsearch syms =3D { + .start =3D mod->syms, + .stop =3D mod->syms + mod->num_syms, + .crcs =3D mod->crcs, + .flagstab =3D mod->flagstab, }; =20 if (mod->state =3D=3D MODULE_STATE_UNFORMED) continue; =20 - for (i =3D 0; i < ARRAY_SIZE(arr); i++) - if (find_exported_symbol_in_section(&arr[i], mod, fsa)) - return true; + if (find_exported_symbol_in_section(&syms, mod, fsa)) + return true; } =20 pr_debug("Failed to find symbol %s\n", fsa->name); @@ -2607,6 +2605,7 @@ static int find_module_sections(struct module *mod, s= truct load_info *info) sizeof(*mod->gpl_syms), &mod->num_gpl_syms); mod->gpl_crcs =3D section_addr(info, "__kcrctab_gpl"); + mod->flagstab =3D section_addr(info, "__kflagstab"); =20 #ifdef CONFIG_CONSTRUCTORS mod->ctors =3D section_objs(info, ".ctors", --=20 2.51.0.338.gd7d06c2dae-goog