Skip to content

eBPF-based security platform

report: write the report of a load whose name is no UTF-8

Daniel Borkmann06ed3f81ef8e
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 31f0580e..1ad5e842 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -179,7 +179,8 @@ signed config image.
- Covers
* - ``t3001-upatch-parse``
- Malformed ``.upatch`` containers are refused, files over 16 MiB
- without mapping them
+ without mapping them, and a load refused for a name that is no
+ UTF-8 still writes its report
* - ``t3002-upatch-decoders``
- Decoder metadata, Lua sandbox limits, refusal of bytecode, a
decoder of a upatch named with 255 characters, one decoder per map
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rst
index bf5beb17..d654624b 100644
--- a/Documentation/reference/failure-categories.rst
+++ b/Documentation/reference/failure-categories.rst
@@ -488,11 +488,14 @@ link.
not run.
* - ``upatch.path``
- string
- - The path given on the command line.
+ - The path given on the command line, with U+FFFD for each byte
+ that is no UTF-8.
* - ``upatch.name``
- string
- - The upatch name from the header. Empty when the operation stopped
- before the artifact was read.
+ - The upatch name from the header, as the file has it and with
+ U+FFFD for each byte that is no UTF-8: a name the load refuses is
+ reported too. Empty when the operation stopped before the
+ artifact was read.
* - ``upatch.payload_sha256``
- string
- For a load, the artifact's payload digest. For an unload, the
diff --git a/testing/functional/upatch/t3001-upatch-parse.sh b/testing/functional/upatch/t3001-upatch-parse.sh
index e33f742f..66351328 100644
--- a/testing/functional/upatch/t3001-upatch-parse.sh
+++ b/testing/functional/upatch/t3001-upatch-parse.sh
@@ -5,7 +5,8 @@
# t3001 -- the .upatch container parser is the target's trust boundary:
# an attacker can hand it an arbitrary file. It must reject malformed
# input cleanly (non-zero exit, never a crash). Driven through the real
-# core binary's read-only `upatch info`; needs no root, kernel, or clang.
+# core binary's read-only `upatch info`, and through a load it refuses
+# before it reaches the kernel; needs no root, kernel, or clang.
cd "$(dirname "$0")/../.."
. ./test-lib.sh
@@ -106,6 +107,16 @@ name = json.load(open(sys.argv[1]))["name"]
assert name == "a\x1b[2Jb\x9bc\ufffd", repr(name)
PY
'
+test_expect_success 'a refused load reports a name that is no UTF-8' '
+ ! "$S" upatch load --no-precheck --report=- "$WORK/controls-in-name" \
+ >"$WORK/report.json" 2>"$WORK/report.err" &&
+ python3 - "$WORK/report.json" <<"PY"
+import json, sys
+report = json.load(open(sys.argv[1]))
+assert report["category"] == "parser_rejected", report
+assert report["upatch"]["name"] == "a\x1b[2Jb\x9bc\ufffd", report
+PY
+'
test_expect_success 'upatch info --json grows to hold a long escaped path' '
dir=$WORK && seg=$(printf "\001%.0s" $(seq 200)) &&
for i in $(seq 15); do dir=$dir/$seg; done &&
diff --git a/util/report.c b/util/report.c
index aa4234be..1db2b997 100644
--- a/util/report.c
+++ b/util/report.c
@@ -23,6 +23,18 @@
#include "report.h"
#include "seal.h"
+/*
+ * The path is as the caller spelled it and the name as the file has it,
+ * before anything checked either: a byte that is no UTF-8 must not cost
+ * the report of the refusal it is part of.
+ */
+static void kv_unverified(struct json_emit *e, const char *key,
+ const char *val)
+{
+ json_key(e, key);
+ json_str_lossy(e, val, strlen(val));
+}
+
int report_emit(const char *path, const struct op_report *r)
{
struct seal_output out;
@@ -66,8 +78,8 @@ int report_emit(const char *path, const struct op_report *r)
json_kv_int(&e, "loader_return", r->loader_return);
json_obj_open_key(&e, "upatch");
- json_kv_string(&e, "path", r->path ? r->path : "");
- json_kv_string(&e, "name", r->name ? r->name : "");
+ kv_unverified(&e, "path", r->path ? r->path : "");
+ kv_unverified(&e, "name", r->name ? r->name : "");
json_kv_string(&e, "payload_sha256", r->payload_hex);
json_obj_close(&e);