net: Fix two issues in sk_clone() error path.
Subsystems (3)
Kuniyuki Iwashima
maintainercover net: Fix two issues in sk_clone() error path.
Sashiko reported issues in the sk_clone() error path.
https://lore.kernel.org/bpf/[email protected]/
This series fixes them.
Note that Sashiko may point out the same issue for sk_bpf_storage, but the fix was already merged in the bpf tree:
7cbd0c4cebe4 ("bpf: Fix UAF in sock clone early bailouts")
Kuniyuki Iwashima (2):
soreuseport: Clear sk_reuseport_cb before failure in sk_clone().
net: Call net_enable_timestamp() before failure in sk_clone().
net/core/sock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Kuniyuki Iwashima
maintainerPATCH 1/2 soreuseport: Clear sk_reuseport_cb before failure in sk_clone().
When sk_clone() fails, sk_destruct() is called for the new socket.
If the parent socket has sk->sk_reuseport_cb, the child will call reuseport_detach_sock() for the reuseport group.
Let's clear sk->sk_reuseport_cb before any failure path in sk_clone().
Note that this was not a problem before the cited commit because reuseport_detach_sock() did nothing if the socket was not found in the reuseport array.
--- net/core/sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock.c +2 -2
@@ -2544,6 +2544,8 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,cgroup_sk_clone (&newsk->sk_cgrp_data); +RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); +rcu_read_lock (); filter =rcu_dereference (sk->sk_filter);if (filter !=NULL )
@@ -2566,8 +2568,6 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority, goto free; } -RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); -if (bpf_sk_storage_clone (sk, newsk)) goto free;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Re: [PATCH v1 net 1/2] soreuseport: Clear sk_reuseport_cb before failure in sk_clone().
Quoted 7 lines · Kuniyuki Iwashima
When
sk_clone()fails,sk_destruct()is called for the new socket.If the parent socket has
sk->sk_reuseport_cb, the child will callreuseport_detach_sock()for the reuseport group.Let's clear
sk->sk_reuseport_cbbefore any failure path insk_clone().
Quoted 8 lines
Note that this was not a problem before the cited commit because
reuseport_detach_sock()did nothing if the socket was not found in the reuseport array.Fixes 5dc4c4b7d4e8 ("bpf: Introduce BPF_MAP_TYPE_REUSEPORT_SOCKARRAY")Reported-by Sashiko <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v1 net 1/2] soreuseport: Clear sk_reuseport_cb before failure in sk_clone().
In reply to Kuniyuki IwashimaQuoted 8 lines · Kuniyuki Iwashima
When
sk_clone()fails,sk_destruct()is called for the new socket.If the parent socket has
sk->sk_reuseport_cb, the child will callreuseport_detach_sock()for the reuseport group.Let's clear
sk->sk_reuseport_cbbefore any failure path insk_clone().
Quoted 8 lines
Note that this was not a problem before the cited commit because
reuseport_detach_sock()did nothing if the socket was not found in the reuseport array.Fixes 5dc4c4b7d4e8 ("bpf: Introduce BPF_MAP_TYPE_REUSEPORT_SOCKARRAY")Reported-by Sashiko <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Quoted 30 lines
--- net/core/sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/core/sock.c +2
-3@@ -2544,6 +2544,8 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,cgroup_sk_clone (&newsk->sk_cgrp_data); +RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); +rcu_read_lock (); filter =rcu_dereference (sk->sk_filter);if (filter !=NULL )@@ -2566,8 +2568,6 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority, goto free; } -RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); -if (bpf_sk_storage_clone (sk, newsk)) goto free; --2.55.0.795.g602f6c329a-goog
Kuniyuki Iwashima
maintainerPATCH 2/2 net: Call net_enable_timestamp() before failure in sk_clone().
In reply to Kuniyuki IwashimaWhen sk_clone() fails, sk_destruct() is called for the new socket.
If the parent socket has SK_FLAGS_TIMESTAMP in sk->sk_flags, net_disable_timestamp() is called for the child socket even though net_enable_timestamp() is not called for it.
Let's call net_enable_timestamp() before any failure path in sk_clone().
--- net/core/sock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/sock.c +3 -3
@@ -2546,6 +2546,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); +if (sock_needs_netstamp (sk) && newsk->sk_flags &SK_FLAGS_TIMESTAMP ) +net_enable_timestamp (); +rcu_read_lock (); filter =rcu_dereference (sk->sk_filter);if (filter !=NULL )
@@ -2595,9 +2598,6 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,if (newsk->sk_prot->sockets_allocated)sk_sockets_allocated_inc (newsk); - -if (sock_needs_netstamp (sk) && newsk->sk_flags &SK_FLAGS_TIMESTAMP ) -net_enable_timestamp (); out:return newsk; free:
Signature · 1 line
2.55.0.795.g602f6c329a-goog
Re: [PATCH v1 net 2/2] net: Call net_enable_timestamp() before failure in sk_clone().
Quoted 6 lines · Kuniyuki Iwashima
When
sk_clone()fails,sk_destruct()is called for the new socket.If the parent socket has
SK_FLAGS_TIMESTAMPinsk->sk_flags,net_disable_timestamp()is called for the child socket even thoughnet_enable_timestamp()is not called for it.
Quoted 7 lines
Let's call
net_enable_timestamp()before any failure path insk_clone().Fixes 704da560c0a0 ("tcp: update the netstamp_needed counter when cloning sockets")Reported-by Sashiko <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v1 net 2/2] net: Call net_enable_timestamp() before failure in sk_clone().
In reply to Kuniyuki IwashimaQuoted 7 lines · Kuniyuki Iwashima
When
sk_clone()fails,sk_destruct()is called for the new socket.If the parent socket has
SK_FLAGS_TIMESTAMPinsk->sk_flags,net_disable_timestamp()is called for the child socket even thoughnet_enable_timestamp()is not called for it.
Quoted 7 lines
Let's call
net_enable_timestamp()before any failure path insk_clone().Fixes 704da560c0a0 ("tcp: update the netstamp_needed counter when cloning sockets")Reported-by Sashiko <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Quoted 32 lines
--- net/core/sock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/core/sock.c +3
-4@@ -2546,6 +2546,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,RCU_INIT_POINTER (newsk->sk_reuseport_cb,NULL ); +if (sock_needs_netstamp (sk) && newsk->sk_flags &SK_FLAGS_TIMESTAMP ) +net_enable_timestamp (); +rcu_read_lock (); filter =rcu_dereference (sk->sk_filter);if (filter !=NULL )@@ -2595,9 +2598,6 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,if (newsk->sk_prot->sockets_allocated)sk_sockets_allocated_inc (newsk); - -if (sock_needs_netstamp (sk) && newsk->sk_flags &SK_FLAGS_TIMESTAMP ) -net_enable_timestamp (); out:return newsk; free: --2.55.0.795.g602f6c329a-goog
Quoted 9 lines · Kuniyuki Iwashima
Sashiko reported issues in the
sk_clone()error path.https://lore.kernel.org/bpf/[email protected]/
This series fixes them.
Note that Sashiko may point out the same issue for
sk_bpf_storage, but the fix was already merged in the bpf tree:
Quoted 6 lines
7cbd0c4cebe4("bpf: Fix UAF in sock clone early bailouts")Kuniyuki Iwashima (2):
soreuseport: Clearsk_reuseport_cbbefore failure insk_clone().
net: Callnet_enable_timestamp()before failure insk_clone().
For the series:
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 9 Jul 2026 18:31:38 +0000 you wrote:
Sashiko reported issues in the
sk_clone()error path.https://lore.kernel.org/bpf/[email protected]/
This series fixes them.
Note that Sashiko may point out the same issue for
sk_bpf_storage, but the fix was already merged in the bpf tree:[...]
Here is the summary with links:
- [v1,net,1/2] soreuseport: Clear sk_reuseport_cb before failure in sk_clone().
https://git.kernel.org/netdev/net/c/98da8ce87dd5 - [v1,net,2/2] net: Call net_enable_timestamp() before failure in sk_clone(). https://git.kernel.org/netdev/net/c/d50557779257
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html