On 17/01/2025 18:14, Sabrina Dubroca wrote:
2025-01-13, 10:31:31 +0100, Antonio Quartulli wrote:
+static int ovpn_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
int flags, int *addr_len)
+{
- int err = 0, off, copied = 0, ret;
- struct ovpn_socket *sock;
- struct ovpn_peer *peer;
- struct sk_buff *skb;
- rcu_read_lock();
- sock = rcu_dereference_sk_user_data(sk);
- if (!sock || !sock->peer) {
rcu_read_unlock();
return -EBADF;
- }
- /* we take a reference to the peer linked to this TCP socket, because
* in turn the peer holds a reference to the socket itself.
Going back now to this specific comment:
Not anymore since v12? [*]
I think it's ok here because we're only using peer and sk (not anything from ovpn_socket), but it is relevant in _sendmsg, which has the same peer_hold pattern without this comment.
After applying to _sendmsg() the modifications you suggested (i.e. reference peer directly instead of sock->peer), it also only uses peer and sk, but not ovpn_socket. Therefore it should be fine too.
This said, the comment above should go away or at least should be modified.
[*] v11:
- https://lore.kernel.org/netdev/20241029-b4-ovpn-v11-8-de4698c73a25@openvpn.n... ovpn_peer_release -> ovpn_socket_put
v12:
https://lore.kernel.org/netdev/20241202-b4-ovpn-v12-9-239ff733bf97@openvpn.n... ovpn_peer_release doesn't do ovpn_socket_put
https://lore.kernel.org/netdev/20241202-b4-ovpn-v12-7-239ff733bf97@openvpn.n... ovpn_socket_put is done directly at ovpn_peer_remove time, before the final peer_put
Right - the lifetime of ovpn_socket is not tied to ovpn_peer anymore. However, with the current code I don't think we ever assume that.
Regards,