Skip to content

Commit

Permalink
libxdp: Check program name when determining if a program is a dispatcher
Browse files Browse the repository at this point in the history
When loading a program from an interface, libxdp will try to determine
whether that program is a program dispatcher based on the BTF information.
However, if the xdp_pass program from the dispatcher object is loaded on
the interface, that will carry the BTF information with it, but the map
size check will fail. This in turn makes libxdp completely fail to
recognise the program.

To fix this, add a check for the program name before looking at the BTF
information when determining if the program is a dispatcher or not.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo committed Dec 13, 2022
1 parent 929a22e commit 074fcfb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/libxdp/libxdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,12 +1730,18 @@ int check_xdp_prog_version(const struct btf *btf, const char *name, __u32 *versi
return 0;
}

static int check_dispatcher_version(struct btf *btf)
static int check_dispatcher_version(const char *prog_name, struct btf *btf)
{
const char *name = "dispatcher_version";
__u32 version = 0;
int err;

if (prog_name && strcmp(prog_name, "xdp_dispatcher")) {
pr_debug("XDP program with name '%s' is not a dispatcher\n",
prog_name);
return -ENOENT;
}

err = check_xdp_prog_version(btf, name, &version);
if (err)
return err;
Expand Down Expand Up @@ -1869,7 +1875,7 @@ static int xdp_multiprog__fill_from_fd(struct xdp_multiprog *mp,
goto out;
}

err = check_dispatcher_version(btf);
err = check_dispatcher_version(info.name, btf);
if (err) {
if (err != -ENOENT) {
pr_warn("Dispatcher version check failed for ID %d\n",
Expand Down Expand Up @@ -2479,7 +2485,8 @@ static struct xdp_multiprog *xdp_multiprog__generate(struct xdp_program **progs,
goto err;
}

err = check_dispatcher_version(dispatcher->btf);
err = check_dispatcher_version(bpf_program__name(dispatcher->bpf_prog),
dispatcher->btf);
if (err) {
pr_warn("XDP dispatcher object version check failed: %s\n",
strerror(-err));
Expand Down

0 comments on commit 074fcfb

Please sign in to comment.