[PATCH v2 3/5] rust: kernel: add LSM abstraction layer

kernel test robot lkp at intel.com
Wed Mar 11 12:07:04 UTC 2026


Hi Jamie,

kernel test robot noticed the following build errors:

[auto build test ERROR on rust/rust-next]
[also build test ERROR on linus/master v7.0-rc3 next-20260310]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jamie-Lindsey/rust-helpers-add-C-shims-for-LSM-hook-initialisation/20260311-131258
base:   https://github.com/Rust-for-Linux/linux rust-next
patch link:    https://lore.kernel.org/r/0102019cdb4c705e-7d46b4f3-5cbb-4a6a-b315-e10f182fa987-000000%40eu-west-1.amazonses.com
patch subject: [PATCH v2 3/5] rust: kernel: add LSM abstraction layer
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260311/202603111327.ZxGK7MvE-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260311/202603111327.ZxGK7MvE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp at intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603111327.ZxGK7MvE-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

>> warning: unresolved link to `define_lsm`
   --> rust/kernel/lsm.rs:7:46
   |
   7 | //! registers itself at boot time with the [`define_lsm!`] macro.
   |                                              ^^^^^^^^^^^ no item named `define_lsm` in scope
   |
   = note: `macro_rules` named `define_lsm` exists in this crate, but it is not in scope at this link's location
   = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
--
   PATH=/opt/cross/clang-20/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
   INFO PATH=/opt/cross/rustc-1.88.0-bindgen-0.72.1/cargo/bin:/opt/cross/clang-20/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
   /usr/bin/timeout -k 100 12h /usr/bin/make KCFLAGS=\ -fno-crash-diagnostics\ -Wno-error=return-type\ -Wreturn-type\ -funsigned-char\ -Wundef\ -falign-functions=64 W=1 --keep-going LLVM=1 -j32 -C source O=/kbuild/obj/consumer/x86_64-rhel-9.4-rust ARCH=x86_64 SHELL=/bin/bash rustfmtcheck 
   make: Entering directory '/kbuild/src/consumer'
   make[1]: Entering directory '/kbuild/obj/consumer/x86_64-rhel-9.4-rust'
>> Diff in rust/kernel/lsm.rs:120:
        /// `file` must be a valid, non-null pointer to a `struct file` that
        /// remains valid for the duration of this call.  Called only by the
        /// LSM framework.
   -    pub unsafe extern "C" fn file_open(
   -        file: *mut bindings::file,
   -    ) -> core::ffi::c_int {
   +    pub unsafe extern "C" fn file_open(file: *mut bindings::file) -> core::ffi::c_int {
            // SAFETY: The LSM framework guarantees `file` is valid and non-null
            // for the duration of this call.
            let file_ref = unsafe { File::from_raw_file(file.cast_const()) };
   Diff in rust/kernel/lsm.rs:190:
        // SAFETY: `bindings::lsm_info` is a C struct.  Zero-initialisation
        // gives valid zero/null values for every optional field.  The caller
        // is responsible for providing a valid `id` and `init`.
   -    let mut info: bindings::lsm_info =
   -        unsafe { MaybeUninit::zeroed().assume_init() };
   +    let mut info: bindings::lsm_info = unsafe { MaybeUninit::zeroed().assume_init() };
        info.id = id;
        info.init = init;
        LsmInfo(info)
   Diff in rust/kernel/lsm.rs:230:
                // The LSM identity — must be 'static because the static-call
                // table holds a back-pointer to it via security_hook_list.lsmid.
                // LsmId wraps lsm_id with `unsafe impl Sync` so it can be `static`.
   -            static __LSM_ID: $crate::lsm::LsmId =
   -                $crate::lsm::LsmId($crate::bindings::lsm_id {
   -                    name: $name.as_ptr().cast(),
   -                    id: $id,
   -                });
   +            static __LSM_ID: $crate::lsm::LsmId = $crate::lsm::LsmId($crate::bindings::lsm_id {
   +                name: $name.as_ptr().cast(),
   +                id: $id,
   +            });
    
                // The hook list array.  MaybeUninit avoids needing security_hook_list
                // to implement a const-initialiser; the C shims fill each slot in
   Diff in rust/kernel/lsm.rs:242:
                //
                // SAFETY: This array must be 'static — the static-call table holds
                // back-pointers (scall->hl) into it after registration.
   -            static mut __LSM_HOOKS: [
   -                ::core::mem::MaybeUninit<$crate::bindings::security_hook_list>;
   -                3
   -            ] = [::core::mem::MaybeUninit::zeroed(); 3];
   +            static mut __LSM_HOOKS: [::core::mem::MaybeUninit<
   +                $crate::bindings::security_hook_list,
   +            >; 3] = [::core::mem::MaybeUninit::zeroed(); 3];
    
                // The init function stored in lsm_info.init.  Called once by
                // security_init() in single-threaded boot context.
   Diff in rust/kernel/lsm.rs:283:
                #[link_section = ".lsm_info.init"]
                static __LSM_INFO: $crate::lsm::LsmInfo = {
                    // SAFETY: __LSM_ID and __lsm_init have 'static lifetime.
   -                unsafe {
   -                    $crate::lsm::new_lsm_info(
   -                        &raw const __LSM_ID.0,
   -                        Some(__lsm_init),
   -                    )
   -                }
   +                unsafe { $crate::lsm::new_lsm_info(&raw const __LSM_ID.0, Some(__lsm_init)) }
                };
            }
        };
