From: Wen Gu <guwen@linux.alibaba.com>
To: Dmitry Antipov <dmantipov@yandex.ru>,
"wenjia@linux.ibm.com" <wenjia@linux.ibm.com>
Cc: "lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>,
"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"jaka@linux.ibm.com" <jaka@linux.ibm.com>
Subject: Re: [lvc-project] [PATCH] [RFC] net: smc: fix fasync leak in smc_release()
Date: Wed, 6 Mar 2024 22:45:56 +0800 [thread overview]
Message-ID: <2c9c9ffe-13c4-44b8-982a-a3b4070b8a11@linux.alibaba.com> (raw)
In-Reply-To: <380043fa-3208-4856-92b1-be9c87caeeb6@yandex.ru>
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
>
>
next prev parent reply other threads:[~2024-03-06 14:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 5:16 [PATCH] [RFC] net: smc: fix fasync leak in smc_release() Dmitry Antipov
2024-02-21 13:09 ` Wen Gu
2024-02-21 15:02 ` [lvc-project] " Antipov, Dmitriy
2024-02-23 3:36 ` Wen Gu
2024-03-04 16:35 ` Dmitry Antipov
2024-03-06 14:45 ` Wen Gu [this message]
2024-03-06 18:07 ` Dmitry Antipov
2024-03-07 8:58 ` Jan Karcher
2024-03-07 9:57 ` Jan Karcher
2024-03-07 10:21 ` Antipov, Dmitriy
2024-03-26 8:18 ` Antipov, Dmitriy
2024-03-27 6:12 ` Wen Gu
2024-03-07 13:53 ` Wen Gu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c9c9ffe-13c4-44b8-982a-a3b4070b8a11@linux.alibaba.com \
--to=guwen@linux.alibaba.com \
--cc=dmantipov@yandex.ru \
--cc=jaka@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=wenjia@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).