🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Shihuang Liu Sun, 15 Nov 2026 15:24
[PATCH v1] net: sock_reuseport: check program type on the migration path
#16678
Author: Shihuang Liu
Date: Sun, 15 Nov 2026 15:24
68 lines
13147 bytes
From: Linux kernel audit <audit@example.invalid>

A BPF_PROG_TYPE_SOCKET_FILTER program can be loaded with
expected_attach_type set to BPF_SK_REUSEPORT_SELECT_OR_MIGRATE and
attached to a SO_REUSEPORT TCP group; both steps are allowed without
CAP_BPF.  Closing a listener that still has queued children then runs
that socket filter with a struct sk_reuseport_kern as its context,
while the program was verified against struct sk_buff.  It reads and
writes past the 56-byte object on the stack, which KASAN reports as a
stack-out-of-bounds in ___bpf_prog_run().

The cause is that reuseport_migrate_sock() decides from
prog->expected_attach_type alone.  That field is supplied by user
space and does not identify the program type, and
bpf_prog_load_check_attach() does not reject the value for
SOCKET_FILTER programs.

Fix this by requiring BPF_PROG_TYPE_SK_REUSEPORT before running the
program, and use the same check in reuseport_stop_listen_sock().
Socket filters can still be attached and used as selectors; the
selection path is unchanged.

Fixes: d5e4ddaeb6ab ("bpf: Support socket migration by eBPF.")
Signed-off-by: Linux kernel audit <audit@example.invalid>
---
 net/core/sock_reuseport.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -460,6 +460,18 @@
 }
 EXPORT_SYMBOL(reuseport_detach_sock);
 
+/*
+ * Only a BPF_PROG_TYPE_SK_REUSEPORT program is verified against
+ * struct sk_reuseport_kern, which is the context bpf_run_sk_reuseport()
+ * passes to it.  expected_attach_type is set by user space and does not
+ * identify the program type.
+ */
+static bool reuseport_is_migration_prog(const struct bpf_prog *prog)
+{
+	return prog && prog->type == BPF_PROG_TYPE_SK_REUSEPORT &&
+	       prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE;
+}
+
 void reuseport_stop_listen_sock(struct sock *sk)
 {
 	if (sk->sk_protocol == IPPROTO_TCP) {
@@ -474,7 +486,7 @@
 						 lockdep_is_held(&reuseport_lock));
 
 		if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req) ||
-		    (prog && prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE)) {
+		    reuseport_is_migration_prog(prog)) {
 			/* Migration capable, move sk from the listening section
 			 * to the closed section.
 			 */
@@ -644,7 +656,7 @@
 
 	hash = migrating_sk->sk_hash;
 	prog = rcu_dereference(reuse->prog);
-	if (!prog || prog->expected_attach_type != BPF_SK_REUSEPORT_SELECT_OR_MIGRATE) {
+	if (!reuseport_is_migration_prog(prog)) {
 		if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req))
 			goto select_by_hash;
 		goto failure;
Re: [PATCH v1] net: sock_reuseport: check program type on the migration path
#16681
Author: netdev-bot+sinfo
Date: Sun, 15 Nov 2026 15:28
19 lines
8406 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH v1] net: sock_reuseport: check program type on the migration path
#16686
Author: J4f J4f
Date: Sun, 15 Nov 2026 15:43
83 lines
15078 bytes
On Sun, 15 Nov 2026 at 23:24, Shihuang Liu <shlomojune6@gmail.com> wrote:
>
> From: Linux kernel audit <audit@example.invalid>
>
> A BPF_PROG_TYPE_SOCKET_FILTER program can be loaded with
> expected_attach_type set to BPF_SK_REUSEPORT_SELECT_OR_MIGRATE and
> attached to a SO_REUSEPORT TCP group; both steps are allowed without
> CAP_BPF.  Closing a listener that still has queued children then runs
> that socket filter with a struct sk_reuseport_kern as its context,
> while the program was verified against struct sk_buff.  It reads and
> writes past the 56-byte object on the stack, which KASAN reports as a
> stack-out-of-bounds in ___bpf_prog_run().
>
> The cause is that reuseport_migrate_sock() decides from
> prog->expected_attach_type alone.  That field is supplied by user
> space and does not identify the program type, and
> bpf_prog_load_check_attach() does not reject the value for
> SOCKET_FILTER programs.
>
> Fix this by requiring BPF_PROG_TYPE_SK_REUSEPORT before running the
> program, and use the same check in reuseport_stop_listen_sock().
> Socket filters can still be attached and used as selectors; the
> selection path is unchanged.
>
> Fixes: d5e4ddaeb6ab ("bpf: Support socket migration by eBPF.")
> Signed-off-by: Linux kernel audit <audit@example.invalid>
> ---

