-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: relax return code check for subprograms
Currently verifier enforces return code checks for subprograms in the same manner as it does for program entry points. This prevents returning arbitrary scalar values from subprograms. Scalar type of returned values is checked by btf_prepare_func_args() and hence it should be safe to allow only scalars for now. Relax return code checks for subprograms and allow any correct scalar values. Signed-off-by: Dmitrii Banshchikov <me@ubique.spb.ru> Fixes: 51c39bb (bpf: Introduce function-by-function verification)
- Loading branch information
1 parent
5372d2a
commit f8ed257
Showing
3 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* Copyright (c) 2020 Facebook */ | ||
#include <stddef.h> | ||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
|
||
__attribute__ ((noinline)) | ||
int bar(struct __sk_buff *skb) | ||
{ | ||
return bpf_get_prandom_u32(); | ||
} | ||
|
||
static __always_inline int foo(struct __sk_buff *skb) | ||
{ | ||
if (!bar(skb)) | ||
return 0; | ||
|
||
return 1; | ||
} | ||
|
||
SEC("cgroup_skb/ingress") | ||
int test_cls(struct __sk_buff *skb) | ||
{ | ||
return foo(skb); | ||
} |