All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miguel Gazquez (Schneider Electric)" <miguel.gazquez@bootlin.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.12.y] tcp: clear sock_ops cb flags before force-closing a child socket
Date: Mon, 07 Sep 2026 17:14:16 +0000	[thread overview]
Message-ID: <20260907171417.559201F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907-cve-2026-74268-v1-1-cacea38d7fb3@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Calling tcp_clear_sock_ops_cb_flags() unconditionally on non-TCP sockets (like DCCP) causes an out-of-bounds write due to an invalid struct tcp_sock cast.
--

commit a1e4666cc30271c086f6d9e64c6ebfaddd6750ca
Author: Sechang Lim <rhkrqnwk98@gmail.com>

tcp: clear sock_ops cb flags before force-closing a child socket

A child socket inherits the listener's bpf_sock_ops_cb_flags via
sk_clone_lock(). If its setup fails in tcp_v4_syn_recv_sock() /
tcp_v6_syn_recv_sock(), the child is freed through put_and_exit, where
inet_csk_prepare_forced_close() drops the socket lock and tcp_done() runs
without it.

Link: https://patch.msgid.link/20260611092923.1895982-1-rhkrqnwk98@gmail.com

> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 1cc25e0b3bdea..c472c1cdd3b83 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
[ ... ]
> @@ -2702,6 +2702,11 @@ static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
>  	return tcp_call_bpf(sk, op, 3, args);
>  }
>  
> +static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
> +{
> +	tcp_sk(sk)->bpf_sock_ops_cb_flags = 0;

[Severity: Critical]
Does this code perform an unsafe cast and memory write for non-TCP sockets?

This accesses an offset that exceeds the bounds of a dccp_sock when
invoked on DCCP sockets, which writes outside the slab allocation for the
socket structure.

> +}
> +
[ ... ]
> diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
> index 91dcdb7567ace..e0bd8e76fa781 100644
> --- a/net/ipv4/inet_connection_sock.c
> +++ b/net/ipv4/inet_connection_sock.c
[ ... ]
> @@ -1315,6 +1315,14 @@ void inet_csk_destroy_sock(struct sock *sk)
>  }
>  EXPORT_SYMBOL(inet_csk_destroy_sock);
>  
> +void inet_csk_prepare_for_destroy_sock(struct sock *sk)
> +{
> +	/* The below has to be done to allow calling inet_csk_destroy_sock */
> +	tcp_clear_sock_ops_cb_flags(sk);

[Severity: Critical]
Can calling this unconditionally on non-TCP sockets cause memory regressions?

This generic connection socket destruction path in
inet_csk_prepare_for_destroy_sock() blindly invokes a TCP-specific helper,
passing it sockets (like DCCP) that are incompatible with the TCP socket
structure.

This can be triggered by a remote, unauthenticated attacker sending a
malicious or unroutable DCCP connection request to a listening DCCP port.

The regression is triggered on the failure path of DCCP connection setup,
for example when routing fails:

net/dccp/ipv4.c:dccp_v4_request_recv_sock()
   ...
   put_and_exit:
        ...
        inet_csk_prepare_forced_close(newsk);
            inet_csk_prepare_for_destroy_sock(newsk);
                tcp_clear_sock_ops_cb_flags(newsk); /* out-of-bounds write */

> +	sock_set_flag(sk, SOCK_DEAD);
> +	this_cpu_inc(*sk->sk_prot->orphan_count);
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260907-cve-2026-74268-v1-1-cacea38d7fb3@bootlin.com?part=1

  reply	other threads:[~2026-09-07 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 17:02 [PATCH 6.12.y] tcp: clear sock_ops cb flags before force-closing a child socket Miguel Gazquez (Schneider Electric)
2026-09-07 17:14 ` sashiko-bot [this message]
2026-09-08  0:53 ` Sasha Levin

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=20260907171417.559201F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=miguel.gazquez@bootlin.com \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.