Linux Kernel Selftest development
 help / color / mirror / Atom feed
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,
	leon.hwang@linux.dev, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, martin.lau@linux.dev,
	mattbobrowski@google.com, memxor@gmail.com,
	menglong.dong@linux.dev, song@kernel.org, yangfeng@kylinos.cn,
	yonghong.song@linux.dev
Subject: Re: [PATCH v3 bpf-next 1/2] bpf: Fix Null-Pointer Dereference in kernel_clone() via BPF fmod_ret on security_task_alloc
Date: Tue, 21 Apr 2026 17:18:59 +0800	[thread overview]
Message-ID: <20260421091859.256592-1-yangfeng59949@163.com> (raw)
In-Reply-To: <20260411163556.8567-2-yangfeng59949@163.com>

[...]

Issue Regarding BPF_PROG_TYPE_EXT Programs Bypassing Validation Logic:

__attribute__ ((noinline)) int B()
{
        return 0; /* Valid return value */
}

SEC("fmod_ret/security_task_alloc")
int A()
{
        return B();
}

SEC("freplace/B")
int replace()
{
        return 1; /* Invalid return value */
}

This method can verify whether the return value of freplace is legitimate
by using env->prog->aux->dst_prog->aux->attach_btf_id.

However, this approach will reject legitimate programs if the return value of
the original program does not come from the replaced function (as shown below).

__attribute__ ((noinline)) int B()
{
        return 0; 
}

SEC("fmod_ret/security_task_alloc")
int A()
{
        B();
        return 0;
}

SEC("freplace/B")
int replace()
{
        return 1;
}

I have not found a proper solution to this issue.



target.bpf.c:
__attribute__ ((noinline)) int B()
{
	bpf_printk("--\n");
	return -2;	
}

SEC("fmod_ret/security_task_alloc")
int A()
{
	int i = B();
	bpf_printk("return: %d\n", i);
   	return i;
}

freplace.bpf.c:
SEC("freplace/B")
int replace()
{
	bpf_printk("freplace\n");
	return -1;
}
In addition, the log output from testing the above program is as follows:
cat /sys/kernel/debug/tracing/trace_pipe 
          attack-5370    [002] ...11  4379.086626: bpf_trace_printk: freplace

          attack-5370    [002] ...11  4379.086656: bpf_trace_printk: return: -2

Strangely, the replacement program is executed, but the return value still originates from the original program.



  parent reply	other threads:[~2026-04-21  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-11 16:35 [PATCH v3 bpf-next 0/2] bpf: Fix Null-Pointer Dereference in kernel_clone() via BPF fmod_ret on security_task_alloc Feng Yang
2026-04-11 16:35 ` [PATCH v3 bpf-next 1/2] " Feng Yang
2026-04-11 17:32   ` Alexei Starovoitov
2026-04-12  2:40     ` Feng Yang
2026-04-12  3:39   ` Menglong Dong
2026-04-13  1:58     ` Feng Yang
2026-04-21  9:18   ` Feng Yang [this message]
2026-04-11 16:35 ` [PATCH v3 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=20260421091859.256592-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=leon.hwang@linux.dev \
    --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=menglong.dong@linux.dev \
    --cc=song@kernel.org \
    --cc=yangfeng@kylinos.cn \
    --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