eBPF-based security platform
bpm: say why a member too large for a package fails the build
Daniel Borkmann75521ce74278
diff --git a/Documentation/upatches/publish/beefile.rst b/Documentation/upatches/publish/beefile.rstindex f38d5ff1..5309f92c 100644--- a/Documentation/upatches/publish/beefile.rst+++ b/Documentation/upatches/publish/beefile.rst@@ -381,7 +381,7 @@ Limits and reserved names* - member path including ``<name>-<version>/``- 99 bytes, the limit of a ustar name* - ``.bee`` file- - 256 MiB per member file, and for all members together+ - 256 MiB for all member files togetherEvery member path must be unique, and none may lie below another: aname is a file or a directory, not both, so ``a`` and ``a/b`` do not go@@ -389,9 +389,10 @@ into one package. ``Beefile``, ``README.md``, ``cert.der`` and``build-environment.json`` are reserved for the members ``bpm build``writes itself, and no member path lies below one of them either. Amember path longer than the ustar limit fails the build with ``bpm-build: File name too long``, and members of more than 256 MiB together-with ``bpm build: the members of the package are more than 256 MiB-together, the most a target installs``: a target unpacks no more.+build: File name too long``, and members of more than 256 MiB together,+or one of that size alone, with ``bpm build: the members of the package+are more than 256 MiB together, the most a target installs``: a target+unpacks no more.Example-------diff --git a/testing/functional/bpm/t7005-bpm-publish.sh b/testing/functional/bpm/t7005-bpm-publish.shindex 94303d05..224471f0 100644--- a/testing/functional/bpm/t7005-bpm-publish.sh+++ b/testing/functional/bpm/t7005-bpm-publish.sh@@ -141,14 +141,21 @@ for pair in "a a/b" "a/b a" "data.txt README.md/data.txt" "data.txt upatches"; dn=$((n + 1))done-# Two members that each fit and together pass what a target unpacks.-mkdir -p "$WORK/large" &&+# Two members that each fit and together pass what a target unpacks, and+# one that passes it alone.+mkdir -p "$WORK/large" "$WORK/larger" &&ln -s "$REPO/vendor" "$WORK/large/vendor" &&ln -s "$REPO/bpf" "$WORK/large/bpf" &&+ ln -s "$REPO/vendor" "$WORK/larger/vendor" &&+ ln -s "$REPO/bpf" "$WORK/larger/bpf" &&cp "$WORK/pkg/t7005.bpf.c" "$WORK/large/" &&+ cp "$WORK/pkg/t7005.bpf.c" "$WORK/larger/" &&truncate -s 134217729 "$WORK/large/one" "$WORK/large/two" &&+ truncate -s 268435457 "$WORK/larger/one" &&printf '[package]\nname = "t7005"\n\n[[files]]\nsource = "one"\n\n[[files]]\nsource = "two"\n\n[[upatches]]\nsource = "t7005.bpf.c"\n' \- >"$WORK/large/Beefile"+ >"$WORK/large/Beefile" &&+ printf '[package]\nname = "t7005"\n\n[[files]]\nsource = "one"\n\n[[upatches]]\nsource = "t7005.bpf.c"\n' \+ >"$WORK/larger/Beefile"test_expect_success 'bpm build takes a SemVer version alone' 'for v in 1.0 01.0.0 1.0.0.1 1.0.0_rc; do@@ -178,11 +185,13 @@ test_expect_success 'bpm build refuses a target below another member' ''test_expect_success 'bpm build refuses members a target could not unpack together' '- ( cd "$WORK" && ! "$S" bpm build large --version 9.2.0 \- --keys-dir "$WORK/keys" ) 2>"$WORK/large.err" &&- grep -q "more than 256 MiB together, the most a target installs" \- "$WORK/large.err" &&- ! test -e "$WORK/t7005-9.2.0.bee"+ for n in large larger; do+ ( cd "$WORK" && ! "$S" bpm build $n --version 9.2.0 \+ --keys-dir "$WORK/keys" ) 2>"$WORK/$n.err" &&+ grep -q "more than 256 MiB together, the most a target installs" \+ "$WORK/$n.err" &&+ ! test -e "$WORK/t7005-9.2.0.bee" || return 1+ done'PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.cindex 2e0fe8e2..dcafc42c 100644--- a/tools/shirudo-build/bpm-build.c+++ b/tools/shirudo-build/bpm-build.c@@ -104,12 +104,16 @@ static int build_read_file(const char *path, __u8 **out, size_t *len,fd = open(path, O_RDONLY | O_CLOEXEC);if (fd < 0)return -errno;- if (fstat(fd, &st) || st.st_size < 0 || (uintmax_t)st.st_size > max) {- int ret = errno ? -errno : -E2BIG;+ if (fstat(fd, &st)) {+ int ret = -errno;close(fd);return ret;}+ if (st.st_size < 0 || (uintmax_t)st.st_size > max) {+ close(fd);+ return -EFBIG;+ }body = xmalloc((size_t)st.st_size + 1);if (!body) {close(fd);@@ -1508,7 +1512,7 @@ static int tar_path(struct bpm_tar *tar, const char *name, const char *path)return -errno;if (!S_ISREG(st.st_mode))return -EINVAL;- ret = build_read_file(path, &body, &len, BPM_BUILD_MAX_FILE);+ ret = build_read_file(path, &body, &len, BPM_MAX_PACKAGE_BYTES);if (!ret) {ret = tar_entry(tar, name, body, len, st.st_mode, '0');xfree(body, len + 1);