netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Kuniyuki Iwashima <kuniyu@amazon.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Willem de Bruijn <willemb@google.com>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>,
	Jeff Layton <jlayton@kernel.org>,
	linux-nfs@vger.kernel.org, Keith Busch <kbusch@kernel.org>,
	Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
	Wenjia Zhang <wenjia@linux.ibm.com>,
	Jan Karcher <jaka@linux.ibm.com>,
	Steve French <sfrench@samba.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	linux-nvme@lists.infradead.org,
	Matthieu Baerts <matttbe@kernel.org>,
	MPTCP Linux <mptcp@lists.linux.dev>
Subject: Re: [PATCH v1 net-next 4/6] socket: Remove kernel socket conversion except for net/rds/.
Date: Thu, 22 May 2025 10:55:47 +0200	[thread overview]
Message-ID: <7a965a97-a6d0-462f-b7dd-8833605ea7c9@redhat.com> (raw)
In-Reply-To: <20250517035120.55560-5-kuniyu@amazon.com>

On 5/17/25 5:50 AM, Kuniyuki Iwashima wrote:
> Since commit 26abe14379f8 ("net: Modify sk_alloc to not reference
> count the netns of kernel sockets."), TCP kernel socket has caused
> many UAF.
> 
> We have converted such sockets to hold netns refcnt, and we have
> the same pattern in cifs, mptcp, nvme, rds, smc, and sunrpc.
> 
>   __sock_create_kern(..., &sock);
>   sk_net_refcnt_upgrade(sock->sk);
> 
> Let's drop the conversion and use sock_create_kern() instead.
> 
> The changes for cifs, mptcp, nvme, and smc are straightforward.
> 
> For sunrpc, we call sock_create_net() for IPPROTO_TCP only and still
> call __sock_create_kern() for others.
> 
> For rds, we cannot drop sk_net_refcnt_upgrade() for accept()ed
> sockets.
> 
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

This LGTM, but is touching a few other subsystems, it would be great to
collect acks from the relevant maintainers: I'm adding a few CCs.

Direct link to the series:

https://lore.kernel.org/all/20250517035120.55560-1-kuniyu@amazon.com/#t

> diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
> index 37a2ba38f10e..c7b4f5a7cca1 100644
> --- a/fs/smb/client/connect.c
> +++ b/fs/smb/client/connect.c
> @@ -3348,21 +3348,14 @@ generic_ip_connect(struct TCP_Server_Info *server)
>  		socket = server->ssocket;
>  	} else {
>  		struct net *net = cifs_net_ns(server);
> -		struct sock *sk;
>  
> -		rc = __sock_create_kern(net, sfamily, SOCK_STREAM,
> -					IPPROTO_TCP, &server->ssocket);
> +		rc = sock_create_kern(net, sfamily, SOCK_STREAM,
> +				      IPPROTO_TCP, &server->ssocket);
>  		if (rc < 0) {
>  			cifs_server_dbg(VFS, "Error %d creating socket\n", rc);
>  			return rc;
>  		}
>  
> -		sk = server->ssocket->sk;
> -		__netns_tracker_free(net, &sk->ns_tracker, false);
> -		sk->sk_net_refcnt = 1;
> -		get_net_track(net, &sk->ns_tracker, GFP_KERNEL);
> -		sock_inuse_add(net, 1);

AFAICS the above implicitly adds a missing net_passive_dec(net), which
in turns looks like a separate bugfix. What about adding a separate
patch introducing that line? Could be in the same series to simplify the
processing.

Thanks,

Paolo


  reply	other threads:[~2025-05-22  8:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-17  3:50 [PATCH v1 net-next 0/6] socket: Make sock_create_kern() robust against misuse Kuniyuki Iwashima
2025-05-17  3:50 ` [PATCH v1 net-next 1/6] socket: Un-export __sock_create() Kuniyuki Iwashima
2025-05-19 12:16   ` David Laight
2025-05-19 17:16     ` Kuniyuki Iwashima
2025-05-17  3:50 ` [PATCH v1 net-next 2/6] socket: Rename sock_create_kern() to __sock_create_kern() Kuniyuki Iwashima
2025-05-22 15:01   ` Matthieu Baerts
2025-05-17  3:50 ` [PATCH v1 net-next 3/6] socket: Restore sock_create_kern() Kuniyuki Iwashima
2025-05-22 15:02   ` Matthieu Baerts
2025-05-22 16:23     ` Kuniyuki Iwashima
2025-05-17  3:50 ` [PATCH v1 net-next 4/6] socket: Remove kernel socket conversion except for net/rds/ Kuniyuki Iwashima
2025-05-22  8:55   ` Paolo Abeni [this message]
2025-05-22 16:12     ` Kuniyuki Iwashima
2025-05-22 16:38     ` Chuck Lever
2025-05-22 17:04       ` Kuniyuki Iwashima
2025-05-23  4:23     ` Christoph Hellwig
2025-05-22 15:03   ` Matthieu Baerts
2025-05-17  3:50 ` [PATCH v1 net-next 5/6] socket: Replace most sock_create() calls with sock_create_kern() Kuniyuki Iwashima
2025-05-22  9:11   ` Paolo Abeni
2025-05-17  3:50 ` [PATCH v1 net-next 6/6] socket: Clean up kdoc for sock_create() and sock_create_lite() Kuniyuki Iwashima
2025-05-19 12:43   ` David Laight
2025-05-19 17:28     ` 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=7a965a97-a6d0-462f-b7dd-8833605ea7c9@redhat.com \
    --to=pabeni@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hch@lst.de \
    --cc=horms@kernel.org \
    --cc=jaka@linux.ibm.com \
    --cc=jlayton@kernel.org \
    --cc=kbusch@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@amazon.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sfrench@samba.org \
    --cc=wenjia@linux.ibm.com \
    --cc=willemb@google.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).