linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: remove unnecessary condition in bpf_check()
@ 2018-07-09 11:48 Tobias Tefke
  2018-07-09 23:01 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Tefke @ 2018-07-09 11:48 UTC (permalink / raw)
  To: tobias.tefke, ast, daniel; +Cc: netdev, linux-kernel

In the label skip_full_check the function sanitize_dead_code()
is being called if the return value equals zero.
After that call there is another condition checking
if the return value equals zero.
If this condition evaluates to true,
check_max_stack_depth() is being called.
However, sanitize_dead_code() has no return value.
Therefore the return value of bpf_check() is still the same
and the condition can be removed.

Signed-off-by: Tobias Tefke <tobias.tefke@tutanota.com>
---
 kernel/bpf/verifier.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9e2bf834f13a..b022d0a85427 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5935,11 +5935,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
 	while (!pop_stack(env, NULL, NULL));
 	free_states(env);
 
-	if (ret == 0)
+	if (ret == 0) {
 		sanitize_dead_code(env);
-
-	if (ret == 0)
 		ret = check_max_stack_depth(env);
+	}
 
 	if (ret == 0)
 		/* program is valid, convert *(u32*)(ctx + off) accesses */
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: remove unnecessary condition in bpf_check()
  2018-07-09 11:48 [PATCH] bpf: remove unnecessary condition in bpf_check() Tobias Tefke
@ 2018-07-09 23:01 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2018-07-09 23:01 UTC (permalink / raw)
  To: Tobias Tefke; +Cc: tobias.tefke, ast, daniel, netdev, linux-kernel

On Mon, Jul 09, 2018 at 01:48:37PM +0200, Tobias Tefke wrote:
> In the label skip_full_check the function sanitize_dead_code()
> is being called if the return value equals zero.
> After that call there is another condition checking
> if the return value equals zero.
> If this condition evaluates to true,
> check_max_stack_depth() is being called.
> However, sanitize_dead_code() has no return value.
> Therefore the return value of bpf_check() is still the same
> and the condition can be removed.
> 
> Signed-off-by: Tobias Tefke <tobias.tefke@tutanota.com>
> ---
>  kernel/bpf/verifier.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 9e2bf834f13a..b022d0a85427 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5935,11 +5935,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
>  	while (!pop_stack(env, NULL, NULL));
>  	free_states(env);
>  
> -	if (ret == 0)
> +	if (ret == 0) {
>  		sanitize_dead_code(env);
> -
> -	if (ret == 0)
>  		ret = check_max_stack_depth(env);
> +	}

Technically the patch is correct, but I think it would make
the code harder to read. I prefer to keep it as-is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-09 23:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-09 11:48 [PATCH] bpf: remove unnecessary condition in bpf_check() Tobias Tefke
2018-07-09 23:01 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).