All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org,
	 John Fastabend <john.fastabend@gmail.com>,
	Sabrina Dubroca <sd@queasysnail.net>,
	 Ilya Lesokhin <ilyal@mellanox.com>
Subject: [PATCH v2 net-next 5/7] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock().
Date: Tue, 16 Sep 2025 21:47:23 +0000	[thread overview]
Message-ID: <20250916214758.650211-6-kuniyu@google.com> (raw)
In-Reply-To: <20250916214758.650211-1-kuniyu@google.com>

get_netdev_for_sock() is called during setsockopt(),
so not under RCU.

Using sk_dst_get(sk)->dev could trigger UAF.

Let's use __sk_dst_get() and dst_dev_rcu().

Note that the only ->ndo_sk_get_lower_dev() user is
bond_sk_get_lower_dev(), which uses RCU.

Fixes: e8f69799810c ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Sabrina Dubroca <sd@queasysnail.net>
Cc: Ilya Lesokhin <ilyal@mellanox.com>
---
 net/tls/tls_device.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index f672a62a9a52..a82fdcf19969 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -123,17 +123,19 @@ static void tls_device_queue_ctx_destruction(struct tls_context *ctx)
 /* We assume that the socket is already connected */
 static struct net_device *get_netdev_for_sock(struct sock *sk)
 {
-	struct dst_entry *dst = sk_dst_get(sk);
-	struct net_device *netdev = NULL;
+	struct net_device *dev, *lowest_dev = NULL;
+	struct dst_entry *dst;
 
-	if (likely(dst)) {
-		netdev = netdev_sk_get_lowest_dev(dst->dev, sk);
-		dev_hold(netdev);
+	rcu_read_lock();
+	dst = __sk_dst_get(sk);
+	dev = dst ? dst_dev_rcu(dst) : NULL;
+	if (likely(dev)) {
+		lowest_dev = netdev_sk_get_lowest_dev(dev, sk);
+		dev_hold(lowest_dev);
 	}
+	rcu_read_unlock();
 
-	dst_release(dst);
-
-	return netdev;
+	return lowest_dev;
 }
 
 static void destroy_record(struct tls_record_info *record)
-- 
2.51.0.384.g4c02a37b29-goog


  parent reply	other threads:[~2025-09-16 21:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16 21:47 [PATCH v2 net-next 0/7] net: Fix UAF of sk_dst_get(sk)->dev Kuniyuki Iwashima
2025-09-16 21:47 ` [PATCH v2 net-next 1/7] smc: Fix use-after-free in __pnet_find_base_ndev() Kuniyuki Iwashima
2025-09-17  6:52   ` Mahanta Jambigi
2025-09-17  6:56     ` Kuniyuki Iwashima
2025-09-17 14:18   ` Eric Dumazet
2025-09-16 21:47 ` [PATCH v2 net-next 2/7] smc: Use __sk_dst_get() and dst_dev_rcu() in in smc_clc_prfx_set() Kuniyuki Iwashima
2025-09-17 14:12   ` Eric Dumazet
2025-09-16 21:47 ` [PATCH v2 net-next 3/7] smc: Use __sk_dst_get() and dst_dev_rcu() in smc_clc_prfx_match() Kuniyuki Iwashima
2025-09-17 14:13   ` Eric Dumazet
2025-09-16 21:47 ` [PATCH v2 net-next 4/7] smc: Use __sk_dst_get() and dst_dev_rcu() in smc_vlan_by_tcpsk() Kuniyuki Iwashima
2025-09-17  9:13   ` Mahanta Jambigi
2025-09-17 14:09     ` Eric Dumazet
2025-09-17 17:41       ` Kuniyuki Iwashima
2025-09-18  7:34         ` Mahanta Jambigi
2025-09-16 21:47 ` Kuniyuki Iwashima [this message]
2025-09-17 14:14   ` [PATCH v2 net-next 5/7] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock() Eric Dumazet
2025-09-17 15:45   ` Sabrina Dubroca
2025-09-16 21:47 ` [PATCH v2 net-next 6/7] mptcp: Call dst_release() in mptcp_active_enable() Kuniyuki Iwashima
2025-09-17 10:17   ` Matthieu Baerts
2025-09-17 14:04     ` Eric Dumazet
2025-09-17 14:51       ` Matthieu Baerts
2025-09-16 21:47 ` [PATCH v2 net-next 7/7] mptcp: Use __sk_dst_get() and dst_dev_rcu() " Kuniyuki Iwashima
2025-09-17 10:17   ` Matthieu Baerts
2025-09-17 17:43     ` Kuniyuki Iwashima
2025-09-17 14:10   ` Eric Dumazet
2025-09-18  1:20 ` [PATCH v2 net-next 0/7] net: Fix UAF of sk_dst_get(sk)->dev 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=20250916214758.650211-6-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=ilyal@mellanox.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.