Re: [PATCH net 3/3] vsock: Fix transport_* TOCTOU
From: Michal Luczaj
Date: Fri Jun 20 2025 - 08:58:26 EST
On 6/20/25 10:37, Stefano Garzarella wrote:
>> - if (!new_transport || !try_module_get(new_transport->module))
>> - return -ENODEV;
>> + if (!new_transport || !try_module_get(new_transport->module)) {
>> + ret = -ENODEV;
>> + goto unlock;
>> + }
>> +
>
> I'd add a comment here to explain that we can release it since we
> successfully increased the `new_transport` refcnt.
Sure, will do.
>> + mutex_unlock(&vsock_register_mutex);
>>
>> if (sk->sk_type == SOCK_SEQPACKET) {
>> if (!new_transport->seqpacket_allow ||
>> @@ -528,6 +539,9 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
>> vsk->transport = new_transport;
>>
>> return 0;
>> +unlock:
>
> I'd call it `err:` so it's clear is the error path.
Right, that makes sense.
Thanks!
Michal