From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0B9126F2B3; Mon, 13 Oct 2025 15:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369922; cv=none; b=egfsZIg9MDke0ZYCXiThhiwyLGi+ubEtnVxe3yVueh9ZPclGdVyCjq3NnD+L2S7KLf0QSbZ1zYfr0IeBoxFbJhQBputWN4J7KdCk2qQXytpPQa3TcWN2tl+G3J3xo+7uxWtcuMYGBvkx/77LKnVLeGcl5eRQU0xL/gizbVTMUnA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760369922; c=relaxed/simple; bh=H+Xo0/RvGEZjqmI2uWrhvWBn9rKUKShYiWmKMtaWcG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CmW8JT/hoPcngsJkoFbEHFkCGAfMuOq1yFf4VhMdcVU7RiqksYZ9A3V0OPq5nBhfQfIqrdKUftVG7F1k64lqQx2Qn8mGpLHXmBGZZcMT3rt8jnsBrvx6EvoI9OvOfctQuDyVckSXrsqN2+gGtxHQK1eZeJCSL6JSCsfX3PqPK+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TYBKT/9d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TYBKT/9d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F5C7C4CEE7; Mon, 13 Oct 2025 15:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760369921; bh=H+Xo0/RvGEZjqmI2uWrhvWBn9rKUKShYiWmKMtaWcG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TYBKT/9dwm7z/9j+oLHsVcnlMPGrObCjKHD954A0zZgB9g5nWOXDh73TYArIH7SfX ni3zVVTJWreGvdC8kgTAOw0OtrA0NEneaW4qgOwJ9PGiLvIYvbHFJqVxJ2za7a+HNK yPsYEl+63Kl0kQoxewjJieLrZkRR3e7JclqhNTTA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kuniyuki Iwashima , Eric Dumazet , Sabrina Dubroca , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.17 382/563] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock(). Date: Mon, 13 Oct 2025 16:44:03 +0200 Message-ID: <20251013144425.111402747@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251013144411.274874080@linuxfoundation.org> References: <20251013144411.274874080@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima [ Upstream commit c65f27b9c3be2269918e1cbad6d8884741f835c5 ] 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 Reviewed-by: Eric Dumazet Reviewed-by: Sabrina Dubroca Link: https://patch.msgid.link/20250916214758.650211-6-kuniyu@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 f672a62a9a52f..a82fdcf199690 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