Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Correctly propagate errors up from bpf_core_composites_match

This change addresses a comment made earlier [0] about a missing return
of an error when __bpf_core_types_match is invoked from
bpf_core_composites_match, which could have let to us erroneously
ignoring errors.

Regarding the typedef name check pointed out in the same context, it is
not actually an issue, because callers of the function perform a name
check for the root type anyway. To make that more obvious, let's add
comments to the function (similar to what we have for
bpf_core_types_are_compat, which is called in pretty much the same
context).

[0]: https://lore.kernel.org/bpf/165708121449.4919.13204634393477172905.git-patchwork-notify@kernel.org/T/#m55141e8f8cfd2e8d97e65328fa04852870d01af6

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Müller <deso@posteo.net>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220707211931.3415440-1-deso@posteo.net

authored by

Daniel Müller and committed by
Andrii Nakryiko
06cd4e9d 18410251

+8 -1
+8 -1
tools/lib/bpf/relo_core.c
··· 1500 1500 1501 1501 err = __bpf_core_types_match(local_btf, local_m->type, targ_btf, 1502 1502 targ_m->type, behind_ptr, level - 1); 1503 + if (err < 0) 1504 + return err; 1503 1505 if (err > 0) { 1504 1506 matched = true; 1505 1507 break; ··· 1514 1512 return 1; 1515 1513 } 1516 1514 1517 - /* Check that two types "match". 1515 + /* Check that two types "match". This function assumes that root types were 1516 + * already checked for name match. 1518 1517 * 1519 1518 * The matching relation is defined as follows: 1520 1519 * - modifiers and typedefs are stripped (and, hence, effectively ignored) ··· 1564 1561 if (!local_t || !targ_t) 1565 1562 return -EINVAL; 1566 1563 1564 + /* While the name check happens after typedefs are skipped, root-level 1565 + * typedefs would still be name-matched as that's the contract with 1566 + * callers. 1567 + */ 1567 1568 if (!bpf_core_names_match(local_btf, local_t->name_off, targ_btf, targ_t->name_off)) 1568 1569 return 0; 1569 1570