On Thu, Oct 31, 2024 at 1:06 PM Wang Liang <wangliang74@xxxxxxxxxx> wrote:Yes,I find the report here (the C repo in the url is useful):
Syzkaller reported this warning:Was this a public report ?
Thank you very much for your suggestion and patch![ 65.568203][ C0] ------------[ cut here ]------------Oh the horror, this is completely wrong and unsafe anyway.
[ 65.569339][ C0] WARNING: CPU: 0 PID: 16 at net/ipv4/af_inet.c:156 inet_sock_destruct+0x1c5/0x1e0
[ 65.575017][ C0] Modules linked in:
[ 65.575699][ C0] CPU: 0 UID: 0 PID: 16 Comm: ksoftirqd/0 Not tainted 6.12.0-rc5 #26
[ ...]
TCP listen path MUST be lockless, and stay lockless.
Ask yourself : Why would a listener even hold a pktoptions in the first place ?
Normally, each request socket can hold an ireq->pktopts (see in
tcp_v6_init_req())
The skb_clone_and_charge_r() happen later in tcp_v6_syn_recv_sock()
The correct fix is to _not_ call skb_clone_and_charge_r() for a
listener socket, of course, this never made _any_ sense.
The following patch should fix both TCP and DCCP, and as a bonus make
TCP SYN processing faster
for listeners requesting these IPV6_PKTOPTIONS things.
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index da5dba120bc9a55c5fd9d6feda791b0ffc887423..d6649246188d72b3df6c74750779b7aa5910dcb7
100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -618,7 +618,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct
sk_buff *skb)
by tcp. Feel free to propose better solution.
--ANK (980728)
*/
- if (np->rxopt.all)
+ if (np->rxopt.all && sk->sk_state != DCCP_LISTEN)
opt_skb = skb_clone_and_charge_r(skb, sk);
if (sk->sk_state == DCCP_OPEN) { /* Fast path */
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index d71ab4e1efe1c6598cf3d3e4334adf0881064ce9..e643dbaec9ccc92eb2d9103baf185c957ad1dd2e
100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1605,25 +1605,12 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
* is currently called with bh processing disabled.
*/
- /* Do Stevens' IPV6_PKTOPTIONS.
-
- Yes, guys, it is the only place in our code, where we
- may make it not affecting IPv4.
- The rest of code is protocol independent,
- and I do not like idea to uglify IPv4.
-
- Actually, all the idea behind IPV6_PKTOPTIONS
- looks not very well thought. For now we latch
- options, received in the last packet, enqueued
- by tcp. Feel free to propose better solution.
- --ANK (980728)
- */
- if (np->rxopt.all)
- opt_skb = skb_clone_and_charge_r(skb, sk);
if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
struct dst_entry *dst;
+ if (np->rxopt.all)
+ opt_skb = skb_clone_and_charge_r(skb, sk);
dst = rcu_dereference_protected(sk->sk_rx_dst,
lockdep_sock_is_held(sk));
@@ -1656,13 +1643,13 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
if (reason)
goto reset;
}
- if (opt_skb)
- __kfree_skb(opt_skb);
return 0;
}
} else
sock_rps_save_rxhash(sk, skb);
+ if (np->rxopt.all)
+ opt_skb = skb_clone_and_charge_r(skb, sk);
reason = tcp_rcv_state_process(sk, skb);
if (reason)
goto reset;