From: Feng Yang <yangfeng59949@163.com>
To: yangfeng59949@163.com
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, eddyz87@gmail.com, jiayuan.chen@linux.dev,
john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
martin.lau@linux.dev, mattbobrowski@google.com, memxor@gmail.com,
song@kernel.org, yonghong.song@linux.dev
Subject: [PATCH v2 bpf-next 1/2] bpf: Fix Null-Pointer Dereference in kernel_clone() via BPF fmod_ret on security_task_alloc
Date: Fri, 10 Apr 2026 16:03:35 +0800 [thread overview]
Message-ID: <20260410080335.196379-1-yangfeng59949@163.com> (raw)
In-Reply-To: <20260410061037.149532-2-yangfeng59949@163.com>
[...]
> +static int modify_return_get_retval_range(const struct bpf_prog *prog,
> + struct bpf_retval_range *retval_range)
> +{
> + unsigned long addr = (unsigned long)prog->aux->dst_trampoline->func.addr;
> +
> + if (within_error_injection_list(addr)) {
> + switch (get_injectable_error_type(addr)) {
> + case EI_ETYPE_NULL:
> + retval_range->minval = 0;
> + retval_range->maxval = 0;
> + break;
> + case EI_ETYPE_ERRNO:
> + retval_range->minval = -MAX_ERRNO;
> + retval_range->maxval = -1;
> + break;
This refers to the documentation in fault-injection.rst:
Each error injectable functions will have the error type specified by the
ALLOW_ERROR_INJECTION() macro. You have to choose it carefully if you add
a new error injectable function. If the wrong error type is chosen, the
kernel may crash because it may not be able to handle the error.
There are 4 types of errors defined in include/asm-generic/error-injection.h
EI_ETYPE_NULL
This function will return `NULL` if it fails. e.g. return an allocated
object address.
EI_ETYPE_ERRNO
This function will return an `-errno` error code if it fails. e.g. return
-EINVAL if the input is wrong. This will include the functions which will
return an address which encodes `-errno` by ERR_PTR() macro.
EI_ETYPE_ERRNO_NULL
This function will return an `-errno` or `NULL` if it fails. If the caller
of this function checks the return value with IS_ERR_OR_NULL() macro, this
type will be appropriate.
EI_ETYPE_TRUE
This function will return `true` (non-zero positive value) if it fails.
Restrict EI_ETYPE_ERRNO to only return error codes.
However, it was noticed that the self-test bpf_testmod_test_read uses
ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO); and returns 0, which causes a failure.
So should returning 0 be considered valid for the EI_ETYPE_ERRNO type, or should the self-test be modified instead?
Thanks.
> + case EI_ETYPE_ERRNO_NULL:
> + retval_range->minval = -MAX_ERRNO;
> + retval_range->maxval = 0;
> + break;
> + case EI_ETYPE_TRUE:
> + retval_range->minval = 1;
> + retval_range->maxval = 1;
> + break;
> + }
> + retval_range->return_32bit = true;
> +
> + return 0;
> + }
> +
> + return -EINVAL;
> +}
next prev parent reply other threads:[~2026-04-10 8:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 6:10 [PATCH v2 bpf-next 0/2] bpf: Fix Null-Pointer Dereference in kernel_clone() via BPF fmod_ret on security_task_alloc Feng Yang
2026-04-10 6:10 ` [PATCH v2 bpf-next 1/2] " Feng Yang
2026-04-10 7:00 ` bot+bpf-ci
2026-04-10 8:24 ` Feng Yang
2026-04-10 7:21 ` Leon Hwang
2026-04-10 7:36 ` Leon Hwang
2026-04-10 7:40 ` Feng Yang
2026-04-10 7:49 ` Leon Hwang
2026-04-10 8:07 ` Feng Yang
2026-04-10 8:03 ` Feng Yang [this message]
2026-04-10 8:27 ` Leon Hwang
2026-04-10 9:20 ` Menglong Dong
2026-04-10 6:10 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add selftests for verifying return values of fmod_ret Feng Yang
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=20260410080335.196379-1-yangfeng59949@163.com \
--to=yangfeng59949@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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