Skip to content

Linux user/initrd modules #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions linux-user/dvkm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
sharedir/dvkm.ko
sharedir/fuzz_dvkm

Module.symvers
modules.order
.modules.order.cmd
.Module.symvers.cmd

6 changes: 5 additions & 1 deletion linux-user/dvkm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MAKEF_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
EXAMPLES_ROOT := $(KAFL_ROOT)/examples
LINUX_AGENT_DIR := $(EXAMPLES_ROOT)/linux-user/linux_kafl_agent
GEN_INITRD_DIR := $(EXAMPLES_ROOT)/linux-user/scripts
INITRD_MODULES_STAGING_DIR := $(GEN_INITRD_DIR)/modules
DVKM_DIR := $(MAKEF_DIR)/Damn_Vulnerable_Kernel_Module

# Artifacts
Expand Down Expand Up @@ -38,8 +39,11 @@ $(LINUX_AGENT_BZIMAGE):
$(MAKE) -C $(LINUX_AGENT_DIR) olddefconfig
$(MAKE) -C $(LINUX_AGENT_DIR) -j $(shell nproc)

modules: $(LINUX_AGENT_BZIMAGE)
$(MAKE) -C $(LINUX_AGENT_DIR) modules_install INSTALL_MOD_PATH=$(INITRD_MODULES_STAGING_DIR)

# Build initrd
$(KAFL_INITRD_PATH):
$(KAFL_INITRD_PATH): modules
$(MAKE) -C $(GEN_INITRD_DIR)

# Build dvkm.ko (and test_dvkm)
Expand Down
2 changes: 2 additions & 0 deletions linux-user/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# ignore build output
*.cpio.gz

modules/
1 change: 1 addition & 0 deletions linux-user/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ all: $(TARGET)

clean:
rm -f $(TARGET)
rm -rf $(MAKEF_DIR)/modules

# build vmcall if needed
$(VMCALL_BIN):
Expand Down
7 changes: 7 additions & 0 deletions linux-user/scripts/gen_initrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
set -e
set -u

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_ROOT=$EXAMPLES_ROOT/linux-user
TEMPLATE=$SCRIPT_ROOT/initrd_template
MODULES_STAGING_DIR=$SCRIPT_DIR/modules

fatal() {
echo
Expand Down Expand Up @@ -76,6 +78,11 @@ function inject_files()
echo "Install $dep => $TARGET_ROOT/$dep"
install -D "$dep" $TARGET_ROOT/"$dep"
done

if [ -d "$MODULES_STAGING_DIR" ]; then
echo "[*] Copying modules..."
rsync -av "$MODULES_STAGING_DIR/" "$TARGET_ROOT/"
fi
}

function build_image()
Expand Down