My mistake — I got the From: and Signed-off-by: wrong in v1.  Code and
commit message are unchanged; v2 will fix that.

Thanks
Shihuang
>  net/core/sock_reuseport.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -460,6 +460,18 @@
>  }
>  EXPORT_SYMBOL(reuseport_detach_sock);
>
> +/*
> + * Only a BPF_PROG_TYPE_SK_REUSEPORT program is verified against
> + * struct sk_reuseport_kern, which is the context bpf_run_sk_reuseport()
> + * passes to it.  expected_attach_type is set by user space and does not
> + * identify the program type.
> + */
> +static bool reuseport_is_migration_prog(const struct bpf_prog *prog)
> +{
> +       return prog && prog->type == BPF_PROG_TYPE_SK_REUSEPORT &&
> +              prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE;
> +}
> +
>  void reuseport_stop_listen_sock(struct sock *sk)
>  {
>         if (sk->sk_protocol == IPPROTO_TCP) {
> @@ -474,7 +486,7 @@
>                                                  lockdep_is_held(&reuseport_lock));
>
>                 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req) ||
> -                   (prog && prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE)) {
> +                   reuseport_is_migration_prog(prog)) {
>                         /* Migration capable, move sk from the listening section
>                          * to the closed section.
>                          */
> @@ -644,7 +656,7 @@
>
>         hash = migrating_sk->sk_hash;
>         prog = rcu_dereference(reuse->prog);
> -       if (!prog || prog->expected_attach_type != BPF_SK_REUSEPORT_SELECT_OR_MIGRATE) {
> +       if (!reuseport_is_migration_prog(prog)) {
>                 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req))
>                         goto select_by_hash;
>                 goto failure;
Re: [PATCH v1] net: sock_reuseport: check program type on the migration path
#17946
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 15:27
80 lines
11108 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] net: sock_reuseport: placeholder Signed-off-by trailer in commit
  message
- [Low] The commit message says loading a BPF_PROG_TYPE_SOCKET_FILTER
  program with expected_attach_type=BPF_SK_REUSEPORT_SELECT_OR_MIGRATE…

--

net: sock_reuseport: check program type on the migration path

This commit makes reuseport_migrate_sock() and reuseport_stop_listen_sock()
treat a reuseport program as migration capable only when its type is
BPF_PROG_TYPE_SK_REUSEPORT. Checking expected_attach_type alone allowed a
SOCKET_FILTER program to run with a struct sk_reuseport_kern context.

> A BPF_PROG_TYPE_SOCKET_FILTER program can be loaded with
> expected_attach_type set to BPF_SK_REUSEPORT_SELECT_OR_MIGRATE and
> attached to a SO_REUSEPORT TCP group; both steps are allowed without
> CAP_BPF.

[Severity: Low]
Is "both steps are allowed without CAP_BPF" accurate for a default
configuration?

In bpf_prog_load() in kernel/bpf/syscall.c, this check runs before the
SOCKET_FILTER/CGROUP_SKB exemption for unprivileged loads:

kernel/bpf/syscall.c:bpf_prog_load() {
    ...
	if (sysctl_unprivileged_bpf_disabled && !bpf_cap)
		goto put_token;
    ...
}

The sysctl starts at 2 when CONFIG_BPF_UNPRIV_DEFAULT_OFF is enabled:

int sysctl_unprivileged_bpf_disabled __read_mostly =
	IS_BUILTIN(CONFIG_BPF_UNPRIV_DEFAULT_OFF) ? 2 : 0;

That Kconfig option is "default y" in kernel/bpf/Kconfig. So on a default
kernel, a task without CAP_BPF (or a BPF token granting it) can't load the
socket filter in the first place. Unprivileged users can only reach the
out-of-bounds access when kernel.unprivileged_bpf_disabled has been set
to 0.

