Re: [PATCH net-next v18 12/25] ovpn: implement TCP transport

Sabrina Dubroca
2025-01-21T09:28:23Z

2025-01-20, 15:12:28 +0100, Antonio Quartulli wrote:
> 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.

It can probably go away completely, taking a ref on an object we're
clearly using is reasonable and I don't think it requires an
explanation, unlike the old scheme with dependencies (which was not
completely obvious). Thanks.

--
Sabrina