Commit 06cd4e9d authored by Daniel Müller's avatar Daniel Müller Committed by Andrii Nakryiko

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/#m55141e8f8cfd2e8d97e65328fa04852870d01af6Suggested-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220707211931.3415440-1-deso@posteo.net
parent 18410251
...@@ -1500,6 +1500,8 @@ static int bpf_core_composites_match(const struct btf *local_btf, const struct b ...@@ -1500,6 +1500,8 @@ static int bpf_core_composites_match(const struct btf *local_btf, const struct b
err = __bpf_core_types_match(local_btf, local_m->type, targ_btf, err = __bpf_core_types_match(local_btf, local_m->type, targ_btf,
targ_m->type, behind_ptr, level - 1); targ_m->type, behind_ptr, level - 1);
if (err < 0)
return err;
if (err > 0) { if (err > 0) {
matched = true; matched = true;
break; break;
...@@ -1512,7 +1514,8 @@ static int bpf_core_composites_match(const struct btf *local_btf, const struct b ...@@ -1512,7 +1514,8 @@ static int bpf_core_composites_match(const struct btf *local_btf, const struct b
return 1; return 1;
} }
/* Check that two types "match". /* Check that two types "match". This function assumes that root types were
* already checked for name match.
* *
* The matching relation is defined as follows: * The matching relation is defined as follows:
* - modifiers and typedefs are stripped (and, hence, effectively ignored) * - modifiers and typedefs are stripped (and, hence, effectively ignored)
...@@ -1561,6 +1564,10 @@ int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const st ...@@ -1561,6 +1564,10 @@ int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const st
if (!local_t || !targ_t) if (!local_t || !targ_t)
return -EINVAL; return -EINVAL;
/* While the name check happens after typedefs are skipped, root-level
* typedefs would still be name-matched as that's the contract with
* callers.
*/
if (!bpf_core_names_match(local_btf, local_t->name_off, targ_btf, targ_t->name_off)) if (!bpf_core_names_match(local_btf, local_t->name_off, targ_btf, targ_t->name_off))
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment