BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, memxor@gmail.com
Subject: Re: [PATCH v2 bpf-next 08/13] resolve_btfids: Don't list an error that follows work on an argument
Date: Fri, 13 Nov 2026 12:14:09 +0000	[thread overview]
Message-ID: <avb_ETHW4LCryuhQ@mail.gmail.com> (raw)
In-Reply-To: <20261113050901.1399091-9-alexei.starovoitov@gmail.com>

On 26/11/13 05:08AM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> A program that returns an error skips f(). A skip of f() is not a failure
> of f(). ksys_dup3() takes the lock and ends with "return do_dup2(..)":
> 
> 	static int do_dup2(..) __releases(&files->file_lock)
> 	..
> 	Ebusy:
> 		spin_unlock(&files->file_lock);
> 		return -EBUSY;
> 
> 	do_dup2() fails         dup2() = -EBUSY, the lock is free
> 	do_dup2() is skipped    dup2() = -EBUSY, the lock stays held
> 
> A caller can rely on what f() does on each path to "return e". The rule:
> 
> 	An error is not in the list if, on each path from the entry to its
> 	return, f() hands a pointer that is based on one of its pointer
> 	arguments to a callee that returns void.
> 
> A callee that returns void cannot fail: what it does to the object is done
> when f() returns the error. Most unlock, put, free and init functions
> return void. BTF says so, no name is needed. A callee that returns a value
> may have failed. "Based on": computed without a load, as &arg->lock is.
> 
> 	forward, may   the registers that hold a based pointer. A call that
> 	               hands one to a void callee is an effect. Does a path
> 	               without an effect lead from the entry to here?
> 	backward, may  the analysis that is there. It stops at an effect
> 
> f() stays a target if its list keeps an error.
> 
> 	                tagged            errors
> 	x86-64 GCC      12817 -> 11985    20967 -> 19248
> 	x86-64 clang    13549 -> 12633    22964 -> 20889
> 	arm64 clang     12435 -> 11543    21304 -> 19186
> The run on vmlinux takes 0.2 s more.
> 
> The tool does not see
>  - an unlock that is inlined: it is a store, not a call
>  - a callee that takes the object and returns a value, a computed callee
>  - a void callee without BTF: f.isra.0, a name that two functions have
>  - a pointer that was spilled to the stack, or loaded from the object
>  - that BUG() and panic() do not return: the next block counts as reached
> It also leaves out
>  - an error between mutex_lock(&arg->lock) and its unlock: both are void
>  - an error after a void callee that only prints a message about arg
> 
> Outline KASAN and KCSAN add void callees that get a pointer, such as
> __asan_load8(p) and __tsan_read8(p). Each read of *arg is an effect then:
> in 32 files of fs, net and mm 76 % of the errors go, not 6.5 %.
> Inline KASAN and KCOV: 6.3 % and 6.6 %. Targets are lost, none is added.
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

The robot's finding is real, otherwise

Acked-by: Anton Protopopov <a.s.protopopov@gmail.com>

  parent reply	other threads:[~2026-11-13 12:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  5:08 [PATCH v2 bpf-next 00/13] bpf: fmod_ret for each function that returns errors Alexei Starovoitov
2026-11-13  5:08 ` [PATCH v2 bpf-next 01/13] selftests/bpf: Don't depend on the width of a BTF id in verifier_live_stack Alexei Starovoitov
2026-11-13 11:13   ` Anton Protopopov
2026-11-13  5:08 ` [PATCH v2 bpf-next 02/13] resolve_btfids: Read the code of an ELF file by address Alexei Starovoitov
2026-11-13  5:08 ` [PATCH v2 bpf-next 03/13] resolve_btfids: Describe machine instructions with LLVM's MC layer Alexei Starovoitov
2026-11-13 11:45   ` Anton Protopopov
2026-11-13  5:08 ` [PATCH v2 bpf-next 04/13] resolve_btfids: Find the definitions that reach the return value Alexei Starovoitov
2026-11-13  5:08 ` [PATCH v2 bpf-next 05/13] resolve_btfids: Tag the functions that return errors Alexei Starovoitov
2026-11-13  5:08 ` [PATCH v2 bpf-next 06/13] resolve_btfids: Fold the constants of a select without a branch Alexei Starovoitov
2026-11-13 11:59   ` Anton Protopopov
2026-11-13  5:08 ` [PATCH v2 bpf-next 07/13] resolve_btfids: Say which registers an instruction reads Alexei Starovoitov
2026-11-13 12:03   ` Anton Protopopov
2026-11-13  5:08 ` [PATCH v2 bpf-next 08/13] resolve_btfids: Don't list an error that follows work on an argument Alexei Starovoitov
2026-11-13  5:52   ` bot+bpf-ci
2026-11-13 12:14   ` Anton Protopopov [this message]
2026-11-13  5:08 ` [PATCH v2 bpf-next 09/13] bpf: Allow fmod_ret on tagged functions and check the return value Alexei Starovoitov
2026-11-13  5:52   ` bot+bpf-ci
2026-11-13 12:20   ` Anton Protopopov
2026-11-13  5:08 ` [PATCH v2 bpf-next 10/13] selftests/bpf: Test fmod_ret on tagged functions Alexei Starovoitov
2026-11-13  5:08 ` [PATCH v2 bpf-next 11/13] bpf: Mark the arguments of fmod_ret progs as PTR_UNTRUSTED Alexei Starovoitov
2026-11-13 11:09   ` Anton Protopopov
2026-11-13  5:09 ` [PATCH v2 bpf-next 12/13] bpf: Treat the type of an untrusted pointer as a hint Alexei Starovoitov
2026-11-13  5:52   ` bot+bpf-ci
2026-11-13  5:09 ` [PATCH v2 bpf-next 13/13] selftests/bpf: Test untrusted pointers in fmod_ret progs Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avb_ETHW4LCryuhQ@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox