From: Jason Wang <jasowang@redhat.com>
To: Cong Wang <xiyou.wangcong@gmail.com>,
Eric Dumazet <eric.dumazet@gmail.com>
Cc: syzbot <syzbot+e8b902c3c3fadf0a9dba@syzkaller.appspotmail.com>,
David Miller <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
LKML <linux-kernel@vger.kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Linux Kernel Network Developers <netdev@vger.kernel.org>,
Petar Penkov <peterpenkov96@gmail.com>,
Sabrina Dubroca <sd@queasysnail.net>,
syzkaller-bugs@googlegroups.com
Subject: Re: BUG: spinlock bad magic in tun_do_read
Date: Wed, 9 May 2018 11:38:11 +0800 [thread overview]
Message-ID: <9992abe5-57e6-4c2c-601d-fead7e441696@redhat.com> (raw)
In-Reply-To: <CAM_iQpW+vrecKuWTJ+zHt11ge7xPRWt=4GmZJxJ5Ffp_awV-ag@mail.gmail.com>
On 2018年05月09日 10:50, Cong Wang wrote:
> On Mon, May 7, 2018 at 11:04 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>
>> On 05/07/2018 10:54 PM, Cong Wang wrote:
>>> Yeah, we should return early before hitting this uninitialized ptr ring...
>>> Something like:
>>>
>>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>>> index ef33950a45d9..638c87a95247 100644
>>> --- a/drivers/net/tun.c
>>> +++ b/drivers/net/tun.c
>>> @@ -2128,6 +2128,9 @@ static void *tun_ring_recv(struct tun_file
>>> *tfile, int noblock, int *err)
>>> void *ptr = NULL;
>>> int error = 0;
>>>
>>> + if (!tfile->tx_ring.queue)
>>> + goto out;
>>> +
>>>
>>> Or, checking if tun is detached...
>>>
>>>
>> tx_ring was properly initialized when first ptr_ring_consume() at line 2131 was attempted.
>>
>> The bug happens later at line 2143 , after a schedule() call, line 2155
>>
>> So a single check at function prologue wont solve the case the thread had to sleep,
>> then some uninit happened.
>
> Very good point. RTNL lock is supposed to protect cleanup path, but I don't
> think we can acquire RTNL for tun_chr_read_iter() path...
I think the root cause is we try to initialize ptr ring during TUNSETIFF
since the length depends on the dev->tx_queue_len and try to destroy it
when device is gone. We can solve this by initializing a zero size
ptr_ring during open() and resize if necessary. Then there no need for
any workaround like memset and checking against NULL.
Let me try to cook a patch for this.
Thanks
prev parent reply other threads:[~2018-05-09 3:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-08 5:27 syzbot
2018-05-08 5:54 ` Cong Wang
2018-05-08 6:04 ` Eric Dumazet
2018-05-09 2:50 ` Cong Wang
2018-05-09 3:38 ` Jason Wang [this message]
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=9992abe5-57e6-4c2c-601d-fead7e441696@redhat.com \
--to=jasowang@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=peterpenkov96@gmail.com \
--cc=sd@queasysnail.net \
--cc=syzbot+e8b902c3c3fadf0a9dba@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=xiyou.wangcong@gmail.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
all inboxes | Powered by JetHome®