On Mon, Sep 8, 2025 at 11:09 AM Petr Pavlu <petr.pa...@suse.com> wrote: > This sounds reasonable to me. Do you have any numbers on hand that would > show the impact of extending __ksymtab?
I did performance analysis for module loading. The kflagstab optimizes symbol search, which accounts for less than 2% of the average module load time. Therefore, this change does not translate into any meaningful gains (or losses) in module loading performance. On the binary size side, the on-disk size for vmlinux is somewhat inflated due to extra entries in .symtab and .strtab. Since these sections are not part of the final Image, the only increase in the in-memory size of the kernel is for the kflagstab itself. This new table occupies 1 byte for each symbol in the ksymtab. > > The Android Common Kernel source is compiled into what we call > > GKI (Generic Kernel Image), which consists of a kernel and a > > number of modules. We maintain a stable interface (based on CRCs and > > types) between the GKI components and vendor-specific modules > > (compiled by device manufacturers, e.g., for hardware-specific > > drivers) for the lifetime of a given GKI version. > > > > This interface is intentionally restricted to the minimal set of > > symbols required by the union of all vendor modules; our partners > > declare their requirements in symbol lists. Any additions to these > > lists are reviewed to ensure kernel internals are not overly exposed. > > For example, we restrict drivers from having the ability to open and > > read arbitrary files. This ABI boundary also allows us to evolve > > internal kernel types that are not exposed to vendor modules, for > > example, when a security fix requires a type to change. > > > > The mechanism we use for this is CONFIG_TRIM_UNUSED_KSYMS and > > CONFIG_UNUSED_KSYMS_WHITELIST. This results in a ksymtab > > containing two kinds of exported symbols: those explicitly required > > by vendors ("vendor-listed") and those only required by GKI modules > > ("GKI use only"). > > > > On top of this, we have implemented symbol import protection > > (covered in patches 9/10 and 10/10). This feature prevents vendor > > modules from using symbols that are not on the vendor-listed > > whitelist. It is built on top of CONFIG_MODULE_SIG. GKI modules are > > signed with a specific key, while vendor modules are unsigned and thus > > treated as untrusted. This distinction allows signed GKI modules to > > use any symbol in the ksymtab, while unsigned vendor modules can only > > access the declared subset. This provides a significant layer of > > defense and security against potentially exploitable vendor module > > code. > > If I understand correctly, this is similar to the recently introduced > EXPORT_SYMBOL_FOR_MODULES() macro, but with a coarser boundary. > > I think that if the goal is to control the kABI scope and limit the use > of certain symbols only to GKI modules, then having the protection > depend on whether the module is signed is somewhat odd. It doesn't give > me much confidence if vendor modules are unsigned in the Android > ecosystem. I would expect that you want to improve this in the long > term. GKI modules are the only modules built in the same Kbuild as the kernel image, which Google builds and provides to partners. In contrast, vendor modules are built and packaged entirely by partners. Google signs GKI modules with ephemeral keys. Since partners do not have these keys, vendor modules are treated as unsigned by the kernel. To ensure the authenticity of these unsigned modules, partners package them into a separate image that becomes one of the boot partitions. This entire image is signed, and its signature is verified by the bootloader at boot time. > It would then make more sense to me if the protection was determined by > whether the module is in-tree (the "intree" flag in modinfo) or, > alternatively, if it is signed by a built-in trusted key. I feel this > way the feature could be potentially useful for other distributions that > care about the kABI scope and have ecosystems where vendor modules are > properly signed with some key. However, I'm not sure if this would still > work in your case. Partners can produce both in-tree and out-of-tree modules. We do not trust either type regarding symbol exposure, as there is no way to know exactly what sources were used. Furthermore, symbols exported via EXPORT_SYMBOL_FOR_MODULES can be accessed by any vendor module that mimics the GKI module name. Therefore, neither the in-tree flag nor the EXPORT_SYMBOL_FOR_MODULES mechanism provides a strong enough guarantee for the Android kernel to identify GKI modules. Only module signatures are sufficient to allow a module to access the full set of exported symbols. Unsigned vendor modules may only access the symbol subset declared ahead of time by partners. In case such symbol protection is not useful for the Linux community, I am happy to keep this as an Android-specific feature. However, I would urge you to at least accept the kflagstab, as it allows us (and potentially other Linux distributions) to easily introduce additional flags for symbols. It is also a simplification/clean-up of the module loader code. -- Thanks, Siddharth Nayyar