netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: James Chapman <jchapman@katalix.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org,
	tparkin@katalix.com, horms@kernel.org,
	syzbot+0e85b10481d2f5478053@syzkaller.appspotmail.com
Subject: Re: [PATCH v2 net-next 9/9] l2tp: flush workqueue before draining it
Date: Wed, 14 Aug 2024 11:01:22 -0700	[thread overview]
Message-ID: <Zrzw8oe+LBoTModP@pop-os.localdomain> (raw)
In-Reply-To: <6f0e2c8e-205c-71ae-2b93-02538122097a@katalix.com>

On Mon, Aug 12, 2024 at 10:24:11AM +0100, James Chapman wrote:
> On 11/08/2024 18:54, Cong Wang wrote:
> > On Wed, Aug 07, 2024 at 07:54:52AM +0100, James Chapman wrote:
> > > syzbot exposes a race where a net used by l2tp is removed while an
> > > existing pppol2tp socket is closed. In l2tp_pre_exit_net, l2tp queues
> > > TUNNEL_DELETE work items to close each tunnel in the net. When these
> > > are run, new SESSION_DELETE work items are queued to delete each
> > > session in the tunnel. This all happens in drain_workqueue. However,
> > > drain_workqueue allows only new work items if they are queued by other
> > > work items which are already in the queue. If pppol2tp_release runs
> > > after drain_workqueue has started, it may queue a SESSION_DELETE work
> > > item, which results in the warning below in drain_workqueue.
> > > 
> > > Address this by flushing the workqueue before drain_workqueue such
> > > that all queued TUNNEL_DELETE work items run before drain_workqueue is
> > > started. This will queue SESSION_DELETE work items for each session in
> > > the tunnel, hence pppol2tp_release or other API requests won't queue
> > > SESSION_DELETE requests once drain_workqueue is started.
> > > 
> > 
> > I am not convinced here.
> > 
> > 1) There is a __flush_workqueue() inside drain_workqueue() too. Why
> > calling it again?
> 
> Once drain_workqueue starts, it considers any new work item queued outside
> of its processing as an unexpected condition. By doing __flush_workqueue
> first, we ensure that all TUNNEL_DELETE items are processed, which means
> that SESSION_DELETE work items are queued for all existing sessions before
> drain_workqueue starts. Now if an API request is processed to delete a
> session, l2tp_session_delete will do nothing because session->dead has
> already been set.

What about the following case?

CPU 0			CPU1
test_and_set_bit()
			__flush_workqueue()
  queue_work()
  			drain_workqueue()

> 
> > 2) What prevents new work items be queued right between your
> > __flush_workqueue() and drain_workqueue()?
> 
> Hmm, to do so, a new tunnel would need to be created and then deleted by API
> request once drain_workqueue starts. Is it possible to create new sockets in
> a net once a net's pre_exit starts? I didn't think so, but I'll recheck.

I don't quite understand why you need to create a new one while tearing
down the old one(s). I think what you need here is some way to properly
waiting for the socket tear down to finish.

Thanks.

  reply	other threads:[~2024-08-14 18:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07  6:54 [PATCH v2 net-next 0/9] l2tp: misc improvements James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 1/9] documentation/networking: update l2tp docs James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 2/9] l2tp: remove inline from functions in c sources James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 3/9] l2tp: move l2tp_ip and l2tp_ip6 data to pernet James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 4/9] l2tp: handle hash key collisions in l2tp_v3_session_get James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 5/9] l2tp: add tunnel/session get_next helpers James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 6/9] l2tp: use get_next APIs for management requests and procfs/debugfs James Chapman
2024-08-11 18:36   ` Cong Wang
2024-08-12  8:14     ` James Chapman
2024-08-14 18:05       ` Cong Wang
2024-08-15  8:21         ` James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 7/9] l2tp: improve tunnel/session refcount helpers James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 8/9] l2tp: l2tp_eth: use per-cpu counters from dev->tstats James Chapman
2024-08-07  6:54 ` [PATCH v2 net-next 9/9] l2tp: flush workqueue before draining it James Chapman
2024-08-11 17:54   ` Cong Wang
2024-08-12  9:24     ` James Chapman
2024-08-14 18:01       ` Cong Wang [this message]
2024-08-11  3:52 ` [PATCH v2 net-next 0/9] l2tp: misc improvements patchwork-bot+netdevbpf

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=Zrzw8oe+LBoTModP@pop-os.localdomain \
    --to=xiyou.wangcong@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jchapman@katalix.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+0e85b10481d2f5478053@syzkaller.appspotmail.com \
    --cc=tparkin@katalix.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).