Skip to content

Commit 938cca9

Browse files
Tetsuo Handadavem330
authored andcommitted
sock: fix /proc/net/sockstat underflow in sk_clone_lock()
sk_clone_lock() needs to call sock_inuse_add(1) before entering the sk_free_unlock_clone() error path, for __sk_free() from sk_free() from sk_free_unlock_clone() calls sock_inuse_add(-1). Signed-off-by: Tetsuo Handa <[email protected]> Fixes: 648845a ("sock: Move the socket inuse to namespace.") Signed-off-by: David S. Miller <[email protected]>
1 parent 271351d commit 938cca9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/core/sock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,8 +2124,10 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
21242124
newsk->sk_prot_creator = prot;
21252125

21262126
/* SANITY */
2127-
if (likely(newsk->sk_net_refcnt))
2127+
if (likely(newsk->sk_net_refcnt)) {
21282128
get_net(sock_net(newsk));
2129+
sock_inuse_add(sock_net(newsk), 1);
2130+
}
21292131
sk_node_init(&newsk->sk_node);
21302132
sock_lock_init(newsk);
21312133
bh_lock_sock(newsk);
@@ -2197,8 +2199,6 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
21972199
newsk->sk_err_soft = 0;
21982200
newsk->sk_priority = 0;
21992201
newsk->sk_incoming_cpu = raw_smp_processor_id();
2200-
if (likely(newsk->sk_net_refcnt))
2201-
sock_inuse_add(sock_net(newsk), 1);
22022202

22032203
/* Before updating sk_refcnt, we must commit prior changes to memory
22042204
* (Documentation/RCU/rculist_nulls.rst for details)

0 commit comments

Comments
 (0)