eBPF-based security platform
ci: check the licence tags of the vendored sources
Daniel Borkmann024d7d33137c
diff --git a/.github/scripts/check-spdx.sh b/.github/scripts/check-spdx.shindex 9050335c..3a03ddd6 100755--- a/.github/scripts/check-spdx.sh+++ b/.github/scripts/check-spdx.sh@@ -11,8 +11,8 @@## .github/scripts/check-spdx.sh#-# Runs from anywhere inside the checkout. The vendored trees keep their-# own licences and are not checked.+# Runs from anywhere inside the checkout. Vendored C keeps its upstream+# tag, which has to name one of the licences listed in vendor_ok().set -eu@@ -35,16 +35,46 @@ report() {printf '%s: %s\n' "$1" "$2" >&2}-# Vendored code keeps its own licence, the kernel's coding-style.rst is-# carried verbatim and vmlinux.h is generated from BTF.+# The kernel's coding-style.rst is carried verbatim and vmlinux.h is+# generated from BTF.excluded() {case "$1" in- vendor/*|Documentation/coding-style.rst|vmlinux.h|*/vmlinux.h)+ Documentation/coding-style.rst|vmlinux.h|*/vmlinux.h)return 0 ;;esacreturn 1}+# The licences vendored C may carry, each one the binaries can take next+# to OpenSSL's Apache-2.0: libbpf's dual licence, the UAPI headers' GPL+# with the syscall note, and shirudo's own shims.+vendor_ok() {+ case "$1" in+ '(LGPL-2.1 OR BSD-2-Clause)'|'BSD-2-Clause'|\+ 'GPL-2.0 WITH Linux-syscall-note'|\+ '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')+ return 0 ;;+ esac+ return 1+}++check_vendor() {+ f=$1+ l1=''+ IFS= read -r l1 <"$f" || :+ case "$l1" in+ *SPDX-License-Identifier:*)+ ;;+ *)+ report "$f" "vendored without an SPDX-License-Identifier tag on line 1"+ return ;;+ esac+ expr=$(printf '%s' "${l1#*SPDX-License-Identifier:}" |+ sed 's/^[[:space:]]*//; s/[[:space:]]*\*\/[[:space:]]*$//; s/[[:space:]]*$//')+ vendor_ok "$expr" ||+ report "$f" "licence expression '$expr' is not one vendored code may carry"+}+# The comment form of the tag by file type, the kernel's rules with --# for Lua and .. for reStructuredText. Any other file needs a tag only# when it starts with a shebang.@@ -140,10 +170,16 @@ expr_of() {}: >"$work/files"+: >"$work/vendor": >"$work/exprs"git ls-files | while IFS= read -r f; doexcluded "$f" && continue- printf '%s\n' "$f" >>"$work/files"+ case "$f" in+ vendor/*)+ printf '%s\n' "$f" >>"$work/vendor" ;;+ *)+ printf '%s\n' "$f" >>"$work/files" ;;+ esacdonewhile IFS= read -r f; do@@ -153,6 +189,20 @@ while IFS= read -r f; docheck_file "$f" "$kind"done <"$work/files"+# bpf_doc.py writes bpf_helper_defs.h without a tag; it is libbpf's.+while IFS= read -r f; do+ case "$f" in+ vendor/libbpf/bpf/bpf_helper_defs.h)+ continue ;;+ *.c|*.h)+ ;;+ *)+ continue ;;+ esac+ checked=$((checked + 1))+ check_vendor "$f"+done <"$work/vendor"+# Everything clang -target bpf compiles, the LSM and its loaders under# bpf/ and every *.bpf.c, plus the headers they include by relative# path, found as the build finds them: beside the includer, then indiff --git a/testing/t0042-check-spdx.sh b/testing/t0042-check-spdx.shindex cf819cb7..ce3a9aa3 100755--- a/testing/t0042-check-spdx.sh+++ b/testing/t0042-check-spdx.sh@@ -4,8 +4,8 @@## t0042 -- .github/scripts/check-spdx.sh: the tag every source needs, its form# by file type, the two expressions, the dual licence of everything a-# BPF object compiles and a Beefile ships, on a throwaway repository,-# and the tree itself.+# BPF object compiles and a Beefile ships, the licences vendored C may+# carry, on a throwaway repository, and the tree itself.cd "$(dirname "$0")". ./test-lib.sh@@ -46,7 +46,10 @@ put "$R/block.rst" '..' ' SPDX-License-Identifier: BSD-2-Clause' ' Copyrightput "$R/line.rst" '.. SPDX-License-Identifier: BSD-2-Clause'put "$R/notes.md" 'no tag here'put "$R/data.json" '{}'-put "$R/vendor/x.c" 'int x;'+put "$R/vendor/x.c" '// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)' 'int x;'+put "$R/vendor/uapi.h" '/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */'+put "$R/vendor/libbpf/bpf/bpf_helper_defs.h" '/* This is auto-generated file. */'+put "$R/vendor/README.md" 'no tag here'put "$R/vendor/linux/vmlinux.h" 'struct task_struct;'put "$R/pkg/vmlinux.h" 'struct task_struct;'put "$R/Documentation/coding-style.rst" 'Linux kernel coding style'@@ -63,7 +66,7 @@ put "$R/pkg/gen.py" '#!/usr/bin/env python3' '# SPDX-License-Identifier: BSD-2-Ctest_expect_success 'a tree of well-tagged files passes' 'check "$R" &&- grep -q "SPDX: 16 files checked" "$W/out"+ grep -q "SPDX: 18 files checked" "$W/out"'B=$W/bad@@ -91,10 +94,12 @@ put "$B/pkg/Beefile" '[package]' 'license = "GPL-2.0 OR BSD-2-Clause"' \put "$B/pkg/decoders/x.lua" '-- SPDX-License-Identifier: BSD-2-Clause'put "$B/pkg/gen.py" '# SPDX-License-Identifier: BSD-2-Clause'put "$B/nolic/Beefile" '[package]' 'name = "x"'+put "$B/vendor/types.h" '/* SPDX-License-Identifier: GPL-2.0 */'+put "$B/vendor/bare.c" 'int x;'test_expect_success 'a tree of badly tagged files fails' '! check "$B" &&- grep -q "^14 SPDX problems" "$W/err"+ grep -q "^16 SPDX problems" "$W/err"'test_expect_success 'the form of the tag follows the file type' '@@ -128,6 +133,11 @@ test_expect_success 'a package ships its sources under the licence of its Beefilgrep -q "^nolic/Beefile: no license field" "$W/err"'+test_expect_success 'vendored C carries a licence the binaries can take' '+ grep -q "^vendor/types.h: licence expression .GPL-2.0. is not one vendored code may carry" "$W/err" &&+ grep -q "^vendor/bare.c: vendored without an SPDX-License-Identifier tag on line 1" "$W/err"+'+test_expect_success 'the tree passes' '(cd "$ROOT" && sh "$S") >"$W/out" 2>"$W/err" &&grep -q "^SPDX: [0-9]* files checked" "$W/out"diff --git a/vendor/libbpf/README.md b/vendor/libbpf/README.mdindex 6e2d5c6e..c4aa0ab0 100644--- a/vendor/libbpf/README.md+++ b/vendor/libbpf/README.md@@ -16,7 +16,7 @@ source commit in `COMMIT`, and rebuilds `libbpf.a` as a check.|---|---|---|| `bpf/*.c`, `bpf/*.h` | `tools/lib/bpf/` (verbatim, but see below) | `LGPL-2.1 OR BSD-2-Clause`; shirudo consumes the BSD branch || `bpf/bpf_helper_defs.h` | generated from `bpf.h` by `scripts/bpf_doc.py` | as libbpf |-| `include/uapi/linux/*.h` | `tools/include/uapi/linux/` (verbatim) | `GPL-2.0 WITH Linux-syscall-note`: the syscall note permits user programs to include them |+| `include/uapi/linux/*.h` | `tools/include/uapi/linux/` (verbatim) | `GPL-2.0 WITH Linux-syscall-note`, `netdev.h` also `OR BSD-3-Clause`: the syscall note permits user programs to include them || `include/linux/*.h`, `include/asm/*.h` | shirudo-owned shims replacing the kernel's `tools/include` internals | BSD-2-Clause || `Makefile`, `README.md` | shirudo-owned | BSD-2-Clause |@@ -32,3 +32,7 @@ of `bpf-deps` fails on the missing symbol; extend the shim.the recorded commit, 5de632280142 ("libbpf: validate generated loaderprogram counts"). `bpf-deps` overwrites both files, so re-apply thatchange after a refresh until it is upstream.++`.github/scripts/check-spdx.sh` holds every vendored `.c` and `.h` to+the licences in this table, so a refresh that brings in a file under+any other licence fails CI.