linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leonard Crestez <cdleonard@gmail.com>
To: Eric Dumazet <edumazet@google.com>,
	"David S. Miller" <davem@davemloft.net>
Cc: David Ahern <dsahern@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: BUG: TCP timewait sockets survive across namespace creation in net-next
Date: Thu, 12 May 2022 21:01:08 +0300	[thread overview]
Message-ID: <93323bba-476e-f821-045c-9fe942143da9@gmail.com> (raw)

Hello,

It appears that in recent net-next versions it is possible for sockets 
in the timewait state to survive across namespace add/del. Timewait 
sockets are inserted into a global hash and only the sock_net value is 
compared when they are enumerated from interfaces like /proc/net/tcp and 
inet_diag. Old TW sockets are not cleared after namespace delete and 
namespaces are allocated from a slab and thus their pointers get reused 
a lot, when that happens timewait sockets from an old namespace will 
show up in the new one.

This can be reproduced by establishing a TCP connection over a veth pair 
between two namespaces, closing and then recreating those namespaces. 
Old timewait sockets will be visible and it happens quite reliably, 
often on the first iteration. I can try to provide a script for this.

I can't point to specific bugs outside of tests that explicitly 
enumerate timewait sockets but letting sk_net be a dangling pointer 
seems very dangerous. It also violates the idea of network namespaces 
being independent and isolated.

This does not happen in 5.17, I bisected this behavior to commit 
0dad4087a86a ("tcp/dccp: get rid of inet_twsk_purge()")

--
Regards,
Leonard

             reply	other threads:[~2022-05-12 18:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 18:01 Leonard Crestez [this message]
2022-05-12 18:13 ` BUG: TCP timewait sockets survive across namespace creation in net-next Eric Dumazet
2022-05-12 20:09   ` Eric Dumazet

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=93323bba-476e-f821-045c-9fe942143da9@gmail.com \
    --to=cdleonard@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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).