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 8FF912561AE; Wed, 4 Feb 2026 15:00:10 +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=1770217210; cv=none; b=GYEGYcFlLBvn+SLFkZi0TydegqVZoVunZkX12jzbhgJglW6VPBRaTHgIRrV3Q9iTEjKDVpBE65/iusNIn10jMGfOV4nDbN5fpZO22lvkKPqVDazlLQLCl8LhmdtR03loe8a1bxLxXfpUOm47rYXYXGQWa3htSMgJfWrYmlQFK3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770217210; c=relaxed/simple; bh=BySPZRRF/RIHcnnaMgXRbAgj4ps+PJEDR9+JV37F0/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKnbX5Bx9GZzR2ijQ35NeUU41zAUdRzBQmixarQyMWRwP90jH3RzNuDU+eppHE2085ijiyu7vyN7q7c4/UwcQWmfN0WlvNeyANXCt3ex81m1JyiXxxtnN+wtvOUpoOf74QgFeYL83QD6G8fegIX7KfNKzx+yvYQ8fqnMoU9O1/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sFL7G565; 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="sFL7G565" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EC57C116C6; Wed, 4 Feb 2026 15:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770217210; bh=BySPZRRF/RIHcnnaMgXRbAgj4ps+PJEDR9+JV37F0/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sFL7G565mvszKX0OOlEiZz6W0QrQdYDIuUB+GnuNZqzX3hrfhWlD8aRLZ1fUkRiII jegmCnDW6AZbMzw34WvxO+B3kc9kaOfS9la54xam+n4VhBg2WyjSdQXpu/AYxyhP8T JLbv697EdxQujlCSgJuwjRv/zmoQxxDyxZPpB1E8= 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 , Keerthana K Subject: [PATCH 5.15 156/206] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock(). Date: Wed, 4 Feb 2026 15:39:47 +0100 Message-ID: <20260204143903.823926861@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260204143858.193781818@linuxfoundation.org> References: <20260204143858.193781818@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima commit c65f27b9c3be2269918e1cbad6d8884741f835c5 upstream. 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 [ Keerthana: Backport to v5.15-v6.1 ] 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 @@ -110,17 +110,19 @@ static void tls_device_queue_ctx_destruc /* 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)