Skip to content

eBPF-based security platform

upatch, status: show "?" for a location that cannot be resolved

Daniel Borkmann2ca36ace1790
diff --git a/Documentation/reference/cli/upatch-get.rst b/Documentation/reference/cli/upatch-get.rst
index 95f4a436..40d279b5 100644
--- a/Documentation/reference/cli/upatch-get.rst
+++ b/Documentation/reference/cli/upatch-get.rst
@@ -27,7 +27,7 @@ Description
``get`` opens the first link of the upatch ``<name>`` and reports:
- ``Location``: the attach point in ``SEC()`` form, for example
- ``fentry/do_nanosleep``.
+ ``fentry/do_nanosleep``, or ``?`` when it cannot be read.
- the program ID, the load time and the payload digest recorded on the
pin.
- ``Missed runs``: the runs of its programs the kernel skipped since the
diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rst
index 819adb97..408d07bc 100644
--- a/Documentation/reference/formats/status-json.rst
+++ b/Documentation/reference/formats/status-json.rst
@@ -474,7 +474,7 @@ upatches_loaded
* - ``location``
- string
- The attach point, for example ``fentry/do_nanosleep``; ``java``
- for a Java agent.
+ for a Java agent, ``?`` when it cannot be read.
* - ``status``
- string
- ``success``
diff --git a/builtin-status.c b/builtin-status.c
index 3fb72988..d16c3104 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -1647,9 +1647,9 @@ static size_t build_upatches_table(const struct status_view *v,
if (strscpy(r->name, name, sizeof(r->name)) < 0)
strscpy_literal(r->name, "?");
- upatch_resolve_location(vbtf, name,
- r->location,
- sizeof(r->location));
+ if (upatch_resolve_location(vbtf, name, r->location,
+ sizeof(r->location)))
+ strscpy_literal(r->location, "?");
upatch_loaded_at(name, r->loaded_at,
sizeof(r->loaded_at));
upatch_payload_sha256(name,
diff --git a/builtin-upatch.c b/builtin-upatch.c
index e519aee0..0b3e04c5 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -4388,8 +4388,9 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
upatch_payload_sha256(want, c->payload, sizeof(c->payload));
vbtf = btf__load_vmlinux_btf();
- upatch_resolve_location(vbtf, want, c->location,
- sizeof(c->location));
+ if (upatch_resolve_location(vbtf, want, c->location,
+ sizeof(c->location)))
+ strscpy_literal(c->location, "?");
c->missed_ret = upatch_each_link_misses(vbtf, want, keep_link_misses, c);
btf__free(vbtf);
@@ -4511,8 +4512,7 @@ static void render_get_text(const struct upatch_get_ctx *c,
age_from_ts(c->loaded_at, age, sizeof(age));
printf("%-22s %s\n", "Name:", c->upatch);
- printf("%-22s %s\n", "Location:",
- c->location[0] ? c->location : "?");
+ printf("%-22s %s\n", "Location:", c->location);
printf("%-22s %u\n", "Program ID:", c->prog_id);
if (c->loaded_at[0])
printf("%-22s %s%s%s%s\n", "Loaded at:", c->loaded_at,
diff --git a/util/upatch_maps.c b/util/upatch_maps.c
index 4965b02f..4ebc8062 100644
--- a/util/upatch_maps.c
+++ b/util/upatch_maps.c
@@ -55,8 +55,9 @@ static void resolve_map_location(struct map_view *v)
vbtf = btf__load_vmlinux_btf();
if (libbpf_get_error(vbtf))
vbtf = NULL;
- upatch_resolve_location(vbtf, v->upatch,
- v->location, sizeof(v->location));
+ if (upatch_resolve_location(vbtf, v->upatch, v->location,
+ sizeof(v->location)))
+ v->location[0] = '\0';
btf__free(vbtf);
}
diff --git a/util/upatch_table.c b/util/upatch_table.c
index 9174d78c..3cc06247 100644
--- a/util/upatch_table.c
+++ b/util/upatch_table.c
@@ -58,7 +58,7 @@ void upatch_table_print(const struct upatch_table_row *rows,
format_duration((long)r->age_sec, age, sizeof(age)))
strscpy_literal(age, "?");
printf(" %-24s %-28s %5u %6s %-28s %s\n", r->name,
- r->location[0] ? r->location : "-", r->n_maps,
+ r->location, r->n_maps,
missed_text(r, missed, sizeof(missed)),
r->status[0] ? r->status : "success", age);
}