Netdev List
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: yangyingliang@huawei.com
Cc: netdev@vger.kernel.org, jasowang@redhat.com,
	eric.dumazet@gmail.com, xiyou.wangcong@gmail.com,
	weiyongjun1@huawei.com
Subject: Re: [PATCH v4] tun: fix use-after-free when register netdev failed
Date: Thu, 12 Sep 2019 12:18:33 +0200 (CEST)	[thread overview]
Message-ID: <20190912.121833.160552401560653311.davem@davemloft.net> (raw)
In-Reply-To: <1568113017-79840-1-git-send-email-yangyingliang@huawei.com>

From: Yang Yingliang <yangyingliang@huawei.com>
Date: Tue, 10 Sep 2019 18:56:57 +0800

> I got a UAF repport in tun driver when doing fuzzy test:
 ...
> tun_chr_read_iter() accessed the memory which freed by free_netdev()
> called by tun_set_iff():
> 
>         CPUA                                           CPUB
>   tun_set_iff()
>     alloc_netdev_mqs()
>     tun_attach()
>                                                   tun_chr_read_iter()
>                                                     tun_get()
>                                                     tun_do_read()
>                                                       tun_ring_recv()
>     register_netdevice() <-- inject error
>     goto err_detach
>     tun_detach_all() <-- set RCV_SHUTDOWN
>     free_netdev() <-- called from
>                      err_free_dev path
>       netdev_freemem() <-- free the memory
>                         without check refcount
>       (In this path, the refcount cannot prevent
>        freeing the memory of dev, and the memory
>        will be used by dev_put() called by
>        tun_chr_read_iter() on CPUB.)
>                                                      (Break from tun_ring_recv(),
>                                                      because RCV_SHUTDOWN is set)
>                                                    tun_put()
>                                                      dev_put() <-- use the memory
>                                                                    freed by netdev_freemem()
> 
> Put the publishing of tfile->tun after register_netdevice(),
> so tun_get() won't get the tun pointer that freed by
> err_detach path if register_netdevice() failed.
> 
> Fixes: eb0fb363f920 ("tuntap: attach queue 0 before registering netdevice")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Suggested-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Applied, thanks.

      parent reply	other threads:[~2019-09-12 10:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10 10:56 [PATCH v4] tun: fix use-after-free when register netdev failed Yang Yingliang
2019-09-11  2:57 ` Jason Wang
2019-09-12 10:18 ` David Miller [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=20190912.121833.160552401560653311.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=weiyongjun1@huawei.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yangyingliang@huawei.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