eBPF-based security platform
upatch: show the controls of the member over a .rodata dump as ?
Daniel Borkmann57896de69a8b
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 52f8619d..6961bf2c 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -550,8 +550,10 @@ signed config image.and tree configuration lines* - ``t7002-bpm-info``- READMEs of local and OCI packages, archive integrity, a download- kept in a memory file rather than in ``/tmp``, and one key- fingerprint from a certificate, a package and a download+ kept in a memory file rather than in ``/tmp``, one key+ fingerprint from a certificate, a package and a download, and the+ control characters of a README and of a member name shown as+ ``?`` by ``info``, ``info upatches`` and ``info data``* - ``t7003-bpm-key``- ``bpm key`` from files and OCI references, ``bpm pull``, whichreplaces no file, not even after a failed digest, and names nonediff --git a/Makefile.shirudo b/Makefile.shirudoindex 972599c5..d0d7478a 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -553,7 +553,7 @@ tools/shirudo-build/shirudo-build: $(BUILD_OBJS) $(SIGN_OBJ) util/config_image.outil/seal.o util/harden.o util/string.o \util/crypto_openssl.o util/tls_openssl.o \util/bpm_oci.o util/curl.o util/bpm_package.o \- util/upatch_rodata.o \+ util/upatch_rodata.o util/format.o \util/bpm_tree.o util/bpm_tree_overlap.o \util/chain_history.o util/options.o \util/help.o util/similar.o \@@ -1003,7 +1003,7 @@ testing/helper/test-upatch-serializer-pages: testing/helper/test-upatch-serializtesting/helper/test-upatch-rodata: testing/helper/test-upatch-rodata.c \util/upatch.o util/seal.o util/json.o \util/string.o util/malloc.o util/io.o \- util/log.o util/hex.o+ util/log.o util/hex.o util/format.o@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(STATIC_LIBS) $(DYNAMIC_LIBS)@@ -1192,8 +1192,8 @@ $(FUZZ_OUT)/fuzz-upatch: testing/fuzz/fuzz-upatch.c $(FUZZ_BASE) \$(FUZZ_OUT)/fuzz-prog-metadata: testing/fuzz/fuzz-prog-metadata.c \$(FUZZ_BASE) util/upatch.c$(FUZZ_OUT)/fuzz-rodata: testing/fuzz/fuzz-rodata.c $(FUZZ_BASE) \- util/upatch.c util/upatch_rodata.c util/io.c \- $(FUZZ_SEAL) $(LIBBPF_A)+ util/upatch.c util/upatch_rodata.c util/format.c \+ util/io.c $(FUZZ_SEAL) $(LIBBPF_A)$(FUZZ_OUT)/fuzz-rodata: FUZZ_CFLAGS += $(LIBELF_CFLAGS)$(FUZZ_OUT)/fuzz-rodata: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS) $(ZLIB_LIBS)$(FUZZ_OUT)/fuzz-bpm-tar: testing/fuzz/fuzz-bpm-tar.c $(FUZZ_BASE) \diff --git a/testing/helper/test-bpm-info.py b/testing/helper/test-bpm-info.pyindex d2f32090..0c621f75 100644--- a/testing/helper/test-bpm-info.py+++ b/testing/helper/test-bpm-info.py@@ -19,6 +19,9 @@ import unittestSHIRUDO = str(Path(sys.argv.pop(1)).resolve())README = b"# Example package\n\nPackage documentation without a final newline."+# A upatch named rodata with a struct and an integer in .rodata.+RODATA_UPATCH = (Path(__file__).resolve().parents[1] /+ "fuzz/corpus/rodata/struct").read_bytes()def package_bytes(entries):@@ -112,6 +115,20 @@ class InfoTests(BpmTestCase):self.assertEqual(result.returncode, 0, result.stderr)self.assertEqual(result.stdout, b"upatches/a?[2Jb.upatch\n")+ def test_data_member_name_controls_show_as_question_marks(self):+ member = "upatches/a\x1b]0;x\x07b.upatch"+ path = self.root / "package.bee"+ path.write_bytes(package_bytes([+ ("example-1.0/Beefile", b'[package]\nname = "example"\n'),+ ("example-1.0/" + member, RODATA_UPATCH),+ ]))+ result = self.run_info("data", str(path), member)+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertTrue(result.stdout.startswith(+ b"upatch rodata (upatches/a?]0;x?b.upatch) .rodata: "),+ result.stdout[:80])+ self.assertNotIn(b"\x1b", result.stdout)+def test_empty_readme(self):result = self.local(package(b""))self.assertEqual(result.returncode, 0, result.stderr)diff --git a/util/upatch_rodata.c b/util/upatch_rodata.cindex f5c91ee0..b12cf686 100644--- a/util/upatch_rodata.c+++ b/util/upatch_rodata.c@@ -17,6 +17,7 @@#include <shirudo/overflow.h>#include <shirudo/string.h>+#include "format.h"#include "io.h"#include "json.h"#include "log.h"@@ -971,9 +972,10 @@ static int print_rodata_text(const struct upatch *u,upatch_header_name(u, name);text_sanitize(name, strlen(name), false);- printf("upatch %s (%s) .rodata: %u bytes at data+%u, file+%u\n",- name, path, view->size, view->data_offset,- u->hdr.data_off + view->data_offset);+ printf("upatch %s (", name);+ fputs_sanitized(path, stdout);+ printf(") .rodata: %u bytes at data+%u, file+%u\n", view->size,+ view->data_offset, u->hdr.data_off + view->data_offset);cost = xcalloc(types, sizeof(*cost));if (!cost)return -ENOMEM;