LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Pi kernel: BPF LSM, BTF and Yama (6.18.57-2+lordos)
Federico Pereira8648d5d9d111
diff --git a/tools/rpi/build-kernel.sh b/tools/rpi/build-kernel.shindex 45ef034..5e40b34 100644--- a/tools/rpi/build-kernel.sh+++ b/tools/rpi/build-kernel.sh@@ -1,8 +1,10 @@#!/bin/sh# build-kernel.sh — the LordOS Raspberry Pi kernel: Raspberry Pi's own kernel source and defconfig,-# plus what LordOS needs that it lacks (Landlock). See docs/RASPBERRY.md, "The LordOS kernel".+# plus what LordOS needs that it lacks (Landlock, the BPF LSM and BTF). See docs/RASPBERRY.md,+# "The LordOS kernel".#-# Usage (on an arm64 Debian 13, ideally the Pi itself; about 50 min per flavour on a Pi 5):+# Usage (on an arm64 Debian 13, ideally the Pi itself; about 75 min per flavour on a Pi 5, and+# ~10 GB free in the work folder while one flavour builds: BTF needs the DWARF debug info):# tools/rpi/build-kernel.sh [work folder] [2712|v8|all] # default /var/tmp/lordos-kernel 2712## Result: <work>/out/linux-image-<release>_<version>_arm64.deb (+ linux-headers-…), where@@ -14,9 +16,10 @@# $KERNEL_DEBS (default /var/tmp/lordos-kernel/out).## Variables: RPI_KERNEL_REPO (default the Raspberry Pi GitHub tree), RPI_KERNEL_BRANCH (rpi-6.18.y),-# RPI_KERNEL_REF (a commit to pin; default the branch head), LORDOS_KREV (package revision, 1),+# RPI_KERNEL_REF (a commit to pin; default the branch head), LORDOS_KREV (package revision, 2 since+# 0.8.1: the BPF LSM and BTF were added to 6.18.57-1),# JOBS (default nproc). Building packages needs: build-essential bc bison flex libssl-dev-# libelf-dev libdw-dev dwarves cpio kmod rsync dpkg-dev debhelper git.+# libelf-dev libdw-dev dwarves (pahole, for BTF) cpio kmod rsync dpkg-dev debhelper git.set -euWORK=${1:-/var/tmp/lordos-kernel}@@ -24,7 +27,7 @@ FLAVOURS=${2:-2712}REPO=${RPI_KERNEL_REPO:-https://github.com/raspberrypi/linux.git}BRANCH=${RPI_KERNEL_BRANCH:-rpi-6.18.y}REF=${RPI_KERNEL_REF:-}-KREV=${LORDOS_KREV:-1}+KREV=${LORDOS_KREV:-2}JOBS=${JOBS:-$(nproc)}SRC="$WORK/linux"OUT="$WORK/out"@@ -36,7 +39,7 @@ case "$(uname -m)" inecho "build-kernel.sh: not arm64 and no aarch64-linux-gnu-gcc (gcc-aarch64-linux-gnu)" >&2; exit 1; }CROSS="CROSS_COMPILE=aarch64-linux-gnu-" ;;esac-for t in git make gcc bc bison flex dpkg-deb dpkg-buildpackage dh rsync cpio; do+for t in git make gcc bc bison flex dpkg-deb dpkg-buildpackage dh rsync cpio pahole readelf; docommand -v "$t" >/dev/null || { echo "build-kernel.sh: missing $t" >&2; exit 1; }done@@ -81,7 +84,8 @@ for FL in $FLAVOURS; docp "$B/.config" "$B/config.defconfig"# ---- the LordOS changes (documented in docs/RASPBERRY.md; keep them in sync) ----# Landlock: filesystem and TCP confinement of apps (.lpk) and helpers (lord-doc, lord-media,- # lord-maild): server/src/sec/sandbox.c. Raspberry Pi's defconfig leaves it out.+ # lord-maild): server/src/sec/sandbox.c. Raspberry Pi's defconfig leaves it out. Yama: the+ # lordos package's kernel.yama.ptrace_scope = 1 (as on a PC). The BPF LSM: see below."$SRC/scripts/config" --file "$B/.config" \--enable SECURITY \--enable SECURITYFS \@@ -89,6 +93,8 @@ for FL in $FLAVOURS; do--enable SECURITY_PATH \--enable SECURITY_LANDLOCK \--set-str LSM "landlock,lockdown,yama,integrity,bpf" \+ --enable BPF_LSM \+ --enable SECURITY_YAMA \--set-str LOCALVERSION "$LV" \--disable LOCALVERSION_AUTO# already in the defconfig, required by LordOS; enforced so a future defconfig can't drop them:@@ -97,9 +103,23 @@ for FL in $FLAVOURS; do--enable SECCOMP --enable SECCOMP_FILTER \--enable CGROUPS --enable MEMCG --enable CGROUP_PIDS --enable CGROUP_SCHED \--enable BPF_SYSCALL --enable BPF_JIT --enable CGROUP_BPF+ # BPF LSM + BTF (0.8.1): lord-netperm's per-cgroup LSM program on socket_create (the per-app+ # "No Bluetooth" of Linux apps, docs/FIREWALL.md) needs the bpf LSM and /sys/kernel/btf/vmlinux+ # (its attach point is a BTF id). BTF is generated by pahole from the DWARF debug info; the debug+ # info itself doesn't ship: modules are stripped (builddeb, keeping their .BTF) and the -dbg+ # package is not built (the nokerneldbg build profile below).+ "$SRC/scripts/config" --file "$B/.config" \+ --enable BPF_EVENTS \+ --disable DEBUG_INFO_NONE \+ --enable DEBUG_INFO \+ --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \+ --disable DEBUG_INFO_REDUCED \+ --disable DEBUG_INFO_SPLIT \+ --enable DEBUG_INFO_BTF \+ --enable DEBUG_INFO_BTF_MODULES# shellcheck disable=SC2086make -s -C "$SRC" O="$B" ARCH=arm64 $CROSS olddefconfig- for o in SECURITY_LANDLOCK SECCOMP_FILTER CGROUP_BPF BPF_SYSCALL; do+ for o in SECURITY_LANDLOCK SECURITY_YAMA SECCOMP_FILTER CGROUP_BPF BPF_SYSCALL BPF_LSM DEBUG_INFO_BTF; dogrep -q "^CONFIG_$o=y" "$B/.config" || { echo "build-kernel.sh: CONFIG_$o did not stick" >&2; exit 1; }donegrep -q '^CONFIG_LSM="landlock' "$B/.config" || { echo "build-kernel.sh: CONFIG_LSM did not stick" >&2; exit 1; }@@ -114,6 +134,8 @@ for FL in $FLAVOURS; do# shellcheck disable=SC2086# LOCALVERSION= (empty): without it setlocalversion appends "+" for a git tree that isn't at a# tag, giving "…-rpi-2712+", which raspi-firmware's hook doesn't recognize as a flavour+ # DEB_BUILD_PROFILES: no linux-image-*-dbg (the debug info is only there to make BTF)+ DEB_BUILD_PROFILES="pkg.linux-lordos-rpi-$FL.nokerneldbg" \make -C "$SRC" O="$B" ARCH=arm64 $CROSS -j"$JOBS" LOCALVERSION= \KDEB_PKGVERSION="$KV-$KREV+lordos" KDEB_SOURCENAME="linux-lordos-rpi-$FL" \KBUILD_BUILD_USER=lordos KBUILD_BUILD_HOST=lordos \@@ -123,9 +145,14 @@ for FL in $FLAVOURS; do[ -f "$d" ] && mv "$d" "$OUT/"donerm -f "$WORK"/linux-libc-dev_*.deb "$WORK/linux-image-$KV$LV"-dbg_*.deb "$WORK"/linux-lordos-rpi-"$FL"_*- IMGDEB=$(ls "$OUT/linux-image-$KV$LV"_*.deb 2>/dev/null) || {- echo "build-kernel.sh: no linux-image-$KV$LV package; built: $(ls "$WORK"/*.deb 2>/dev/null)" >&2; exit 1; }+ # this revision's package only (out/ may still hold an older revision of the same kernel)+ IMGDEB="$OUT/linux-image-$KV${LV}_$KV-${KREV}+lordos_arm64.deb"+ [ -f "$IMGDEB" ] || {+ echo "build-kernel.sh: no $(basename "$IMGDEB"); built: $(ls "$WORK"/*.deb "$OUT"/*.deb 2>/dev/null)" >&2; exit 1; }add_overlay_readme "$IMGDEB" "$KV$LV"+ # BTF really in the kernel (vmlinux's .BTF section, what becomes /sys/kernel/btf/vmlinux)+ readelf -S "$B/vmlinux" | grep -q ' \.BTF ' ||+ { echo "build-kernel.sh: $B/vmlinux has no .BTF section" >&2; exit 1; }# the device trees and overlays where raspi-firmware's hook looks for themdpkg-deb -c "$IMGDEB" | grep -c "usr/lib/linux-image-$KV$LV/broadcom/bcm27.*\.dtb" > /dev/null ||{ echo "build-kernel.sh: $IMGDEB has no device trees in /usr/lib/linux-image-$KV$LV/broadcom" >&2; exit 1; }