From nobody Thu Apr 9 23:23:26 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 7FF653D75DE for ; Thu, 5 Mar 2026 16:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772729676; cv=none; b=fPXgtnrTEShE2v/8gwnKm4MXphtR4hWi1MpwVx4g/qxUiQ1jAaXoQ43KCrmEVQmyH9xtPZDHrSFf+lOyHfUUL8Ig8CP+0fgMsf4Igh086Tp66q1rJVUbIHqjcO0DezGlNbxleOA1RCro3hsFw3eKiRwcVt/wMLDnTf0uk49Crvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772729676; c=relaxed/simple; bh=TpZmRegtqEbXTTVHSkwGbHY5Ll9KMK2Mxg+dapA2VWM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NwD7SoEOEV4nJW7tfrHK7QrtYb8PXxt1+ZN0//LMHUNnaYhK63dP5uGlxff8LIsIHd9E6mtsSam32FesciBDcjpKaDP9gq9pEKTl5/WsxVv5lhVZKGUJFDGXLvq4w4uPmiy6TIdv7LMUnqrHrQ42f9HXic7PFhPQayfodp0Bofk= 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=bQrUUkam; arc=none smtp.client-ip=209.85.221.74 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="bQrUUkam" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-439aa1d898cso4906051f8f.2 for ; Thu, 05 Mar 2026 08:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772729673; x=1773334473; 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=kH4l5sUjOP0TtrWWkDh0aa89yXT1o3HsEp7IF0XRzwQ=; b=bQrUUkamxN1QkJYCeRefJ2D3tyeyokD5aDFT/QmtFslOeekId7+b0YOX+53+m9ccJL p9/21KJQZGb+TYYaoWsAuBn5U3N3ihZy7t2QpGgKoDaA3Ajmkfiekwz/GNVuwzAhjciA 9B5EPQ9phmRMBr31t1xbPtPr0Whu9DsXtxDLcUlpSzTJFffZYgCLopHOF3Lkb1Set+Kq 0Mf2wyara4QitFhem9FfEeLPV/ovR6yJoO7CDzeK8ey/8fcWW1LVjSiqA12VRvdELWsz Mpgc/QStXWlC5ixDfczhbY9IFxG8JMrEFmzqjg5e38YvkvEfvthSYunoik+1a9BMBNyN Azjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772729673; x=1773334473; 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=kH4l5sUjOP0TtrWWkDh0aa89yXT1o3HsEp7IF0XRzwQ=; b=RikczWDLWGvjVJOt4W59yBSoYcV9bpszUdn3SjCTEsxL9dwvdLyyaZuqTLdj4LDJBw 7klOSNxu6ULqvzKVvubeP0llItP6vTi7W4ZJSMDmgIN7TrJ/kFzFVkc45ZUWFzWaCRo8 SOa9Z7IRxwdJ53+dxEgbiRiCaLLclyHxQzFyq9M/EMhyi3ytqsfsVgctWmA+hiRZekwn 0OF3RLst6cw2l5Wv+Hzdzw2BlpGRM8wc0rilyBeStOyiC/GuPNQGRiQIFq/iy9XKF40k eRh9RWgbFH/7ugV7C53fof2TQBYSOeCrpAZIxUMxWjd4yp4pCiyjCELD/CMtRG7OFmqG Z7nw== X-Forwarded-Encrypted: i=1; AJvYcCWAhoiUvEdOPK8w0FWAvoJ72DnecgQnlHv+5Eb3r2VLd7Vct87uXjx8hrXu/VoUs1JvtgaXNZAS13aKxzw=@vger.kernel.org X-Gm-Message-State: AOJu0YykJxj03yDOawUNE4UES5Em4FF+r6stZLIDGuVLVqhCzYqBHon6 MFIRGtr32PExhWkq7uRj4JNFGBhP31MeNfmCJ1bMOlvoZXVcKdh/HeWxAsejFc7qNFCtMp5qTCk o8W91IzDjM2O76e+obg== X-Received: from wrbgx17.prod.google.com ([2002:a05:6000:4711:b0:439:b92c:c91c]) (user=sidnayyar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2c10:b0:439:bce5:6518 with SMTP id ffacd0b85a97d-439c7fa448bmr11832934f8f.22.1772729672747; Thu, 05 Mar 2026 08:54:32 -0800 (PST) Date: Thu, 05 Mar 2026 16:54:24 +0000 In-Reply-To: <20260305-kflagstab-v4-0-4fe6eea27e30@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260305-kflagstab-v4-0-4fe6eea27e30@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260305-kflagstab-v4-4-4fe6eea27e30@google.com> Subject: [PATCH v4 4/8] module loader: use kflagstab instead of *_gpl sections From: Siddharth Nayyar To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Arnd Bergmann , Nathan Chancellor , Nicolas Schier , Jonathan Corbet , Shuah Khan Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, Siddharth Nayyar , maennich@google.com, gprocida@google.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Read kflagstab section for vmlinux and modules to determine whether kernel symbols are GPL only. This patch eliminates the need for fragmenting the ksymtab for infering the value of GPL-only symbol flag. The fragmentation of ksymtab is removed in subsequent patches. Signed-off-by: Siddharth Nayyar --- include/linux/module.h | 1 + kernel/module/internal.h | 1 + kernel/module/main.c | 55 +++++++++++++++++++++++++-------------------= ---- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 14f391b186c6..aee3accba73c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -418,6 +418,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 c3ce106c70af..d237fa4e0737 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); @@ -2614,6 +2612,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", @@ -2817,8 +2816,12 @@ static int move_module(struct module *mod, struct lo= ad_info *info) return ret; } =20 -static int check_export_symbol_versions(struct module *mod) +static int check_export_symbol_sections(struct module *mod) { + if (mod->num_syms && !mod->flagstab) { + pr_err("%s: no flags for exported symbols\n", mod->name); + return -ENOEXEC; + } #ifdef CONFIG_MODVERSIONS if ((mod->num_syms && !mod->crcs) || (mod->num_gpl_syms && !mod->gpl_crcs)) { @@ -3434,7 +3437,7 @@ static int load_module(struct load_info *info, const = char __user *uargs, if (err) goto free_unload; =20 - err =3D check_export_symbol_versions(mod); + err =3D check_export_symbol_sections(mod); if (err) goto free_unload; =20 --=20 2.53.0.473.g4a7958ca14-goog