Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
63c98fd
nomount: implement whiteouts
maxsteeel Jun 26, 2026
70e3fae
verify parent_inode->i_sb to avoid NULL pointer dereference
maxsteeel Jun 26, 2026
8222b3e
omit sandboxed/isolated processes
maxsteeel Jun 26, 2026
2ce12c9
remove whiteout logic of handle_getname, optimizations
maxsteeel Jun 26, 2026
09541f1
kernel: optimize memory layout and VFS hot path execution
maxsteeel Jun 27, 2026
1799379
test i_op hijacking
maxsteeel Jun 27, 2026
844ebf4
test s_op hijacking, organize code
maxsteeel Jun 28, 2026
84fa23b
test f_op hijacking
maxsteeel Jun 28, 2026
baebab0
refactor this whole thing of hijacking
maxsteeel Jun 29, 2026
b162778
trying to fix bootloops
maxsteeel Jun 29, 2026
ba5e044
remove nocfi
maxsteeel Jun 30, 2026
b32768d
fix bitwise comprobation in parent permissions
maxsteeel Jun 30, 2026
557c0c9
restore permission hook, test d_op hijacking
maxsteeel Jun 30, 2026
a564c54
optimize getname hook
maxsteeel Jul 1, 2026
89186ac
optimize spoof mmap metadata hook, remove unused helper
maxsteeel Jul 1, 2026
14a4329
skip whiteout comprobation in nomount_actor_proxy if no whiteout
maxsteeel Jul 1, 2026
262e8fe
remove hijacking permission hooks, hijack i_op of parent dirs
maxsteeel Jul 1, 2026
c5aca51
remove deprecated hooks
maxsteeel Jul 1, 2026
b757a87
organize code, fix compilation on >5.12 kernels
maxsteeel Jul 1, 2026
7dacb49
spoof entire kstatfs
maxsteeel Jul 1, 2026
11793d2
convert NOMOUNT_VERSION in a string
maxsteeel Jul 1, 2026
0c0dd70
fix add / delete bug in userspace
maxsteeel Jul 1, 2026
0e52f47
refactor: delete nomount_inodes_ht, nomount_inode_node
maxsteeel Jul 1, 2026
6dd08a0
retrying hijacking permissions again, organize code
maxsteeel Jul 2, 2026
fe34c64
fix compilation errors
maxsteeel Jul 2, 2026
923aced
trying to bypass selinux
maxsteeel Jul 2, 2026
a614d06
remove deprecated `nomount_handle_permission` hook
maxsteeel Jul 3, 2026
90c0937
restore comprobations in `nomount_handle_getname`
maxsteeel Jul 3, 2026
2a22610
hookless
maxsteeel Jul 5, 2026
57f1a06
remove alias engine
maxsteeel Jul 5, 2026
e50dd53
eliminate whiteout comprobation in `nomount_actor_proxy`
maxsteeel Jul 5, 2026
b61b8cc
fs: nomount: add missing #include <linux/module.h>
cvnertnc Jul 6, 2026
44c4ca2
convert NOMOUNT_VERSION again in a number
maxsteeel Jul 8, 2026
f9cdc7d
refactor
maxsteeel Jul 18, 2026
7f6e910
replace children list to idr tree, refactor iterate_dir
maxsteeel Jul 23, 2026
178524b
refactor uid exclusions
maxsteeel Jul 23, 2026
d3b2f0c
remove `nomount_all_dirs_list`
maxsteeel Jul 23, 2026
a35519e
fix some kernel panics, memory leaks, and optimice netlink dump rules
maxsteeel Jul 23, 2026
b797cea
remove `nm_symlink_iops`, improve symlink handling
maxsteeel Jul 23, 2026
f580398
fix more bugs
maxsteeel Jul 23, 2026
f253203
kernel/src: add linux/file header for fput()
Neebe3289 Jul 24, 2026
a8a8b5c
userspace: fix ack bug and prevent overflow
maxsteeel Jul 24, 2026
d4535a8
userspace: replace bss buffer for stack-based buffer
maxsteeel Jul 24, 2026
0905925
replace `nomount_invalidate_cache` for a lazy invalidation in `nm_d_r…
maxsteeel Jul 24, 2026
cfd1262
kernel/src: fix declaration-after-statement in nomount_hijacked_itera…
Neebe3289 Jul 25, 2026
88379d6
kernel: reestructuring and refactoring...
maxsteeel Jul 25, 2026
5796359
kernel: implement unlink and rename support with COW rule operations
maxsteeel Jul 25, 2026
b8d397d
add multi-uid support
maxsteeel Jul 25, 2026
ee56b82
rename internal dir flag to virtual dir, show virtual dir flag in use…
maxsteeel Jul 25, 2026
617c662
implement uid exclusion list, adapt webui to the new uid exclusion list
maxsteeel Jul 25, 2026
58d579b
fix "format %llu expects unsigned long long, but inode->i_ino is unsi…
maxsteeel Jul 25, 2026
2c96934
kernel: remove stat size/blocks spoofing
maxsteeel Jul 27, 2026
c422152
kernel: GKI-wide compile compat + dcache fixes (#31)
Bouteillepleine Jul 28, 2026
847e8bd
kernel: fix UAF risks, implement a lazy cleanup of dir_node
maxsteeel Jul 29, 2026
b85be15
kernel: DCACHE_DONTCACHE the blocked reader's shadow dentry (#32)
Bouteillepleine Jul 29, 2026
647593c
kernel: implement correct cleanup of hijacked structures in nomount_r…
maxsteeel Jul 29, 2026
9f8eeba
kernel: remove unneeded unlink and rename functions
maxsteeel Jul 30, 2026
16f44c2
kernel: remove nm_root_cred
maxsteeel Jul 30, 2026
d860afe
kernel: some changes in nomount_hijacked_lookup
maxsteeel Jul 30, 2026
88dedae
kernel: implement statfs support
maxsteeel Jul 31, 2026
b541650
kernel: replace direct asignation of d_op with a hijacking of origina…
maxsteeel Jul 31, 2026
659567b
change vfs_getxattr / vfs_setxattr to __vfs_getxattr / __vfs_setattr
maxsteeel Aug 1, 2026
4443d7f
kernel: add dentry comprobation in nomount_create_new_inode
maxsteeel Aug 2, 2026
9b0f949
kernel: fix -EOPNOTSUPP in xattr handlers
maxsteeel Aug 3, 2026
ca21a4b
kernel: add S_PRIVATE flag to the real file to bypass LSM checks (dir…
maxsteeel Aug 3, 2026
e8a783d
kernel: remove S_PRIVATE flag after mapping the file (dirty fix)
maxsteeel Aug 3, 2026
b893eed
Revert "kernel: implement statfs support"
maxsteeel Aug 5, 2026
a86aaa2
kernel: remove unneeded `idr_preload()`
maxsteeel Aug 5, 2026
f819793
nomount: replace Generic Netlink API with IPC+Keyring API (#35)
maxsteeel Aug 6, 2026
1872cc0
kernel: use aligned pointer in idr_alloc to avoid Radix Tree collision
maxsteeel Aug 6, 2026
5f6c175
webui: correct exclusions toast
maxsteeel Aug 7, 2026
740ed47
workflow: update
maxsteeel Aug 7, 2026
c77c4c2
workflow: use TopTal minifier API for minify webui files
maxsteeel Aug 7, 2026
8e26737
kernel: add CAP_SYS_ADMIN check to keyring instantiate hook
maxsteeel Aug 7, 2026
ced40d4
workflow: use standalone esbuild binary + shell to minify webui files
maxsteeel Aug 7, 2026
62b97e9
kernel: remove `nomount_get_rule_locked`
maxsteeel Aug 7, 2026
1ae92ee
kernel: unify `nm_dops` into `nomount_hijack_dentry_ops`
maxsteeel Aug 7, 2026
eaf903a
kernel: fix RCU memory lifecycle
maxsteeel Aug 7, 2026
37886ee
kernel: remove redundancy in `nm_alloc_rule`
maxsteeel Aug 7, 2026
be9e926
kernel: improve memory management in `nomount_generate_virtual_topology`
maxsteeel Aug 8, 2026
024601e
kernel: remove unneeded `idr_preload()`
maxsteeel Aug 8, 2026
40e0196
kernel: remove unneeded and problematic iterate check in `nm_dir_iter…
maxsteeel Aug 8, 2026
3c713dd
kernel: improve RCU management in `nm_d_revalidate`
maxsteeel Aug 8, 2026
7a8aec9
kernel: fix use-after-free in dentry ops
maxsteeel Aug 8, 2026
8ac3b01
kernel: do not put S_PRIVATE flag into dir_ops
maxsteeel Aug 8, 2026
dcf2eff
kernel: remove inode->i_lock spinlock from `nomount_cure_sb_inodes`
maxsteeel Aug 8, 2026
2bafaea
kernel: remove unused nm_init_private_list() macro
maxsteeel Aug 8, 2026
5cdaf7b
kernel: use `KMEM_CACHE` macro instead of `kmem_cache_create`
maxsteeel Aug 8, 2026
1dacddf
kernel: refactor nm_process_ipc_payload
maxsteeel Aug 9, 2026
88209d9
kernel: use NOMOUNT_MAGIC_SIG as salt for hash operations
maxsteeel Aug 9, 2026
1a4bca9
kernel: replace magic signature checks with native VFS function valid…
maxsteeel Aug 9, 2026
8bdd8dd
kernel: add checks before overwriting vma->vm_file in mmap/mmap_prepare
maxsteeel Aug 9, 2026
8e42f9b
kernel: implement separated uid and rules cleanup
maxsteeel Aug 10, 2026
9319998
userspace: modernize and expand nm commands
maxsteeel Aug 10, 2026
95e4c8f
module: adapt to the new nm commands
maxsteeel Aug 10, 2026
ce3a991
kernel: simplify child deletion via direct rule pointer matching
maxsteeel Aug 10, 2026
054331e
workflow: reduce binary size adding some build flags
maxsteeel Aug 10, 2026
02365c5
userspace: use stack memory for payload instead of mmap
maxsteeel Aug 12, 2026
8ce6aca
kernel: remove unneeded memset in `nm_process_ipc_payload`
maxsteeel Aug 12, 2026
fc1a55f
userspace: use KEY_SPEC_THREAD_KEYRING ring in add_key()
maxsteeel Aug 12, 2026
5d5effe
module/webui: fix exclusion persistence and error toast
sarreos Aug 12, 2026
69a8a5b
kernel, userpace: rename functions and structs to maintain consistency
maxsteeel Aug 12, 2026
8850321
kernel: prevent UAF during rule shadowing by reparenting child nodes
maxsteeel Aug 12, 2026
6547245
kernel: add an script for kernel integration
maxsteeel Aug 13, 2026
c52936b
kernel: move all from fs/ to fs/nomount/, add Kconfig and Makefile
maxsteeel Aug 13, 2026
2fd6ef6
Small shadow/clear correctness follow-ups (#40)
Bouteillepleine Aug 13, 2026
a46b6d6
workflows: Add action script for building LKM (#41)
sarreos Aug 13, 2026
da05bd5
module, workflows: implement LKM support
maxsteeel Aug 13, 2026
776246f
kernel: ensure virtual children are emitted by deferring emitted coun…
maxsteeel Aug 13, 2026
a41d39b
module: handle system/odm hierarchy during metamodule path resolution
maxsteeel Aug 13, 2026
b157558
webui: handle system/odm hierarchy during hot load/unload
maxsteeel Aug 13, 2026
e8d383d
userspace: remove p_args[] expanding it to argc
maxsteeel Aug 14, 2026
379c778
userspace: fix compilation
maxsteeel Aug 14, 2026
190c797
kernel: change mutex lock by rwsem lock
maxsteeel Aug 14, 2026
e87a5a7
kernel: replace IDR with seqcount-protected RCU arrays and O(log N) b…
maxsteeel Aug 14, 2026
9e75d3b
kernel: fix stale whiteout cache by dropping negative dentries
maxsteeel Aug 14, 2026
59400be
kernel: fix compilation
maxsteeel Aug 14, 2026
a14d80e
kernel: fix open-dir UAF via v_inode tracking and fix bugs in nm_d_re…
maxsteeel Aug 14, 2026
b0fa231
kernel: avoid repeated code in nm_d_revalidate
maxsteeel Aug 14, 2026
ad71d9e
kernel: adopt Data-Oriented Design (SoA) for child hashes and optimiz…
maxsteeel Aug 14, 2026
a37b608
kernel: use contiguous memory arena for SoA child arrays to maximize …
maxsteeel Aug 14, 2026
0961c1a
module: implement hot LKM unload/load during instalation to update LK…
maxsteeel Aug 14, 2026
89712aa
module: restore install_lkm() in customize.sh
maxsteeel Aug 14, 2026
32ba4cf
kernel: migrate static hashtable to dynamic rbtree_cached
maxsteeel Aug 14, 2026
3cd6f64
module: prefer ksud insmod when available (#42)
947409161 Aug 14, 2026
3cebce9
kernel: fix UAF race in lookup via read rwsem to protect sleeping ino…
maxsteeel Aug 14, 2026
45f7033
kernel: proxy mmap through private shmem to prevent cross-filesystem …
maxsteeel Aug 13, 2026
04bdd04
kernel: advance offsets in nm_mmap shmem copy loop
Bouteillepleine Aug 14, 2026
4069690
kernel: bypass cross sb comprobations using COPY_FILE_SPLICE flag whe…
maxsteeel Aug 14, 2026
cd8dfaa
kernel: release shmem_file on the nm_mmap copy error path
Bouteillepleine Aug 14, 2026
d0f6bdd
kernel: fix nm_mmap vm_file refcount on the mmap failure path
Bouteillepleine Aug 14, 2026
637471b
kernel: fix nm_mmap panics by passing clean flags to shmem_file_setup
maxsteeel Aug 14, 2026
ebb4d7b
kernel: fix clang compilation error in nm_mmap
maxsteeel Aug 14, 2026
eb4df8c
kernel: fix compilation in kernels that not support COPY_FILE_SPLICE
maxsteeel Aug 15, 2026
8941c91
module: remove `ko-loader` binary from source code
maxsteeel Aug 15, 2026
9d8e73c
workflow: build `ko-loader` binary from source code
maxsteeel Aug 15, 2026
3987c73
kernel: MODULE_IMPORT_NS
maxsteeel Aug 16, 2026
e4ad7d5
fix(nm userspace): reset payload->arg1 before batched send to prevent…
nleloc Aug 16, 2026
c7ac026
kpm: build NoMount as a KernelPatch module for 6.6 and older
Bouteillepleine Aug 16, 2026
94e0c0e
kpm: compile matrix for every kernel KernelPatch can host
Bouteillepleine Aug 16, 2026
47cd02f
kernel: revert experimental shmem mmap'ing
maxsteeel Aug 17, 2026
81d113b
kernel, userspace: replace keyring-based api with /proc/keys .write h…
maxsteeel Aug 15, 2026
abb475b
kernel, userspace: unify payload protocol and optimize memory layout
maxsteeel Aug 17, 2026
a525130
kernel: implement srcu for sleepable readers
maxsteeel Aug 18, 2026
2e52744
kernel: remove redundant nm_child_array_rcu_free
maxsteeel Aug 18, 2026
76b0c1b
module: use nm binary from installed module if it exists
maxsteeel Aug 18, 2026
36ea0ff
kernel: pin the path of /proc/keys at hooking
maxsteeel Aug 18, 2026
d891f9c
kernel: keep payload offsets inside the mapped page
Bouteillepleine Aug 18, 2026
23a035b
webui: add Vietnamese translation
nleloc Aug 18, 2026
18ff8b7
webui: add module working mode badge
nleloc Aug 18, 2026
ee6c08c
module: symlink `nm` to KSU/APatch `bin`, abort installation on Magisk
nleloc Aug 17, 2026
0e7c2d0
module: add uninstall.sh to clean log and `exclution_list`
nleloc Aug 17, 2026
7f233d0
userspace: trying to bypass Android mount namespace isolation for /pr…
maxsteeel Aug 20, 2026
1d26c2f
kernel: optimizations
maxsteeel Aug 18, 2026
8d3fd49
kernel: testing generic_file_mmap
maxsteeel Aug 20, 2026
7f91783
kernel: hijack /dev/loop-control instead of /proc/keys
maxsteeel Aug 20, 2026
0806dea
kernel: extend retry intents for /dev hijack workqueue
maxsteeel Aug 21, 2026
300fed2
kernel, userspace: return back to keyring-based api
maxsteeel Aug 21, 2026
df84aa0
misc: update setup.sh and setup new ignore files/paths
maxsteeel Aug 23, 2026
28797f4
kernel: remove kernel patches
maxsteeel Aug 23, 2026
449a5ff
userspace: prevent segmentation fault with >1000 arguments
maxsteeel Aug 23, 2026
37398d2
Merge branch 'dev' into dev
Bouteillepleine Aug 24, 2026
e6a6c92
Merge remote-tracking branch 'upstream/dev' into KPM
Bouteillepleine Aug 24, 2026
65f1caa
kpm: resolve srcu and generic_file_mmap symbols via kallsyms shim
Bouteillepleine Aug 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .github/workflows/kpm-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: NoMount KPM — compile matrix

on:
push:
branches: [dev]
paths:
- 'kernel/kpm/**'
- 'kernel/src/**'
- '.github/workflows/kpm-matrix.yml'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: kpm-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: ${{ matrix.ver }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- { ver: '4.9', kref: 'deprecated/android-4.9-q', tc: gcc }
- { ver: '4.14', kref: 'deprecated/android-4.14-stable', tc: gcc }
- { ver: '4.19', kref: 'deprecated/android-4.19-stable', tc: gcc }
- { ver: '5.4', kref: 'android11-5.4', tc: gcc }
- { ver: '5.10', kref: 'android12-5.10', tc: clang }
- { ver: '5.15', kref: 'android13-5.15', tc: clang }
- { ver: '6.1', kref: 'android14-6.1', tc: clang }
- { ver: '6.6', kref: 'android15-6.6', tc: clang }
steps:
- uses: actions/checkout@v4
with: { path: repo }

- name: Toolchain
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq gcc-aarch64-linux-gnu bc flex bison libssl-dev libelf-dev \
clang lld llvm
echo "clang: $(clang --version | head -1)"

- name: KernelPatch headers
run: git clone --depth 1 https://github.com/741afb7/KPatch-Next-EXP kp

- name: Cache kernel clone
id: kcache
uses: actions/cache@v4
with:
path: ksrc
key: kpm-ksrc-${{ matrix.ver }}-${{ matrix.kref }}-v1

- name: Clone kernel ${{ matrix.kref }}
if: steps.kcache.outputs.cache-hit != 'true'
run: |
git clone --depth 1 -b "${{ matrix.kref }}" \
https://android.googlesource.com/kernel/common ksrc
head -3 ksrc/Makefile | tr '\n' ' '

- name: Configure kernel headers
run: |
set -e -o pipefail
cd ksrc
if [ "${{ matrix.tc }}" = "clang" ]; then
M="ARCH=arm64 LLVM=1 LLVM_IAS=1 CROSS_COMPILE=aarch64-linux-gnu- KCFLAGS=-Wno-error"
else
M="ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KCFLAGS=-Wno-error"
fi
if [ -f arch/arm64/configs/gki_defconfig ]; then
make $M gki_defconfig 2>&1 | tail -40
else
make $M defconfig 2>&1 | tail -40
fi
./scripts/config --disable KASAN --disable FORTIFY_SOURCE \
--disable DEBUG_LIST --disable PAGE_PINNER \
--disable LOCKDEP --disable PROVE_LOCKING \
--disable DEBUG_LOCK_ALLOC --disable TRACE_IRQFLAGS \
--disable DEBUG_ATOMIC_SLEEP || true
make $M olddefconfig 2>&1 | tail -20
make $M modules_prepare 2>&1 | tail -30
test -f include/generated/autoconf.h || { echo "::error::prepare produced no autoconf.h"; exit 1; }

- name: Build the engine object
run: |
set -o pipefail
cd repo/kernel/kpm
if [ "${{ matrix.tc }}" = "clang" ]; then
CCX="clang --target=aarch64-linux-gnu"
else
CCX="aarch64-linux-gnu-gcc"
fi
make CC="$CCX" TARGET_COMPILE=aarch64-linux-gnu- \
KP_DIR="$GITHUB_WORKSPACE/kp" \
KERNEL_DIR="$GITHUB_WORKSPACE/ksrc" \
nm_engine.o 2>&1 | tee /tmp/kpm.log
ls -l nm_engine.o && echo "ENGINE_OK ${{ matrix.ver }}"

- name: Undefined symbols
run: |
cd repo/kernel/kpm
U=$(aarch64-linux-gnu-nm -u nm_engine.o | awk '{print $2}' | sort -u | grep -v '^nm_kpm_sym$' || true)
N=$(printf '%s' "$U" | grep -c . || true)
echo "::notice::${{ matrix.ver }} undefined=$N"
[ "$N" = "0" ] && exit 0
printf '%s\n' "$U"
if [ "${{ matrix.tc }}" = "clang" ]; then CCX="clang --target=aarch64-linux-gnu"; else CCX="aarch64-linux-gnu-gcc"; fi
make CC="$CCX" TARGET_COMPILE=aarch64-linux-gnu- \
KP_DIR="$GITHUB_WORKSPACE/kp" KERNEL_DIR="$GITHUB_WORKSPACE/ksrc" \
COMMON_EXTRA=-ffunction-sections clean >/dev/null 2>&1 || true
$CCX -O2 -fno-stack-protector -fno-pic -ffreestanding -w -ffunction-sections \
-mgeneral-regs-only -nostdinc -isystem $($CCX -print-file-name=include) \
-I$GITHUB_WORKSPACE/ksrc/include -I$GITHUB_WORKSPACE/ksrc/include/uapi \
-I$GITHUB_WORKSPACE/ksrc/include/generated -I$GITHUB_WORKSPACE/ksrc/include/generated/uapi \
-I$GITHUB_WORKSPACE/ksrc/arch/arm64/include -I$GITHUB_WORKSPACE/ksrc/arch/arm64/include/uapi \
-I$GITHUB_WORKSPACE/ksrc/arch/arm64/include/generated \
-I$GITHUB_WORKSPACE/ksrc/arch/arm64/include/generated/uapi \
-include $GITHUB_WORKSPACE/ksrc/include/linux/kconfig.h \
-D__KERNEL__ -DMODULE -DKBUILD_MODNAME='"nomount"' \
-c -o /tmp/attr.o nm_engine.c 2>/dev/null || true
if [ -f /tmp/attr.o ]; then
for sym in $U; do
callers=$(aarch64-linux-gnu-objdump -r /tmp/attr.o 2>/dev/null \
| awk -v s="$sym" '/^RELOCATION RECORDS FOR/{sec=$0} $0 ~ ("[ \t]"s"$"){print sec}' \
| sed 's/.*\[\.text\.//; s/\]://' | sort -u | tr '\n' ' ')
if [ -n "$callers" ]; then
echo " $sym <- $callers"
else
echo " $sym <- (no .text ref) raw records:"
aarch64-linux-gnu-objdump -r /tmp/attr.o 2>/dev/null \
| grep -B40 "[ \t]$sym$" | grep "RELOCATION RECORDS" | tail -3 | sed 's/^/ /'
fi
done
fi
echo "::warning::${{ matrix.ver }} has $N unresolved symbol(s)"
47 changes: 47 additions & 0 deletions kernel/kpm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ifndef TARGET_COMPILE
$(error TARGET_COMPILE not set, e.g. aarch64-linux-android- or aarch64-linux-gnu-)
endif
ifndef KP_DIR
$(error KP_DIR not set: checkout of KernelPatch / KPatch-Next-EXP)
endif
ifndef KERNEL_DIR
$(error KERNEL_DIR not set: configured kernel source for the TARGET KMI (<= 6.6))
endif

CC ?= $(TARGET_COMPILE)gcc
LD ?= $(TARGET_COMPILE)ld

KP_INCLUDE_DIRS := . include patch/include linux/include linux/arch/arm64/include \
linux/tools/arch/arm64/include
KP_FLAGS := $(foreach d,$(KP_INCLUDE_DIRS),-I$(KP_DIR)/kernel/$(d))

CC_INCLUDE := $(shell $(CC) -print-file-name=include)

K_FLAGS := -nostdinc -isystem $(CC_INCLUDE) -I$(KERNEL_DIR)/include -I$(KERNEL_DIR)/include/uapi \
-I$(KERNEL_DIR)/include/generated -I$(KERNEL_DIR)/include/generated/uapi \
-I$(KERNEL_DIR)/arch/arm64/include -I$(KERNEL_DIR)/arch/arm64/include/uapi \
-I$(KERNEL_DIR)/arch/arm64/include/generated \
-I$(KERNEL_DIR)/arch/arm64/include/generated/uapi \
-include $(KERNEL_DIR)/include/linux/kconfig.h \
-D__KERNEL__ -DMODULE -DKBUILD_MODNAME='"nomount"'

COMMON := -O2 -fno-stack-protector -fno-pic -ffreestanding -Wall

all: nomount.kpm

nomount.kpm: nm_kpm_entry.o nm_engine.o
$(CC) -r -o $@ $^

nm_kpm_entry.o: nm_kpm_entry.c nm_kpm_syms.h
$(CC) $(COMMON) $(KP_FLAGS) -c -o $@ $<

nm_engine.o: nm_engine.c nm_kpm_shim.h nm_kpm_syms.h ../src/nomount.c ../src/nomount.h
$(CC) $(COMMON) $(K_FLAGS) -c -o $@ $<

.PHONY: undefined
undefined: nm_engine.o
@$(TARGET_COMPILE)nm -u $< | awk '{print $$2}' | sort -u

.PHONY: clean
clean:
rm -f *.o *.kpm
117 changes: 117 additions & 0 deletions kernel/kpm/nm_engine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: GPL-2.0
#undef CONFIG_ARM64_LSE_ATOMICS

#include <linux/version.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/dcache.h>
#include <linux/slab.h>
#include <linux/idr.h>
#include <linux/hashtable.h>
#include <linux/rbtree.h>
#include <linux/rwsem.h>
#include <linux/atomic.h>
#include <linux/cred.h>
#include <linux/file.h>
#include <linux/xattr.h>
#include <linux/key-type.h>
#include <linux/shmem_fs.h>
#include <linux/highmem.h>
#include <linux/compat.h>
#include <linux/list.h>
#include <linux/types.h>
#include <linux/jump_label.h>
#include <linux/srcu.h>
#include <linux/mm.h>
#include <asm/alternative.h>

#include "nm_kpm_shim.h"

#define NM_KPM_BUILD 1
#include "../src/nomount.c"

#undef memcpy
#undef memset
#undef memmove

void *memcpy(void *d, const void *s, __kernel_size_t n)
{
char *dp = d; const char *sp = s;
while (n--) *dp++ = *sp++;
return d;
}
void *memset(void *d, int c, __kernel_size_t n)
{
char *dp = d;
while (n--) *dp++ = (char)c;
return d;
}
void *memmove(void *d, const void *s, __kernel_size_t n)
{
char *dp = d; const char *sp = s;
if (dp <= sp || dp >= sp + n) return memcpy(d, s, n);
dp += n; sp += n;
while (n--) *--dp = *--sp;
return d;
}

void *__memcpy(void *d, const void *s, __kernel_size_t n) { return memcpy(d, s, n); }
void *__memset(void *d, int c, __kernel_size_t n) { return memset(d, c, n); }
void *__memmove(void *d, const void *s, __kernel_size_t n) { return memmove(d, s, n); }

#if defined(CONFIG_DEBUG_LIST) || defined(CONFIG_LIST_HARDENED)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 2, 0)
bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev,
struct list_head *next)
#else
bool __list_add_valid(struct list_head *new, struct list_head *prev,
struct list_head *next)
#endif
{
if (!nm_kpm_sym[NMS___list_add_valid_or_report])
return true;
return ((bool (*)(struct list_head *, struct list_head *, struct list_head *))
nm_kpm_sym[NMS___list_add_valid_or_report])(new, prev, next);
}
#endif

void alt_cb_patch_nops(struct alt_instr *alt, __le32 *origptr,
__le32 *updptr, int nr_inst)
{
if (!nm_kpm_sym[NMS_alt_cb_patch_nops])
return;
((void (*)(struct alt_instr *, __le32 *, __le32 *, int))
nm_kpm_sym[NMS_alt_cb_patch_nops])(alt, origptr, updptr, nr_inst);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)
void __folio_put(struct folio *folio)
{
((void (*)(struct folio *))nm_kpm_sym[NMS___folio_put])(folio);
}
#else
void __put_page(struct page *page)
{
((void (*)(struct page *))nm_kpm_sym[NMS___folio_put])(page);
}
#endif

int nm_kpm_engine_init(void)
{
return nomount_init();
}

void nm_kpm_engine_exit(void)
{
#ifdef NOMOUNT_HAS_EXIT
nomount_exit();
#endif
}

long nm_kpm_engine_ctl(const char *args)
{
(void)args;
return 0;
}
Loading