>> Diff in rust/kernel/lsm.rs:120:
        /// `file` must be a valid, non-null pointer to a `struct file` that
        /// remains valid for the duration of this call.  Called only by the
        /// LSM framework.
   -    pub unsafe extern "C" fn file_open(
   -        file: *mut bindings::file,
   -    ) -> core::ffi::c_int {
   +    pub unsafe extern "C" fn file_open(file: *mut bindings::file) -> core::ffi::c_int {
            // SAFETY: The LSM framework guarantees `file` is valid and non-null
            // for the duration of this call.
            let file_ref = unsafe { File::from_raw_file(file.cast_const()) };
   Diff in rust/kernel/lsm.rs:190:
        // SAFETY: `bindings::lsm_info` is a C struct.  Zero-initialisation
        // gives valid zero/null values for every optional field.  The caller
        // is responsible for providing a valid `id` and `init`.
   -    let mut info: bindings::lsm_info =
   -        unsafe { MaybeUninit::zeroed().assume_init() };
   +    let mut info: bindings::lsm_info = unsafe { MaybeUninit::zeroed().assume_init() };
        info.id = id;
        info.init = init;
        LsmInfo(info)
   Diff in rust/kernel/lsm.rs:230:
                // The LSM identity — must be 'static because the static-call
                // table holds a back-pointer to it via security_hook_list.lsmid.
                // LsmId wraps lsm_id with `unsafe impl Sync` so it can be `static`.
   -            static __LSM_ID: $crate::lsm::LsmId =
   -                $crate::lsm::LsmId($crate::bindings::lsm_id {
   -                    name: $name.as_ptr().cast(),
   -                    id: $id,
   -                });
   +            static __LSM_ID: $crate::lsm::LsmId = $crate::lsm::LsmId($crate::bindings::lsm_id {
   +                name: $name.as_ptr().cast(),
   +                id: $id,
   +            });
    
                // The hook list array.  MaybeUninit avoids needing security_hook_list
                // to implement a const-initialiser; the C shims fill each slot in
   Diff in rust/kernel/lsm.rs:242:
                //
                // SAFETY: This array must be 'static — the static-call table holds
                // back-pointers (scall->hl) into it after registration.
   -            static mut __LSM_HOOKS: [
   -                ::core::mem::MaybeUninit<$crate::bindings::security_hook_list>;
   -                3
   -            ] = [::core::mem::MaybeUninit::zeroed(); 3];
   +            static mut __LSM_HOOKS: [::core::mem::MaybeUninit<
   +                $crate::bindings::security_hook_list,
   +            >; 3] = [::core::mem::MaybeUninit::zeroed(); 3];
    
                // The init function stored in lsm_info.init.  Called once by
                // security_init() in single-threaded boot context.
   Diff in rust/kernel/lsm.rs:283:
                #[link_section = ".lsm_info.init"]
                static __LSM_INFO: $crate::lsm::LsmInfo = {
                    // SAFETY: __LSM_ID and __lsm_init have 'static lifetime.
   -                unsafe {
   -                    $crate::lsm::new_lsm_info(
   -                        &raw const __LSM_ID.0,
   -                        Some(__lsm_init),
   -                    )
   -                }
   +                unsafe { $crate::lsm::new_lsm_info(&raw const __LSM_ID.0, Some(__lsm_init)) }
                };
            }
        };
   make[1]: Leaving directory '/kbuild/obj/consumer/x86_64-rhel-9.4-rust'
   make[1]: *** [Makefile:248: __sub-make] Error 2
   make[1]: Target 'rustfmtcheck' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2
   make[2]: *** [Makefile:1912: rustfmt] Error 123
   make: Target 'rustfmtcheck' not remade because of errors.
   make[2]: Target 'rustfmtcheck' not remade because of errors.
   make: Leaving directory '/kbuild/src/consumer'

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki



More information about the Linux-security-module-archive mailing list