diff mbox series

[bpf-next] bpf: Correctly propagate errors up from bpf_core_composites_match

Message ID 20220707211931.3415440-1-deso@posteo.net (mailing list archive)
State Accepted
Commit 06cd4e9d5d969d713e6b710f0e5ca0bc8476ae41
Delegated to: BPF
Headers show
Series [bpf-next] bpf: Correctly propagate errors up from bpf_core_composites_match | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4 this patch: 4
netdev/cc_maintainers warning 6 maintainers not CCed: netdev@vger.kernel.org songliubraving@fb.com yhs@fb.com john.fastabend@gmail.com kafai@fb.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc

Commit Message

Daniel Müller July 7, 2022, 9:19 p.m. UTC
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>
---
 tools/lib/bpf/relo_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org July 8, 2022, 10:40 p.m. UTC | #1
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu,  7 Jul 2022 21:19:31 +0000 you wrote:
> 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).
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: Correctly propagate errors up from bpf_core_composites_match
    https://git.kernel.org/bpf/bpf-next/c/06cd4e9d5d96

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index fe25330..c4b0e8 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -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,
 						     targ_m->type, behind_ptr, level - 1);
+			if (err < 0)
+				return err;
 			if (err > 0) {
 				matched = true;
 				break;
@@ -1512,7 +1514,8 @@  static int bpf_core_composites_match(const struct btf *local_btf, const struct b
 	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:
  * - 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
 	if (!local_t || !targ_t)
 		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))
 		return 0;