BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Alan Maguire <almagui@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH v1 bpf-next 3/7] bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functions
Date: Wed, 25 Nov 2026 13:38:15 +0000	[thread overview]
Message-ID: <awbkx6SJaw2Q-_dQ@mail.gmail.com> (raw)
In-Reply-To: <20261125102810.699464-4-a.s.protopopov@gmail.com>

On 26/11/25 10:28AM, Anton Protopopov wrote:
> The caller of such a function dereferences what an fmod_ret program
> returns. Functions on the error injection list like xe_device_create()
> return a pointer. Let the program return only NULL or an error pointer.
> 
> Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> ---
>  kernel/bpf/verifier.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 18c7b9a6f456..d2475edeecd9 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -19710,6 +19710,8 @@ static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)
>  static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range)
>  {
>  	enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
> +	const struct bpf_prog_aux *aux = env->prog->aux;
> +	const struct btf_type *t;
>  
>  	/* Default return value range. */
>  	*range = retval_range(0, 1);
> @@ -19762,8 +19764,19 @@ static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_
>  			*range = retval_range(0, 0);
>  			break;
>  		case BPF_TRACE_RAW_TP:
> -		case BPF_MODIFY_RETURN:
>  			return false;
> +		case BPF_MODIFY_RETURN:
> +			/* An extension replaces a global function of the program */
> +			if (!aux->attach_btf)
> +				return false;

This ^ check will also go away after Alexei's series
https://lore.kernel.org/bpf/20261125032938.670542-1-alexei.starovoitov@gmail.com/
lands.

> +			/* Allow only NULL or an error pointer for functions returning pointers */
> +			t = btf_type_skip_modifiers(aux->attach_btf,
> +						    aux->attach_func_proto->type, NULL);
> +			if (!btf_type_is_ptr(t))
> +				return false;
> +			*range = retval_range(-MAX_ERRNO, 0);
> +			break;
>  		case BPF_TRACE_ITER:
>  		default:
>  			break;
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-11-25 13:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 10:27 [PATCH v1 bpf-next 0/7] Tag fmod_ret functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 1/7] bpf: Require the JIT for fmod_ret programs on 64-bit functions Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 2/7] bpf: Remove a wrong comment about fmod_ret targets Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 3/7] bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functions Anton Protopopov
2026-11-25 10:47   ` bot+bpf-ci
2026-11-25 13:14     ` Anton Protopopov
2026-11-25 13:38   ` Anton Protopopov [this message]
2026-11-25 10:28 ` [PATCH v1 bpf-next 4/7] selftests/bpf: Test fmod_ret on a declared function that returns a pointer Anton Protopopov
2026-11-25 13:34   ` Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 5/7] bpf: Check fmod_ret return values of tagged pointer targets in 64 bits Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 6/7] resolve_btfids: Tag the functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 7/7] selftests/bpf: Test fmod_ret on functions that return a pointer Anton Protopopov

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=awbkx6SJaw2Q-_dQ@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=john.fastabend@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