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 8051F3E8C64; Thu, 15 Jan 2026 17:59:57 +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=1768499997; cv=none; b=R2hvmvmQ+oLRNvKI3zElb7o04EVoqn3PgfV4eGaUX1+bJX33DI+zjx5rOF3dYyL2IpjVYcwCQbRIt4NGSTq81JcMq7BR6PQXQd/UYWLduDf6qIFvDUbc91A0qI+zmUnQi98uv/GeKk16K93u3HasQsZJCofhCs8hq5xhaoeMNk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499997; c=relaxed/simple; bh=QtHYkNgWObVfLiyBiBg8Ofjeq+zSOxbSmlISaeSQXpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KpV+s+lsWVCsFHJEq8TtziJUnW4fB6M9gP7q9nHzRuDr3MAupkoim1nDh6VkFwIxQtxVLaWdXYhDgaIIeEnQ/2yX6GN5Gua3CS20tfJNjEP5+oU75vyZI3otqhk+GNRvDRBaU+46y/dZI8b10E1soviY8jUYx3BTjweboZm9Lkk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oaWmcCs/; 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="oaWmcCs/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1110C16AAE; Thu, 15 Jan 2026 17:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768499997; bh=QtHYkNgWObVfLiyBiBg8Ofjeq+zSOxbSmlISaeSQXpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oaWmcCs/+n8HDIFDMy1x4yhV04YXUv2ze1Sh6/4nTY5DRq0KEW4JMvpiaG8EOdh5G EE0FwUB/wjyuOu+A8t9mx2L6JnH/5pe/olMLxH48JgiRLyFjrRGJAhGHwh6ZucQ8JQ OT/FmJbFMFDOU3ZIYiXX/IIk16DUAoU9chpxICOg= 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 , Keerthana K Subject: [PATCH 5.10 423/451] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock(). Date: Thu, 15 Jan 2026 17:50:24 +0100 Message-ID: <20260115164246.242565555@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164230.864985076@linuxfoundation.org> References: <20260115164230.864985076@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-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 [ Keerthana: Backported the patch to v5.10.y ] Signed-off-by: Keerthana K Signed-off-by: Greg Kroah-Hartman --- net/tls/tls_device.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -113,17 +113,19 @@ unlock: /* 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 = dst->dev; - 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)