eBPF-based security platform
ci: analyze the C sources from a traced CodeQL build
Daniel Borkmann219742d326ec
diff --git a/.github/scripts/build-debian.sh b/.github/scripts/build-debian.shindex 4312142d..3438c0e9 100755--- a/.github/scripts/build-debian.sh+++ b/.github/scripts/build-debian.sh@@ -3,9 +3,7 @@# Copyright (c) 2026 Authors of shirudo## .github/scripts/build-debian.sh -- build on a Debian testing container of-# any architecture, with the distribution's compiler and libraries, which-# are new enough to need no toolchain of their own, and clang 23 from-# unstable through install-clang.sh: the binary and the+# any architecture, with what debian-deps.sh installs: the binary and the# shirudo-build helper, then the unit tests and the linkage check. The BPF# objects are bytecode whatever the host, so the BTF can come from a# kernel of another architecture.@@ -28,25 +26,7 @@ grep -aq 'signature_size' "$btf" || {exit 1}-export DEBIAN_FRONTEND=noninteractive-apt-get update-apt-get install -y --no-install-recommends \- build-essential \- ca-certificates \- git \- openssl \- pkgconf \- python3 \- libcurl4-openssl-dev \- libelf-dev \- libluajit-5.1-dev \- libssl-dev \- libtss2-dev \- zlib1g-dev-sh .github/scripts/install-clang.sh-sh .github/scripts/install-static-libcrypto-deps.sh--git config --global --add safe.directory "$PWD"+sh .github/scripts/debian-deps.shuname -mcc --version | head -n 1diff --git a/.github/scripts/codeql-c.sh b/.github/scripts/codeql-c.shnew file mode 100755index 00000000..5a97b544--- /dev/null+++ b/.github/scripts/codeql-c.sh@@ -0,0 +1,47 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/codeql-c.sh -- the C build CodeQL traces, on Debian+# testing with what debian-deps.sh installs. prepare runs before the+# tracing starts and builds what is not shirudo's own, the vendored+# libbpf, and the vmlinux.h its BPF programs include; build then compiles+# shirudo's sources alone: the binary with its BPF objects, the+# shirudo-build helper, the quote checker, the test helpers and the unit+# tests.+#+# .github/scripts/codeql-c.sh prepare <vmlinux-btf>+# .github/scripts/codeql-c.sh build <vmlinux-btf>+#+# Run as root in the checkout root, inside a throwaway container.++set -eu++if [ "$#" -ne 2 ]; then+ printf 'usage: %s prepare|build <vmlinux-btf>\n' "$0" >&2+ exit 2+fi+export BPF_VMLINUX_BTF="$2"++case $1 in+prepare)+ grep -aq 'signature_size' "$BPF_VMLINUX_BTF" || {+ echo "$BPF_VMLINUX_BTF lacks bpf_attr.signature_size; needs a signed-BPF capable bpf-next kernel" >&2+ exit 1+ }+ sh .github/scripts/debian-deps.sh+ make config+ make -f Makefile.shirudo PROFILE=operator CONFIG_MK=config.mk \+ vendor/libbpf/libbpf.a vendor/linux/vmlinux.h+ ;;+build)+ make -j"$(nproc)"+ make shirudo-build+ make quote-check+ make -C testing test-helpers build-unit+ ;;+*)+ printf 'usage: %s prepare|build <vmlinux-btf>\n' "$0" >&2+ exit 2+ ;;+esacdiff --git a/.github/scripts/debian-deps.sh b/.github/scripts/debian-deps.shnew file mode 100755index 00000000..458da6f0--- /dev/null+++ b/.github/scripts/debian-deps.sh@@ -0,0 +1,33 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/debian-deps.sh -- install what a build on Debian testing+# needs: the distribution's compiler and libraries, which are new enough+# to need no toolchain of their own, and clang 23 from unstable through+# install-clang.sh.+#+# Run as root in the checkout root, inside a throwaway container: it+# installs packages and changes the git configuration.++set -eu++export DEBIAN_FRONTEND=noninteractive+apt-get update+apt-get install -y --no-install-recommends \+ build-essential \+ ca-certificates \+ git \+ openssl \+ pkgconf \+ python3 \+ libcurl4-openssl-dev \+ libelf-dev \+ libluajit-5.1-dev \+ libssl-dev \+ libtss2-dev \+ zlib1g-dev+sh .github/scripts/install-clang.sh+sh .github/scripts/install-static-libcrypto-deps.sh++git config --global --add safe.directory "$PWD"diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.ymlindex c3a50832..4f7063a4 100644--- a/.github/workflows/codeql.yml+++ b/.github/workflows/codeql.yml@@ -15,6 +15,91 @@ concurrency:cancel-in-progress: truejobs:+ btf:+ name: bpf-next BTF+ runs-on: ubuntu-latest+ timeout-minutes: 30++ steps:+ # The BTF of the bpf-next kernel the build generates vmlinux.h from,+ # as the Build workflow takes it.+ - name: Copy the kernel BTF out of the LVH VM+ uses: cilium/little-vm-helper@c8b0bfbae3bdda7bc69fb9cd370e4b74ce84986d # v0.0.33+ with:+ test-name: shirudo-codeql-btf+ image: kind+ image-version: bpf-next-20260603.072225+ kernel-version: bpf-next-main+ host-mount: ${{ github.workspace }}+ images-folder-parent: ${{ github.workspace }}/../lvh+ install-dependencies: true+ cpu: 2+ mem: 4G+ cmd: |+ grep -aq 'signature_size' /sys/kernel/btf/vmlinux || {+ echo 'kernel BTF lacks bpf_attr.signature_size; needs a signed-BPF capable bpf-next kernel' >&2+ exit 1+ }+ mkdir -p /host/build+ cp /sys/kernel/btf/vmlinux /host/build/vmlinux.btf++ - name: Upload the kernel BTF+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2+ with:+ name: bpf-next-btf+ path: build/vmlinux.btf+ if-no-files-found: error+ retention-days: 1++ # CodeQL follows the compiler through a real build, which tells it the+ # types, macros and code each file is built with. Debian testing has the+ # OpenSSL 3.5 the build needs; the vendored libbpf and vmlinux.h are+ # built before the tracing starts, so that their code is not analyzed.+ c:+ name: Analyze (C)+ needs: btf+ runs-on: ubuntu-latest+ container: debian:testing+ timeout-minutes: 60+ permissions:+ actions: read+ contents: read+ security-events: write++ steps:+ # Without git the checkout is no repository, and the build takes its+ # version from one.+ - name: Install git+ run: apt-get update && apt-get install -y --no-install-recommends ca-certificates git++ - name: Check out repository+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1++ - name: Download the kernel BTF+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2+ with:+ name: bpf-next-btf+ path: build++ - name: Build what CodeQL does not analyze+ run: sh .github/scripts/codeql-c.sh prepare build/vmlinux.btf++ - name: Initialize CodeQL+ uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3+ with:+ languages: c-cpp+ build-mode: manual+ queries: +security-extended,security-and-quality+ config-file: ./.github/codeql/codeql-config.yml++ - name: Build the C sources under CodeQL+ run: sh .github/scripts/codeql-c.sh build build/vmlinux.btf++ - name: Perform CodeQL analysis+ uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3+ with:+ category: /language:c-cpp+analyze:name: Analyze (${{ matrix.name }})runs-on: ubuntu-latest@@ -27,8 +112,6 @@ jobs:fail-fast: falsematrix:include:- - language: c-cpp- name: C- language: pythonname: Python- language: actions@@ -38,10 +121,7 @@ jobs:- name: Check out repositoryuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1- # The full build needs the BTF of a bpf-next kernel for vmlinux.h and- # an OpenSSL 3.5 toolchain, neither of which the runner has, so the C- # sources are extracted without a build, as Python and the workflows- # always are. The vendored libbpf is left to its own project's scans.+ # Python and the workflows are read without a build.- name: Initialize CodeQLuses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3with: