Skip to content

Commit 87ebb62

Browse files
edumazetkuba-moo
authored andcommitted
net: clear sk->sk_ino in sk_set_socket(sk, NULL)
Andrei Vagin reported that blamed commit broke CRIU. Indeed, while we want to keep sk_uid unchanged when a socket is cloned, we want to clear sk->sk_ino. Otherwise, sock_diag might report multiple sockets sharing the same inode number. Move the clearing part from sock_orphan() to sk_set_socket(sk, NULL), called both from sock_orphan() and sk_clone_lock(). Fixes: 5d6b58c ("net: lockless sock_i_ino()") Closes: https://lore.kernel.org/netdev/[email protected]/ Closes: checkpoint-restore/criu#2744 Reported-by: Andrei Vagin <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Andrei Vagin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3fbfe25 commit 87ebb62

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/net/sock.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,9 @@ static inline void sk_set_socket(struct sock *sk, struct socket *sock)
20612061
if (sock) {
20622062
WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid);
20632063
WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino);
2064+
} else {
2065+
/* Note: sk_uid is unchanged. */
2066+
WRITE_ONCE(sk->sk_ino, 0);
20642067
}
20652068
}
20662069

@@ -2082,8 +2085,6 @@ static inline void sock_orphan(struct sock *sk)
20822085
sock_set_flag(sk, SOCK_DEAD);
20832086
sk_set_socket(sk, NULL);
20842087
sk->sk_wq = NULL;
2085-
/* Note: sk_uid is unchanged. */
2086-
WRITE_ONCE(sk->sk_ino, 0);
20872088
write_unlock_bh(&sk->sk_callback_lock);
20882089
}
20892090

0 commit comments

Comments
 (0)