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 AA3CA394487; Thu, 15 Jan 2026 17:07:01 +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=1768496821; cv=none; b=i3e7oLWHZiLqA4QxjARQOIaqFaLZmASXHho4oQYT3DnmHf6wLD/pF05gr9P1ybfQVZUvlDnUbCGEEjTnCCGM6MD1rsNn4bVKeoQM+galqmXiUJAYfRXNGFZFcaZXrJERfi4mgdDQH8THe3qOajYDREiB5eg6RuxuDDVXIv3amSk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768496821; c=relaxed/simple; bh=mdS5ntGW1jM+JJTXVEtauXW0o+yt1TEIeyqQkQSORqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HHCdLsIYdAIQvfGR+kwJDlBKAkN9Y8ZF/F3OrFJDrzRLrBy0s2j+0ka3wTRA7ECyNkxi5scEdnHcF22b4xGtnNzsKnaeXZaa7nX8UOxiLRrUG19HG64SpMUNs3v40bXJVNC9wqJC9cKPpQnldrU0x0f2ftvgZkRVMHulr9Eiblk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1LJXZJMx; 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="1LJXZJMx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 380B9C116D0; Thu, 15 Jan 2026 17:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768496821; bh=mdS5ntGW1jM+JJTXVEtauXW0o+yt1TEIeyqQkQSORqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1LJXZJMxfzcJrAJI6QTaH2gdalIBD6RqVDfaLzyhROh2GdG6fjzK6+PWkqOkmjD2q bh2cjU7bhCcp+Fbf50b/KR9g5tqyN8m3w1FpWskNQY1Q0V5HeX+nbhu2yGORxTGaXj xkwxwOp+9cZGpbJkWdQ4oiQ+hCB+fB3GS4WDRCdE= 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 6.6 27/88] tls: Use __sk_dst_get() and dst_dev_rcu() in get_netdev_for_sock(). Date: Thu, 15 Jan 2026 17:48:10 +0100 Message-ID: <20260115164147.296215915@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164146.312481509@linuxfoundation.org> References: <20260115164146.312481509@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 6.6-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 v6.6.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 @@ -125,17 +125,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)