Could the commit message mention that the unprivileged case depends on
this sysctl? That would help backporters and security triage judge the
exposure. The code change itself is not affected by this.

[Severity: High]
The author and Signed-off-by trailer both use the identity
Linux kernel audit <audit@example.invalid>. That isn't a person, and
the .invalid TLD is reserved (RFC 2606), so the address can never
receive mail.

Signed-off-by is the Developer's Certificate of Origin described in
Documentation/process/submitting-patches.rst. It certifies that a
specific person wrote the change or has the right to pass it on under
the kernel's license. A placeholder identity can't make that
certification. Nobody can be reached at this address if questions
about the patch come up later, so this can't be applied as is.

Could you resend with the author and Signed-off-by set to your real
name and a working email address? If you're forwarding a change
written by someone else, it needs the original author's sign-off
followed by your own. The code change itself is not affected by this.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115152408.48205-1-shlomojune6%40gmail.com
Re: [PATCH v1] net: sock_reuseport: check program type on the migration path
#18608
Author: J4f J4f
Date: Wed, 18 Nov 2026 15:33
92 lines
15493 bytes
On Tue, 17 Nov 2026 at 23:27, <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] net: sock_reuseport: placeholder Signed-off-by trailer in commit
>   message
> - [Low] The commit message says loading a BPF_PROG_TYPE_SOCKET_FILTER
>   program with expected_attach_type=BPF_SK_REUSEPORT_SELECT_OR_MIGRATE…
>
> --
>
> net: sock_reuseport: check program type on the migration path
>
> This commit makes reuseport_migrate_sock() and reuseport_stop_listen_sock()
> treat a reuseport program as migration capable only when its type is
> BPF_PROG_TYPE_SK_REUSEPORT. Checking expected_attach_type alone allowed a
> SOCKET_FILTER program to run with a struct sk_reuseport_kern context.
>
> > A BPF_PROG_TYPE_SOCKET_FILTER program can be loaded with
> > expected_attach_type set to BPF_SK_REUSEPORT_SELECT_OR_MIGRATE and
> > attached to a SO_REUSEPORT TCP group; both steps are allowed without
> > CAP_BPF.
>
> [Severity: Low]
> Is "both steps are allowed without CAP_BPF" accurate for a default
> configuration?
>
> In bpf_prog_load() in kernel/bpf/syscall.c, this check runs before the
> SOCKET_FILTER/CGROUP_SKB exemption for unprivileged loads:
>
> kernel/bpf/syscall.c:bpf_prog_load() {
>     ...
>         if (sysctl_unprivileged_bpf_disabled && !bpf_cap)
>                 goto put_token;
>     ...
> }
>
> The sysctl starts at 2 when CONFIG_BPF_UNPRIV_DEFAULT_OFF is enabled:
>
> int sysctl_unprivileged_bpf_disabled __read_mostly =
>         IS_BUILTIN(CONFIG_BPF_UNPRIV_DEFAULT_OFF) ? 2 : 0;
>
> That Kconfig option is "default y" in kernel/bpf/Kconfig. So on a default
> kernel, a task without CAP_BPF (or a BPF token granting it) can't load the
> socket filter in the first place. Unprivileged users can only reach the
> out-of-bounds access when kernel.unprivileged_bpf_disabled has been set
> to 0.
>
> Could the commit message mention that the unprivileged case depends on
> this sysctl? That would help backporters and security triage judge the
> exposure. The code change itself is not affected by this.
>
> [Severity: High]
> The author and Signed-off-by trailer both use the identity
> Linux kernel audit <audit@example.invalid>. That isn't a person, and
> the .invalid TLD is reserved (RFC 2606), so the address can never
> receive mail.
>
> Signed-off-by is the Developer's Certificate of Origin described in
> Documentation/process/submitting-patches.rst. It certifies that a
> specific person wrote the change or has the right to pass it on under
> the kernel's license. A placeholder identity can't make that
> certification. Nobody can be reached at this address if questions
> about the patch come up later, so this can't be applied as is.
>
> Could you resend with the author and Signed-off-by set to your real
> name and a working email address? If you're forwarding a change
> written by someone else, it needs the original author's sign-off
> followed by your own. The code change itself is not affected by this.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115152408.48205-1-shlomojune6%40gmail.com

Will fix it.

pw-bot: cr
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads