]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: Call net_enable_timestamp() before failure in sk_clone().
authorKuniyuki Iwashima <kuniyu@google.com>
Thu, 9 Jul 2026 18:31:40 +0000 (18:31 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 21 Jul 2026 16:14:59 +0000 (09:14 -0700)
When 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().

Fixes: 704da560c0a0 ("tcp: update the netstamp_needed counter when cloning sockets")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260709032007.9E4D61F000E9@smtp.kernel.org/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260709183315.965751-3-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/sock.c

index fc3ff0552d68cfa4882a1ab021ce8958cc36cd73..504d82a3aacd1fa775f1a726452a9f68147f6f1f 100644 (file)
@@ -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: