[lvc-project] [PATCH] [RFC] net: smc: fix fasync leak in smc_release()

Wen Gu guwen at linux.alibaba.com
Wed Mar 6 17:45:56 MSK 2024



On 2024/3/5 00:35, Dmitry Antipov wrote:
> On 2/23/24 06:36, Wen Gu wrote:
> 
>> One solution to this issue I can think of is to check whether
>> filp->private_data has been changed when the sock_fasync holds the sock lock,
>> but it inevitably changes the general code..
>>
>> diff --git a/net/socket.c b/net/socket.c
>> index ed3df2f749bf..a28435195854 100644
>> --- a/net/socket.c
>> +++ b/net/socket.c
>> @@ -1443,6 +1443,11 @@ static int sock_fasync(int fd, struct file *filp, int on)
>>                  return -EINVAL;
>>
>>          lock_sock(sk);
>> +       /* filp->private_data has changed */
>> +       if (on && unlikely(sock != filp->private_data)) {
>> +               release_sock(sk);
>> +               return -EAGAIN;
>> +       }
>>          fasync_helper(fd, filp, on, &wq->fasync_list);
>>
>>          if (!wq->fasync_list)
>>
>> Let's see if anyone else has a better idea.
> 
> IIUC this is not a solution just because it decreases the probability of the race
> but doesn't eliminate it completely - an underlying socket switch (e.g. changing
> 'filp->private_data') may happen when 'fasync_helper()' is in progress.
> 
Hi Dmitry,

IIUC, the fallback (or more precisely the private_data change) essentially
always happens when the lock_sock(smc->sk) is held, except in smc_listen_work()
or smc_listen_decline(), but at that moment, userspace program can not yet
acquire this new socket to add fasync entries to the fasync_list.

So IMHO, the above patch should work, since it checks the private_data under
the lock_sock(sk). But if I missed something, please correct me.

And I wonder if you can still see the leak with the patch above through
your reproducer or syzbot's reproducer? I once ran your reproducer for about
50 mins and didn't see the leak.

Thanks!

> Dmitry
> 
> 



More information about the lvc-project mailing list