|
| 1 | +# Lua-LSM Native Support |
| 2 | + |
| 3 | +Lua-LSM is a kernel-provided built-in Linux Security Module. Loongshield treats |
| 4 | +it as a runtime capability exposed through securityfs, not as another |
| 5 | +out-of-tree kernel module under `src/kmod/`. |
| 6 | + |
| 7 | +## Boundary |
| 8 | + |
| 9 | +Loongshield owns: |
| 10 | + |
| 11 | +- readiness checks for the running kernel |
| 12 | +- policy validation before explicit load |
| 13 | +- securityfs read/write orchestration |
| 14 | +- operator CLI and packaging of example policies |
| 15 | +- fake-securityfs tests for normal CI |
| 16 | + |
| 17 | +The kernel owns: |
| 18 | + |
| 19 | +- `CONFIG_LUA` |
| 20 | +- `CONFIG_SECURITY_LUA_LSM` |
| 21 | +- LSM hook registration |
| 22 | +- `/sys/kernel/security/lua/*` |
| 23 | +- policy execution inside the kernel Lua VM |
| 24 | + |
| 25 | +## Runtime ABI |
| 26 | + |
| 27 | +The userspace manager talks to these securityfs files: |
| 28 | + |
| 29 | +- `version` |
| 30 | +- `register` |
| 31 | +- `unregister` |
| 32 | +- `modules` |
| 33 | +- `stats` |
| 34 | +- `lsm_funcs` |
| 35 | + |
| 36 | +Only `register` and `unregister` are written. The CLI checks effective |
| 37 | +`CAP_MAC_ADMIN` before writes so operators get a clear userspace error before |
| 38 | +the kernel rejects the write. |
| 39 | + |
| 40 | +## Package Layout |
| 41 | + |
| 42 | +Bundled example policies are installed under: |
| 43 | + |
| 44 | +```text |
| 45 | +/etc/loongshield/lua-lsm/policies.d/ |
| 46 | +``` |
| 47 | + |
| 48 | +The example manifest is informational and does not trigger autoload: |
| 49 | + |
| 50 | +```text |
| 51 | +profiles/lua-lsm/manifest.yml |
| 52 | +``` |
| 53 | + |
| 54 | +## Safety Gate |
| 55 | + |
| 56 | +The feature remains experimental because the inspected Lua-LSM source tree has |
| 57 | +documented high-risk audit findings, including memory lifetime, refcount, RCU, |
| 58 | +and hook contract issues. Loongshield therefore does not auto-load policies and |
| 59 | +marks the CLI surface as experimental in status/help/docs. |
| 60 | + |
| 61 | +Before production use, either fix the kernel audit blockers or enforce a |
| 62 | +conservative policy allowlist in Loongshield that only permits audited hook |
| 63 | +wrappers. |
| 64 | + |
| 65 | +## Test Strategy |
| 66 | + |
| 67 | +Normal CI uses a fake securityfs root through |
| 68 | +`LOONGSHIELD_LUA_LSM_SECURITYFS_ROOT` or direct module options. That covers |
| 69 | +status, doctor, list, load, unload, stats, and hooks behavior without requiring |
| 70 | +privileged kernel state. |
| 71 | + |
| 72 | +Privileged end-to-end coverage should run in a VM with: |
| 73 | + |
| 74 | +```text |
| 75 | +CONFIG_SECURITY=y |
| 76 | +CONFIG_SECURITYFS=y |
| 77 | +CONFIG_LUA=y |
| 78 | +CONFIG_SECURITY_LUA_LSM=y |
| 79 | +CONFIG_LSM=...,lua,... |
| 80 | +``` |
| 81 | + |
| 82 | +The VM test should load a narrow policy, prove the target hook behavior, unload |
| 83 | +the policy, and verify the behavior is gone. |
0 commit comments