From: David Laight <David.Laight@ACULAB.COM>
To: 'Kuniyuki Iwashima' <kuniyu@amazon.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Allison Henderson <allison.henderson@oracle.com>
Cc: Kuniyuki Iwashima <kuni1840@gmail.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
"rds-devel@oss.oracle.com" <rds-devel@oss.oracle.com>
Subject: RE: [PATCH v2 net 3/5] net: Convert @kern of __sock_create() to enum.
Date: Thu, 29 Feb 2024 21:51:34 +0000 [thread overview]
Message-ID: <fdd655490688410497d82ff3d38da093@AcuMS.aculab.com> (raw)
In-Reply-To: <20240227011041.97375-4-kuniyu@amazon.com>
From: Kuniyuki Iwashima
> Sent: 27 February 2024 01:11
> Subject: [PATCH v2 net 3/5] net: Convert @kern of __sock_create() to enum.
Should probably be (something like):
Allow __sock_create() create kernel sockets that hold a reference
to the network namespace.
> Historically, syzbot has reported many use-after-free of struct
> net by kernel sockets.
>
> In most cases, the root cause was a timer kicked by a kernel socket
> which does not hold netns refcount nor clean it up during netns
> dismantle.
>
> This patch converts the @kern argument of __sock_create() to enum
> so that we can pass SOCKET_KERN_NET_REF and later sk_alloc() can
> hold refcount of net for kernel sockets.
I think you should add a 'hold netns' parameter to sock_create_kern().
Indeed, that is likely to be used for a real connection
(which would need the 'hold netns') and code that doesn't need it
(because the socket is some internal housekeeping socket) could
directly call __sock_create().
Fortunately both functions are exported non-gpl.
I've this comment in a driver...
/* sock_create_kern() creates a socket that doesn't hold a reference
* to the namespace (they get used for sockets needed by the protocol
* stack code itself).
* We need a socket that holds a reference to the namespace, so create
* a 'user' socket in a specific namespace.
* This adds an extra security check which we should pass because all the
* sockets are created by kernel threads.
*/
rval = __sock_create(net, family, type, protocol, sockp, 0);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-02-29 21:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 1:10 [PATCH v2 net 0/5] tcp/rds: Fix use-after-free around kernel TCP reqsk Kuniyuki Iwashima
2024-02-27 1:10 ` [PATCH v2 net 1/5] tcp: Restart iteration after removing reqsk in inet_twsk_purge() Kuniyuki Iwashima
2024-02-27 1:10 ` [PATCH v2 net 2/5] Revert "tcp: Clean up kernel listener's reqsk in inet_twsk_purge()" Kuniyuki Iwashima
2024-02-27 1:10 ` [PATCH v2 net 3/5] net: Convert @kern of __sock_create() to enum Kuniyuki Iwashima
2024-02-29 21:51 ` David Laight [this message]
2024-02-27 1:10 ` [PATCH v2 net 4/5] rds: tcp: Fix use-after-free of net in reqsk_timer_handler() Kuniyuki Iwashima
2024-02-27 12:06 ` Eric Dumazet
2024-02-28 2:24 ` Kuniyuki Iwashima
2024-02-27 1:10 ` [PATCH v2 net 5/5] tcp: Add assertion for reqsk->rsk_listener->sk_net_refcnt Kuniyuki Iwashima
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=fdd655490688410497d82ff3d38da093@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=allison.henderson@oracle.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@amazon.com \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rds-devel@oss.oracle.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).