From patchwork Mon Feb 3 14:30:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957601 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-vs1-f73.google.com (mail-vs1-f73.google.com [209.85.217.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE52920A5DE for ; Mon, 3 Feb 2025 14:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593055; cv=none; b=D44RqUpzHfs0y9lcMgeyU2/cHtk/Rj96KtMbdEFOn2TE/kOmOHtXt41G1w83Hy+JoizF0kPRNNQ/nkDT0woa2va5Wv/FjEo6YrTTjdw2L8cDJc1/0UYp95ZOGganzI5cYiU5LMXf7bndVTIAnG8OtPILlJEsIIeCGeRmL3l+XqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593055; c=relaxed/simple; bh=R4Et5ZGNv0Tby5ViLhNa7xiDNoTmcHwKTWxjkKH6iqs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CvYZsXGXRc0LyHJxYt5GjU1cc5f+5g9KSPbRlg8PRnhoZwZijZ6LdR6ie91pfCqB6Dg+6WEn0Oo3GozUy065IdiD9Kk2H7g1oTIhVPVEG+siZAFvLmygy8ls7c3OQ26XQQkXGn9Ab46rb994UE3wH3gKw+BxLY5ZRcIcuVlON/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3y7GGH63; arc=none smtp.client-ip=209.85.217.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3y7GGH63" Received: by mail-vs1-f73.google.com with SMTP id ada2fe7eead31-4b63e7ac660so4260196137.0 for ; Mon, 03 Feb 2025 06:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593053; x=1739197853; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=avlxdsW5BiWcLQRJNiGfBt63W2Zm8o/S9CZldBDJxA4=; b=3y7GGH63ROg1CrOC0r3hju68xMbzv6yfTnrvQnrTqxQlaIT5OVAZh5Bacu6LBmqFJZ Rwtmjz/sj9mFvLTwYjlc0OGTiOIXrWAjpAB89ukdXWJBCSxqVebkKc1v+aJTLhQbPbT1 zhLqDMyl27tVYc93VqjG4rCpPQu+FnAR7AhRgVWTTtIN0VYaU+IcmzUjoeGSD+MXSSWQ KjMXsI/rOQzq+rfSgJoiwGcaxz+DZPD6/panrOt1CzI/mecMDRAlq8nhT+cI+S633Ekn 0TE+vYjKu8h3xJb3oObU4+s81jyhDLgAg+TXtL4r2fr0WyK3cvPByDNoBYg6EkYRKtWU 6Mow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593053; x=1739197853; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=avlxdsW5BiWcLQRJNiGfBt63W2Zm8o/S9CZldBDJxA4=; b=USpUW9vq+J/0pJh19+tLfzSjvOtfCsL9Jn4vrcxVVKeYamgwS99rYFrGJdnD+wqHF6 xLRRCpMq3ShxW+wDHe+VB1sPfUQ1PWdUmlNNuawzU6IkFY+UYDGPs/C1JTtpemsQeNa/ USP3N9WPsfW0H9a05z9hmpVkJiybpcCSoSj2fCaDOJSz9QjyiuxlwfixFNb3BjdtIzIw KxCmD/a/Qq6DHNdr3XxNLgfiMIm/+pZIZTYOP1uOaw7Ows1RKbGUKdu5lZR3uJ9Kd80G OISPMe10dYLp2qxHlTZKx4N7hVGNUiUGShA5kRy5k79G02W7RSn1svu3cyDNrkKxcF+i 7ZGw== X-Gm-Message-State: AOJu0YxsGmpg/d1Su8xfO81nLlCFOcMYuF1U11aIpZnKB23J1iFj4W/t BZCSVbe0LEyWpRvA0OjY2Sp4E/mvpO5+04T0xzP7tPhX+HRi2Q3Ned/HQJ1oKezDyGVs2xd0OPr RlBlAOzzeMg== X-Google-Smtp-Source: AGHT+IH7cTT8tbC11ISbYR1/Wwrx02lrcAzD/GhY68YPCDckxHkAzoab3oJncXRhTo7bQ6+mKZoAfpLiV5Tcpg== X-Received: from vsbib5.prod.google.com ([2002:a05:6102:2b85:b0:4b2:cc7a:f725]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:3f03:b0:4b5:aa91:f29f with SMTP id ada2fe7eead31-4b9b71b00b1mr12246940137.8.1738593049566; Mon, 03 Feb 2025 06:30:49 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:31 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-2-edumazet@google.com> Subject: [PATCH v2 net 01/16] net: add dev_net_rcu() helper From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org dev->nd_net can change, readers should either use rcu_read_lock() or RTNL. We currently use a generic helper, dev_net() with no debugging support. We probably have many hidden bugs. Add dev_net_rcu() helper for callers using rcu_read_lock() protection. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/linux/netdevice.h | 6 ++++++ include/net/net_namespace.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 2a59034a5fa2fb53300657968c2053ab354bb746..046015adf2856f859b9a671e2be4ef674125ef96 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2663,6 +2663,12 @@ struct net *dev_net(const struct net_device *dev) return read_pnet(&dev->nd_net); } +static inline +struct net *dev_net_rcu(const struct net_device *dev) +{ + return read_pnet_rcu(&dev->nd_net); +} + static inline void dev_net_set(struct net_device *dev, struct net *net) { diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 0f5eb9db0c6264efc1ac83ab577511fd6823f4fe..7ba1402ca7796663bed3373b1a0c6a0249cd1599 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -398,7 +398,7 @@ static inline struct net *read_pnet(const possible_net_t *pnet) #endif } -static inline struct net *read_pnet_rcu(possible_net_t *pnet) +static inline struct net *read_pnet_rcu(const possible_net_t *pnet) { #ifdef CONFIG_NET_NS return rcu_dereference(pnet->net); From patchwork Mon Feb 3 14:30:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957600 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C48C20A5ED for ; Mon, 3 Feb 2025 14:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593054; cv=none; b=CBOVU+T4pxSqK8VoRMlSZb3aBGkyxtbR/zLGrIquNnFytAPjEe0+WeS9seTTDswI44GfQGrLbKA8dAQflec9CXD0DGbA+3paj7tlOzL4Nw4cKissH8sAtB9XkNAu8ogGRLlVli2xb49K6pRkJ0+mwF5d4qipoa49c5lnx0/ULRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593054; c=relaxed/simple; bh=BjDBT6Ld/KkPV9e18e0rFMjRoUhNxwx0+3f23tk62VA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Hhj2FlPcEj2gOuh2ulHne31eFPOiaMc5LezVZTsz3CT0BOcZFSZsjUGxBQrEanx5pfi6358sJfCdLp6lgWzKh8142phvXa7NUHlYSdu/fBH6Him/dzlU9j5Oi5tIgLZklEzWWoTh375zTglvNxT7og4clLAJRrkKy1e4yrygWg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aN9BUGVt; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aN9BUGVt" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-46909701869so99361001cf.0 for ; Mon, 03 Feb 2025 06:30:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593051; x=1739197851; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wFUTWn43E87kH4WvQpJOMQwE5y357mjWskRk2Y0FDpo=; b=aN9BUGVtij+kL9hX454yLyu9b59FS0OjI0g9GDzE6TuQPKJM53B7Pxh+/WuGuPb+Q1 JO4H7LcnuXT66ZjdZ+A49QuaesTa4uegkRf9VjFt5/OFIwlR1Xk7NTsa+a3IvxbKgnaa n/FoBdYF694IU2QHutKh9p7zuxPwgAqeVop6oM6C2Mpdl458z4SwjTwVfEhNcud88C55 UipVaUH+Uu7e60JeY+T7OrfFpVgwrNX20/Dyx7uFoh2UmDLSeCdly8BMXjjfT8rvSF9B tIJ/cjl3qw7rxiqjPz/JTOGgfMbqn8DMBWyas6ena4IYug1CWq347Amow8H4EV64J0iK QjmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593051; x=1739197851; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wFUTWn43E87kH4WvQpJOMQwE5y357mjWskRk2Y0FDpo=; b=tRERXR/h2qaKN8lHP3mvvqQI/J7jvJvFbrXQkbLRcqtIoCJSDjLt3duUmhLn5a95OP Tvc/cPTcwJt1kNnIn4bvVo6LPDH8ufKTxUI0vI2QK4qcLvvUaQmWJOUtGMJ6dxkKIYip Ae/PoYyDuvhyaD1gsfmlk22nf94+wnGebRdJvIkMboyhufwqOxZYFkCtBdGGmy+gPYXe UroZ6gdoZKV5Df9ubk6g/EuerE+38heO3PelO+GP1hOctel6WgQlzYwgRDLoiSoDGcVI Hm18ovBk84qUOx702WN4E3BQgEYwNxmfwy4Fmq7EGR+utUvepgJYGxVvk/VHbGLew8jj 7gvg== X-Gm-Message-State: AOJu0YzQIA25nJ2bVuZ6EsZnpoI9qD7Z7H58WZS3dwaVOKvd/0Uck2NF EknDyJf2XpfoH6xzyceHRR90IowfbxT6cJJPOA2Fev7ai+2jVJhfv/SKzF+XQsZJIHFTJHHkSQz ICwOAYU9Ajw== X-Google-Smtp-Source: AGHT+IGvYma/ATaRnFREOH+tvmRCOgKofawknl3O75OVXUcuXOjekwJUF7rPMvr5TPMXLsQWwTghwJmc7WQwaQ== X-Received: from qtbfa8.prod.google.com ([2002:a05:622a:4cc8:b0:467:60a9:3317]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:90:b0:467:6cce:44ba with SMTP id d75a77b69052e-46fd0bcb95bmr347270301cf.43.1738593051103; Mon, 03 Feb 2025 06:30:51 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:32 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-3-edumazet@google.com> Subject: [PATCH v2 net 02/16] ipv4: add RCU protection to ip4_dst_hoplimit() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ip4_dst_hoplimit() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: fa50d974d104 ("ipv4: Namespaceify ip_default_ttl sysctl knob") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/route.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/route.h b/include/net/route.h index f86775be3e2934697533a61f566aca1ef196d74e..c605fd5ec0c08cc7658c3cf6aa6223790d463ede 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -382,10 +382,15 @@ static inline int inet_iif(const struct sk_buff *skb) static inline int ip4_dst_hoplimit(const struct dst_entry *dst) { int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT); - struct net *net = dev_net(dst->dev); - if (hoplimit == 0) + if (hoplimit == 0) { + const struct net *net; + + rcu_read_lock(); + net = dev_net_rcu(dst->dev); hoplimit = READ_ONCE(net->ipv4.sysctl_ip_default_ttl); + rcu_read_unlock(); + } return hoplimit; } From patchwork Mon Feb 3 14:30:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957602 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 037D020E005 for ; Mon, 3 Feb 2025 14:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593055; cv=none; b=leGMgFhj7zaT2pr9ngz5yG/IIsqSFK8uvKA+HIyPuotmzQW8v3P9//7MH9czEjJvsbHLTMGhCTTJZtCdVeCkgtumnGrXRXJZuFhqstdNCpjpdLchLvDLcNYz8oL9ZDfJdVqwTXnNq9/EMNjv7QSxj/pbNDgDpc7q+B5oLaZQgJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593055; c=relaxed/simple; bh=Tv9lP/iKol3DOwtqFgPyYFOYlq/ggjrKRjQnoathmaA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EvQ+vXWOcPTecSePuAVl54clymh28Z6KQnsAxSXk3yXOzqJOLjHowY31iv1/JxFxqOBcVXUSlLcVnzeQR44VizYMdpUK32gJyTnC9V/StdXOcErtVL/xsef9TWKhYpXMEW0KaD+WgmQjIGQLBgbaa4ORAOQ1qd+FdOkS3JRJVU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2ZJulzLN; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2ZJulzLN" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-467bbc77b05so89059961cf.0 for ; Mon, 03 Feb 2025 06:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593053; x=1739197853; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8gzgfgZQZl+mi1a/sA+Jd+RkxpB2VmO3rTOvLw+ezUA=; b=2ZJulzLNyBuHGCrXB2cgQL1O534r2GBu32icxmpvlvGFl9hmXiX+Isb+fHfrR3GqHl mfhto8tmugdlIIZG9G90LySBrKfR6oxKFH8ibOwa7U/jNELtR8ptAILUxzaEEfxpvf46 Bflf4mgH+Dj+8vMrdt/v2ruZ5x5rmqZ/WBmoiFR84o6zJcv5k2uzh0pj+lLn94XEmUrR Z7dufqmed105ThMvL1fzM1xY6i2YJJw0Q1+YLXWZ835xK8M7nqMDqaDdFDQM7xfubv9q QN6l4uAhUq0TAGYvm+6eJxLr+QUeob8HotGllt6gX4zkv9xodpbLZ0pE5lMUUheTh+yx b0PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593053; x=1739197853; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8gzgfgZQZl+mi1a/sA+Jd+RkxpB2VmO3rTOvLw+ezUA=; b=s04OFI2bbehmMy7pJ2YHnXaous6qCT/5PyYg6ddvGFIRgOGPdJQikLLIgqN09S+3fb L5BkW3bllFJAXimZ6yiKrnThjVxiUlYI4jBDJimjVWjZAiHM61TdW2nhnpF9ukJtGrXR eUWSRWAr7B2Mu3BTJfwdWjqmHEXNzdZ303fTgSd0nhMMJfKdo/007sIBISx5T2ZqvH2f d43wyqOJAVIDJnriWuyFKxSkjY6GxpXlKkAMpFLFRX/vhJh9tP91HxraI0nxvsstamfv o/Vqwi5UYSTF7V74tXOkpTtvE5JKYwO97pZB6Zdy5/gXfrj5sKfFtvMDcJJ4oDR5zLa/ E88w== X-Gm-Message-State: AOJu0Yyv4qk7d8gtHxAsdhMuQtNy/HwIYa8u4qmOEEFWO9QVZWKMvhlL RR0uq3glpbQBip/JDXG87cNyNPFx+bQQiYRRmWpvO0dAGSc7fiyRXlQxmnUdbT4SAQSqV6m7wZz /n0bTrnSJJw== X-Google-Smtp-Source: AGHT+IG/N60AqRx2cNDAYYvc4AAu5L9kUhCk2BVNvVat6spIh407EhrBaktSht8QTUTrysO/abd3kWkYCSpnPA== X-Received: from qtbfa8.prod.google.com ([2002:a05:622a:4cc8:b0:467:60a9:3317]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:8cb:b0:46a:65c:b589 with SMTP id d75a77b69052e-46fd0a81258mr318044321cf.6.1738593052745; Mon, 03 Feb 2025 06:30:52 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:33 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-4-edumazet@google.com> Subject: [PATCH v2 net 03/16] ipv4: use RCU protection in ip_dst_mtu_maybe_forward() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ip_dst_mtu_maybe_forward() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: f87c10a8aa1e8 ("ipv4: introduce ip_dst_mtu_maybe_forward and protect forwarding path against pmtu spoofing") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/ip.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 9f5e33e371fcdd8ea88c54584b8d4b6c50e7d0c9..ba7b43447775e51b3b9a8cbf5c3345d6308bb525 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -471,9 +471,12 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, bool forwarding) { const struct rtable *rt = dst_rtable(dst); - struct net *net = dev_net(dst->dev); - unsigned int mtu; + unsigned int mtu, res; + struct net *net; + + rcu_read_lock(); + net = dev_net_rcu(dst->dev); if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) || ip_mtu_locked(dst) || !forwarding) { @@ -497,7 +500,11 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, out: mtu = min_t(unsigned int, mtu, IP_MAX_MTU); - return mtu - lwtunnel_headroom(dst->lwtstate, mtu); + res = mtu - lwtunnel_headroom(dst->lwtstate, mtu); + + rcu_read_unlock(); + + return res; } static inline unsigned int ip_skb_dst_mtu(struct sock *sk, From patchwork Mon Feb 3 14:30:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957603 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 532DB20E014 for ; Mon, 3 Feb 2025 14:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593056; cv=none; b=PEtyrzmXtzwJzjzMitUEVuXr640FmDNAtTtZ4j9u9U5GfC1WOUD/7mKqKdUDEe/L5z3NGBSXsBwNnulgDITqCERL1RHYZRzrXfYMfS7QNyv68holCILlqafOZXScafLwN2lot4389gH2hC4p1d4rmoLrJyYLGErmzbJMZ8h7/Ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593056; c=relaxed/simple; bh=H8JH/QPjFfGxbrJtRbDkCum9cREuE5YKVIPC//b1qCs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LFyK+VQoL26URaE5ADff6Nw7pdbjmMuRg3zRJjhP2J+M0RqAvC+1L9LYwRsgy8PZYoqbm59I0aoML4QEV/7s9LxDxMKnvb9Xfb47Vt3JXuTuKqia+o7PfrMbWIPE062LxavX5MKvXZjqFPaT+L26Y61F+tb7W1DG9Xj6YJAicgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ORNt+o9z; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ORNt+o9z" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-46dd301a429so95543511cf.1 for ; Mon, 03 Feb 2025 06:30:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593054; x=1739197854; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oummPnO89bchIzAktiowh3Jl3EZAt201EnCE7gdN6jc=; b=ORNt+o9zNiB5qjfH6HEHOfKX3/EDhOXZ2UGkfz0q8va5LSkzUKi8KTuPyf3ZsI6iIR ZkzJ2LOWzqFzSosOw/xrE6p64e81R6CGN2JpmMwE54J85m9oFqQMln7TgIi9He9T65ct dK/3lN4voLfqJV9ih0cCmt0qqjqJRy5uA1FA/maTuFXv5dTy26fb+awHld5kRxoDBV1u w07LRIxpR/+1QzwiG5vTQ6a603wUmFhezNAoZxPlV5krUK7WrDU0I+cYXv92AQMeViBs uuWAi/wMizhZQhm9D492hby3vId2NGEz0wsxooBtxlUw1n/tdh0QfTE2m/emQBiXiMWh bcnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593054; x=1739197854; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oummPnO89bchIzAktiowh3Jl3EZAt201EnCE7gdN6jc=; b=X3uFdBIJTZBZATnAPWbd2j9uvoj4BHhJ9e5og7yEHAtPKBKoTQafJzMC2n7meVtKzS ZxGQJUcQc90/3taEidw0qot8kmrjyw0Hn32V3az73mnzIKbgZcyKOoOMFMFwpncjNZXc lZXDXqS0CWPiRNSGJKNYzmPA++3CezqxjpEm4ot/gg6ymvJZEe+JpPLMsFBUc29xFWV0 084YgjF+XDBK6VtFXBLUMu7C4g6LxJax7TLDR0riWpPp0ljMP/3Ultfr6RRm+G98Z1Jk qotk5mmw29NDxD1vJm/jlEQc2aLUS4ewJkIRI8GRkhyPKahtngYa1oKKYV19ZUpU7zb9 1aVA== X-Gm-Message-State: AOJu0Yyn5e9oOJp1njwH6d2PLvB6linPHcsoNW9aHSoZnnMXtX1TNWo+ f4ZLyJZlEiCQUuuCNn0mh2B2kbbavtc8IQft1C0/OXUXI2HGoTRrS8OFq2tuegzB0CY8LT9oGer 57UUFZmjAIA== X-Google-Smtp-Source: AGHT+IFTe7ZfY4yWX2ICd+1ng3slGad8C5b2GR/bnJKwcPtGGj4cO3rk0SfNRTC0P2RjB2pPcKhR9q+H2bXOMw== X-Received: from qtbay26.prod.google.com ([2002:a05:622a:229a:b0:467:84a6:b744]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:5702:0:b0:46c:7188:e3c4 with SMTP id d75a77b69052e-46fd09e25aemr209240181cf.10.1738593054306; Mon, 03 Feb 2025 06:30:54 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:34 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-5-edumazet@google.com> Subject: [PATCH v2 net 04/16] ipv4: use RCU protection in ipv4_default_advmss() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ipv4_default_advmss() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: 2e9589ff809e ("ipv4: Namespaceify min_adv_mss sysctl knob") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/route.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 577b88a43293aa801c3ee736d7e5cc4d97917717..74c074f45758be5ae78a87edb31837481cc40278 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1307,10 +1307,15 @@ static void set_class_tag(struct rtable *rt, u32 tag) static unsigned int ipv4_default_advmss(const struct dst_entry *dst) { - struct net *net = dev_net(dst->dev); unsigned int header_size = sizeof(struct tcphdr) + sizeof(struct iphdr); - unsigned int advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - net->ipv4.ip_rt_min_advmss); + unsigned int advmss; + struct net *net; + + rcu_read_lock(); + net = dev_net_rcu(dst->dev); + advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, + net->ipv4.ip_rt_min_advmss); + rcu_read_unlock(); return min(advmss, IPV4_MAX_PMTU - header_size); } From patchwork Mon Feb 3 14:30:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957604 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0EF520E03B for ; Mon, 3 Feb 2025 14:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593058; cv=none; b=Z/Cty6KkvERTdYTFaTgqxMy9YjNtAJO9h+31MCWX44prdvcAu3KrDDdUthbFWaPqSedwKFxl5Fb1HCUJ4TbrLHq/BdTPni/+tmq0TclDBb6hrFe11aom+Xa03uJZUacNWICoaltNxcOCgLKgGN1PV2CB6wTD+ukVZRyeyO/4DOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593058; c=relaxed/simple; bh=Y9lnsb8QeKEZFqBhSW8yGtosBM6Zj3i856YbOAw6C2w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dqvcj8TzlubH1w9oHEW04AHIN6ZYGTJgthGpKlxQn5UM2IFgmcC13i4Oz+NioymMnxS6BHNOao5d615N2UgMDnTqytxZHXQJwLSeuwWV79aP/I8inXzAXP6QTIAWBrxqKT5Cjx0HhiZ6HqUY+FM1DSizFI/o+STQSfyK3d9mEVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NqKFCO0s; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NqKFCO0s" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-467bb8aad28so46818811cf.1 for ; Mon, 03 Feb 2025 06:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593055; x=1739197855; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YaNwdpwj0e4SW/9x+BMfHLkop9sD36jHDjUBDn3qdiI=; b=NqKFCO0sjiAh0H47g6Ns16HTUFRUcugsfYA0FYAc7l8QrlmEDw/73k3SAH5R8K+s59 RAOc8TSls1Kfuc2tQAT5C8OvkGwWN7Xi2WmGs3Y3cubpdTyzTiihFSbqmuAY1+Xs2owh 05x45Dp8vuPoaLrrSnKtMcjokHoDeLBDd9u+bZlsS+zGhPdsMDoZNQuj+gdtdSdyip0m CopTghXFA05uZzgEBeEfAmEZofDZVqsv9bObTDLPsmKaBdCvA6R9aVMeziyMefo3++Hh +EGCONpudcPhDp28m6GB02mLTS9565XiOxlYxF265fxp+Cy30lBI15HpmzIsY3Ui0+4b TgYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593055; x=1739197855; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YaNwdpwj0e4SW/9x+BMfHLkop9sD36jHDjUBDn3qdiI=; b=VhmlJKgwOTrN4ktYgQVEwLbyWOpvCzRO2bDZe6g4uaYSRt1dBXgjjULzwxxykwc+/o NF8dze+fmcBKRxBX7lIPLv5nJmZdeCWZYZV5t3VUsN76u/FoCtoGRE0VZfMWCZ4AOH9T iTSlZo1afJft81HN8gtq48+UtJt2Btyu8HWo6vDmDPStzECsMO3HHu30Y2Rq5/2kghfB 3ycNc5Nc717S/tdLzhIrutrWN0YUwCTaSDt3Bv+SpK/TaWZukbRytHPT2nSPX70uedxK Mo00D9lThC0FuFuCesFGMetKb+3rq+Eyayp+12lkGgCWjaMW7gjK4KWr4cmiPuG0j7Lf 2LCQ== X-Gm-Message-State: AOJu0YxP6XwRLkf5uFBeiB8FiLVmOVr/k8Q3Bmqh3FnjgwIwx8RyRZ7h 0x8DP+e4r38wvaLRdPw4gFvOdyCDpE5QOcBJcH9JvhHh+LFZMseX6QFhRVeRUSzcoKIcY+aIdyU avXO6fBvt8Q== X-Google-Smtp-Source: AGHT+IEmBA6uy6sB/rbIMfbv+7lcIPwmKa0t5mGZC0SdBk+3OOjtdyKJJv4t2fbCxSC+F/ZH0g9y+OdbXPUnRg== X-Received: from qtbfz8.prod.google.com ([2002:a05:622a:5a88:b0:467:6227:451b]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:584e:0:b0:467:79eb:4a16 with SMTP id d75a77b69052e-46fd0a114abmr336560961cf.4.1738593055664; Mon, 03 Feb 2025 06:30:55 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:35 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-6-edumazet@google.com> Subject: [PATCH v2 net 05/16] ipv4: use RCU protection in rt_is_expired() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org rt_is_expired() must use RCU protection to make sure the net structure it reads does not disappear. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/route.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 74c074f45758be5ae78a87edb31837481cc40278..e959327c0ba8979ce5c7ca8c46ae41068824edc6 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -390,7 +390,13 @@ static inline int ip_rt_proc_init(void) static inline bool rt_is_expired(const struct rtable *rth) { - return rth->rt_genid != rt_genid_ipv4(dev_net(rth->dst.dev)); + bool res; + + rcu_read_lock(); + res = rth->rt_genid != rt_genid_ipv4(dev_net_rcu(rth->dst.dev)); + rcu_read_unlock(); + + return res; } void rt_cache_flush(struct net *net) From patchwork Mon Feb 3 14:30:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957605 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4616020E316 for ; Mon, 3 Feb 2025 14:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593060; cv=none; b=gXk+q/40UG4bog0WUTPUFSxk8sMx0ddrCUZen8yiXaFhwANZ22ZKlgAYeGuL5gj06ld5F/6VjesUweMEsXe7MidIydmk96TSi0O1L81JWtxO6kHILV1SeNeLtQmnepVC4smG75TJVhmQZrnyM6YdhpWDduFcGE6+dMMpFrV30kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593060; c=relaxed/simple; bh=KUBWLaE7l8G087vZxjYgfbMjhgm6OCSi8YPfBZGcIuA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SQ1pF8t7tNhpf/gbfWDUXF6wW3EZ5EPOnwP2OKYGQSh+HAp/+vcRSCR8T6e9yqzK0DupnoR5vu0jbOnLzVCDDIMZmLIysuunJ7QzJ+tcWH2tWXp4RJSGqB5KOpFR+5i2I3avXGCNMfUDNb6KJ5dfNQPI8nTRSN26+Z2j0o0u2kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fEaEskcR; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fEaEskcR" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-4675749a982so78437871cf.1 for ; Mon, 03 Feb 2025 06:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593057; x=1739197857; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=exj+/WiMcA/4x3JNYZjiPmtoq+Xf15JgMsZphYh6BoQ=; b=fEaEskcROJ5yNRNcueMgL5rgXofR62l2H+Dz1cs73F2IE/quI7J5cP0HtDtKaEKeDo /AWxrfqNY9bfw8OV0FT8ZlhJ8ELJFEH3FcXIkQ9lhyTazlBLToSpUYC74RcBk8T6mQrd Krc0wfTmgbWwzSosSLcRDAdrdHeXx2UpDB2sHWC/hDsKAP9yNEX2s0t8L1gZ8oxUCzVC nPNRIfvKeuZpIQ4FLple7YrgcTD0LoAt72yG7dbVIJxcLJjU46Ja6J0emvP2/+AZr6kt 9LBU01c3hfRgHuosgBZiEvu3i2QE+zfgPXKhX3Kysikh+4K+DdDVIOkdUe/b56KpPXVQ rThg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593057; x=1739197857; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=exj+/WiMcA/4x3JNYZjiPmtoq+Xf15JgMsZphYh6BoQ=; b=reWKsF0o5mVpdNZthla7N8csxUkXSF9pSeN8fWon3O+p9wEVeM35b2etWeQoHAu07w ZSFQ38zzWpFs4FyyITr0Aj+porOBTafmqP7DZRzCqXNiJ6nZ/ZdjoDdAzOkyRdy3ARFO 3H6PyEyb9GAQE7APPhP4Ddq+7/N9W4c6h4pH6GRsHnPS+jeMToJ2Mor25NRK8J0XNY7T +1pcOscALq+KRvJZDFkdLYRS7dpeE0VB3WYm5htyAXcocUgscH3Yg28kWREYxR/0GZaa f+SMHpQUJ3PmvNNMguMVnM+0Mx4PSquRQa9WFTLTv0bI0YK5HgHkb9OTNffYf002sMLR UXDw== X-Gm-Message-State: AOJu0YxDOykYaQy5po917uHW/SA6sA484/uLKmJGb/NZqYLSAuPDjVLL +XD6YkdWK12/OWluaE+nHPPZtVQK/jZ3rSin8jmPgkmjKO9+3O+E6oi7Q8iXW6nNa2YDR3yWrFM PQj907z8Kdw== X-Google-Smtp-Source: AGHT+IF3PhM1mwZ1UWPBr1VauXt/Pgk5w80JKBNla4qSEOZMDTDxFegCEU2rM+9ftOcEWA6csbhbhKarJ9t/+w== X-Received: from qtbeh14.prod.google.com ([2002:a05:622a:578e:b0:46e:4a3:1078]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:1a0d:b0:46c:a0dc:efb1 with SMTP id d75a77b69052e-46fd0b6a4e4mr329041931cf.34.1738593057143; Mon, 03 Feb 2025 06:30:57 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:36 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-7-edumazet@google.com> Subject: [PATCH v2 net 06/16] tcp: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org TCP uses of dev_net() are safe, change them to dev_net_rcu() to get LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/inet6_hashtables.h | 2 +- include/net/inet_hashtables.h | 2 +- net/ipv4/tcp_ipv4.c | 8 ++++---- net/ipv4/tcp_metrics.c | 6 +++--- net/ipv6/tcp_ipv6.c | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h index 74dd90ff5f129fe4c8adad67a642ae5070410518..c32878c69179dac5a7fcfa098a297420d9adfab2 100644 --- a/include/net/inet6_hashtables.h +++ b/include/net/inet6_hashtables.h @@ -150,7 +150,7 @@ static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo, int iif, int sdif, bool *refcounted) { - struct net *net = dev_net(skb_dst(skb)->dev); + struct net *net = dev_net_rcu(skb_dst(skb)->dev); const struct ipv6hdr *ip6h = ipv6_hdr(skb); struct sock *sk; diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 5eea47f135a421ce8275d4cd83c5771b3f448e5c..da818fb0205fed6b4120946bc032e67e046b716f 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -492,7 +492,7 @@ static inline struct sock *__inet_lookup_skb(struct inet_hashinfo *hashinfo, const int sdif, bool *refcounted) { - struct net *net = dev_net(skb_dst(skb)->dev); + struct net *net = dev_net_rcu(skb_dst(skb)->dev); const struct iphdr *iph = ip_hdr(skb); struct sock *sk; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index cc2b5194a18d2e64595f474f62c6f2fd3eff319f..3bd835220d43d6d6491fd5c8d5e9954c37303f83 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -503,7 +503,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) struct request_sock *fastopen; u32 seq, snd_una; int err; - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); sk = __inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo, iph->daddr, th->dest, iph->saddr, @@ -788,7 +788,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb, arg.iov[0].iov_base = (unsigned char *)&rep; arg.iov[0].iov_len = sizeof(rep.th); - net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev); + net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev); /* Invalid TCP option size or twice included auth */ if (tcp_parse_auth_options(tcp_hdr(skb), &md5_hash_location, &aoh)) @@ -1967,7 +1967,7 @@ EXPORT_SYMBOL(tcp_v4_do_rcv); int tcp_v4_early_demux(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); const struct iphdr *iph; const struct tcphdr *th; struct sock *sk; @@ -2178,7 +2178,7 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph, int tcp_v4_rcv(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); enum skb_drop_reason drop_reason; int sdif = inet_sdif(skb); int dif = inet_iif(skb); diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 95669935494ef8003a1877e2b86c76bd27307afd..4251670e328c83b55eff7bbda3cc3d97d78563a8 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -170,7 +170,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, bool reclaim = false; spin_lock_bh(&tcp_metrics_lock); - net = dev_net(dst->dev); + net = dev_net_rcu(dst->dev); /* While waiting for the spin-lock the cache might have been populated * with this entry and so we have to check again. @@ -273,7 +273,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req, return NULL; } - net = dev_net(dst->dev); + net = dev_net_rcu(dst->dev); hash ^= net_hash_mix(net); hash = hash_32(hash, tcp_metrics_hash_log); @@ -318,7 +318,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, else return NULL; - net = dev_net(dst->dev); + net = dev_net_rcu(dst->dev); hash ^= net_hash_mix(net); hash = hash_32(hash, tcp_metrics_hash_log); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 2debdf085a3b4d2452b2b316cb5368507b17efc8..429f8a5ab511b671aa405ae20f7c1b3163839779 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -376,7 +376,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, { const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; const struct tcphdr *th = (struct tcphdr *)(skb->data+offset); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); struct request_sock *fastopen; struct ipv6_pinfo *np; struct tcp_sock *tp; @@ -868,7 +868,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 struct tcphdr *t1; struct sk_buff *buff; struct flowi6 fl6; - struct net *net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev); + struct net *net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev); struct sock *ctl_sk = net->ipv6.tcp_sk; unsigned int tot_len = sizeof(struct tcphdr); __be32 mrst = 0, *topt; @@ -1039,7 +1039,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb, if (!sk && !ipv6_unicast_destination(skb)) return; - net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev); + net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev); /* Invalid TCP option size or twice included auth */ if (tcp_parse_auth_options(th, &md5_hash_location, &aoh)) return; @@ -1744,6 +1744,7 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr, INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) { + struct net *net = dev_net_rcu(skb->dev); enum skb_drop_reason drop_reason; int sdif = inet6_sdif(skb); int dif = inet6_iif(skb); @@ -1753,7 +1754,6 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) bool refcounted; int ret; u32 isn; - struct net *net = dev_net(skb->dev); drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (skb->pkt_type != PACKET_HOST) @@ -2004,7 +2004,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) void tcp_v6_early_demux(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); const struct ipv6hdr *hdr; const struct tcphdr *th; struct sock *sk; From patchwork Mon Feb 3 14:30:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957606 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-vs1-f73.google.com (mail-vs1-f73.google.com [209.85.217.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A779C20E03B for ; Mon, 3 Feb 2025 14:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593061; cv=none; b=Y+qI5+9aSs6xU0mZR9owCfvO6wl5VprLqdtxhlaojx4mDme/xEJ5/mfR6/50Rarp7IiuLAZAOZDoFRGPwGecdPqzqQyfCR2ZUiIbk6IUEzDJFfqoLaNcN0iJnRJEOJ4MiZZIvS6snednQTjpbZG84eLf/VA502QAlPp/1utq2xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593061; c=relaxed/simple; bh=6G9sTXBUqjV7uayq5LLEmA1X8vMgYBif8jKVAafOP5s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ONaRDZJu4qldMxCuWxApUlGB2NUElcDWhqFJAgJiorkj4nFZfygTCzIK++60Oy+B3LDPjq+h5hfaDm8XxjZSbEFalu0HMCcqbhTh51XUj1vr9xV/N7rQxd9AkgloTuROv+Nir333udOa5yYaAURx9ncfONDxjUuWQjuvadGvNyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qilWg5c3; arc=none smtp.client-ip=209.85.217.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qilWg5c3" Received: by mail-vs1-f73.google.com with SMTP id ada2fe7eead31-4afc5ee0e4aso106373137.0 for ; Mon, 03 Feb 2025 06:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593058; x=1739197858; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7epxpWBxPCncrKulKuyPm2yvwQ/qpoNphkrVwet06Pw=; b=qilWg5c3pEGwzZnykUXD5ypOsLGaIL00E9VeadFx73blcrqHt9Lp91UYbb1NP84bjh /iPGjmI7uTiJun6pkTcDpqt7eUgbeqVwdWLW0/1hTAjqFr172xTCWHe6yW71rzlDs+/P gNAQTEtMQAKwv+06PBL11cylysIh7pX7GE3B30x/wbGKwCxUYbYBBjuyJf5PAtEUKbts T86fHEayTTx1UZenOitg/2zxqU+AktLCA1Wab/ken5Wr+aaUdCxiGOIakiwB7OROD+cD sjSQugeUd8JyCPEOkK4hMKjgDV8OYtGUDyCpxhSqWFI/qQEFD+iDS9FIgLTiF6cGJ3RE rp5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593058; x=1739197858; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7epxpWBxPCncrKulKuyPm2yvwQ/qpoNphkrVwet06Pw=; b=gYYzAsGuFm4UYBCIMota9Ijkrc7/F9W1VTLM62iX7klJr+HF3sss70A0wlCg4dgnE9 00Z1wO4pld4PoyKa8sc188D4GTUCL7NToiiZlPIQGLuOvY5Mi9uj3qhz5/F6SopINzq2 MIqMSsL2H5qNMVgss793A3B+Wj4bBZGVAnGVaB9hSZoNPputspjfYlZiew6Ich10SReV ou1yb63SZVYpl0oHbxCy4Mlte2Np35Zh74L9eZPjYjMr+urtp8/bYJvlIVYSNjJq/hAC xNNPvMBKLt3+Gf+0uaDWZCTlWyUoABtInb9SBy5Fo+ZleKg737jfIYFxiqNg7vfDsM7X mUog== X-Gm-Message-State: AOJu0YzuFr3gS8aAFurZUjA8+1aRmpRbWYMn0HjOWEoi44BlNXZak5QY +cL8BsXmGvri2XJMXzgueFgGlkYQlkOxBeHadhMbbc5XzCXykSZ6/bJxOYzIby/mlmpBTyp6NIM Fm+U6NIGBDg== X-Google-Smtp-Source: AGHT+IFowGUMY6KvX6CYSCJak3CuMi6KVFMMJHzYP4baFpkdD00pssZaZyrByiDzEaPRL86RxNPF5DCEp4fktg== X-Received: from vsbka29.prod.google.com ([2002:a05:6102:801d:b0:4b6:373a:b38b]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:4687:b0:4b9:bd00:454b with SMTP id ada2fe7eead31-4b9bd004832mr6411341137.13.1738593058461; Mon, 03 Feb 2025 06:30:58 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:37 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-8-edumazet@google.com> Subject: [PATCH v2 net 07/16] net: gro: convert four dev_net() calls From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org tcp4_check_fraglist_gro(), tcp6_check_fraglist_gro(), udp4_gro_lookup_skb() and udp6_gro_lookup_skb() assume RCU is held so that the net structure does not disappear. Use dev_net_rcu() instead of dev_net() to get LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/tcp_offload.c | 2 +- net/ipv4/udp_offload.c | 2 +- net/ipv6/tcpv6_offload.c | 2 +- net/ipv6/udp_offload.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 2308665b51c5388814e5b61a262a1636d897c4a9..ecef16c58c07146cbeebade0620a5ec7251ddbc5 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -425,7 +425,7 @@ static void tcp4_check_fraglist_gro(struct list_head *head, struct sk_buff *skb, inet_get_iif_sdif(skb, &iif, &sdif); iph = skb_gro_network_header(skb); - net = dev_net(skb->dev); + net = dev_net_rcu(skb->dev); sk = __inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo, iph->saddr, th->source, iph->daddr, ntohs(th->dest), diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index a5be6e4ed326fbdc6a9b3889db4da903f7f25d37..c1a85b300ee87758ee683a834248a600a3e7f18d 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -630,7 +630,7 @@ static struct sock *udp4_gro_lookup_skb(struct sk_buff *skb, __be16 sport, __be16 dport) { const struct iphdr *iph = skb_gro_network_header(skb); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); int iif, sdif; inet_get_iif_sdif(skb, &iif, &sdif); diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c index a45bf17cb2a172d4612cb42f51481b97bbf364cd..91b88daa5b555cb1af591db7680b7d829ce7b1b7 100644 --- a/net/ipv6/tcpv6_offload.c +++ b/net/ipv6/tcpv6_offload.c @@ -35,7 +35,7 @@ static void tcp6_check_fraglist_gro(struct list_head *head, struct sk_buff *skb, inet6_get_iif_sdif(skb, &iif, &sdif); hdr = skb_gro_network_header(skb); - net = dev_net(skb->dev); + net = dev_net_rcu(skb->dev); sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo, &hdr->saddr, th->source, &hdr->daddr, ntohs(th->dest), diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index b41152dd424697a9fc3cef13fbb430de49dcb913..404212dfc99abba4d48fc27a574b48ab53731d39 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -117,7 +117,7 @@ static struct sock *udp6_gro_lookup_skb(struct sk_buff *skb, __be16 sport, __be16 dport) { const struct ipv6hdr *iph = skb_gro_network_header(skb); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); int iif, sdif; inet6_get_iif_sdif(skb, &iif, &sdif); From patchwork Mon Feb 3 14:30:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957607 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 099ED212F84 for ; Mon, 3 Feb 2025 14:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593062; cv=none; b=SRf4GZARSdCYrFIEx21WlE9VzQixsDgyvg+4Wsv3UpfOL3cSAvqKFPSZGYGQ1SpKQY9xv3cXspCN/pHQE5eJY6WZe4yp4OlBV7MG6lx16c9WAmW7cIjfY+N8jAFvl4dbM6VDaxAAYHM9+ndk079gQ3d8jMinKnZiibQ7GloH1nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593062; c=relaxed/simple; bh=rteRAK8u2cYuSPdsdFOuXbtGScv+u9pINXmSOxOYqEw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jd0r4WDjseclwNmPseJgHtuQjP0klDyqjWzQGsu3SjZBce5b+pPbFDnjC+k187cPLI8+wVPp7aaMUyFw2QkjsXI1b7OZSTIVCIZKoDaUIhfTyxzAwOiuDdVsFMLQ1/f41aotUILsjqcXhjkhtzEdx/VQIf/rRaJVZ3es+yxRbbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dZ+Vine3; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dZ+Vine3" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-467a0a6c846so95750941cf.1 for ; Mon, 03 Feb 2025 06:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593060; x=1739197860; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K75MRH5r6VIew1gMzCEXzzdkS9dRmi/YhLuN/XRo0eE=; b=dZ+Vine3dI5zHmn64QL7NsbqHJdRSbjNc06dqiBBmPJ/QTekNjNdo3WDm76eTE+ytR eWjXfB1cogPokuvwZIXUQhKO0CduDTOcFJqcVAUyE3MJwDZuMXSxTzMN8R0zOtQUiLw4 lk3S8/uFphBxHNOmriDo827dxE+sEOx7hwaFUwp0Whufl4sG5F0LN88liaxCZat9lNh7 xoQs/6ue4OadAa0pwgBRBtQ5AiFj6QA5PiH6EeSSAtBrTFmtywjLeUq9pYiSw0g5z1Mi zkZtBjyyLii+dAbzq/ej1PEHuCokrYIhKVqLRNqYXZ6D7NMT2VRXGdqxK5yLgWY2hn1d M6RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593060; x=1739197860; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K75MRH5r6VIew1gMzCEXzzdkS9dRmi/YhLuN/XRo0eE=; b=OIFLUwnXJPt3NEU6ipkbbie5EfN74DCFh9dWVxjhE1UTlx0LMmdWoGtrRIl+n/3z3s eOw4/zgahSDn92N8jDd0GG/BvcWjl4x2PUpi1acrYmKg9erRwCd4b9fc/8A+uN2PT1ot yyqo5dITcZ4WrSS/Rnpm36QyEGwH+HeXQll0GBqT7VH6+SerEfa9UuZNjruUwAotzR9h b3WDqua7grkg5YlbggsBprJ4ifhdPsnCUBgW+8mSC7NwwUFZbGPEK6MYGuJimLU1fuV8 144hmirddXGBZh6w1vYVMCWe9HfZtf6ZJrvuu07t3GKUZB6Hie/G+AXNq2zqoaY2A2PI fnVg== X-Gm-Message-State: AOJu0YyUkdj2GKQ55UCS125HZkhMsxldKduR6umnJzD3pzj4UDLGacSA DjjALigTZ0xJgQs0DSVIk1q7EpcSUay7m1EEnOTq8AH/ATNzcD8Qm0HPxw4sKjmIkMKna2cqcXb 45ZiGUCozVA== X-Google-Smtp-Source: AGHT+IFvsEloV68HLiN99Vm8eVjrwbH/RUo7TGZYC7PKTLHV5qAksbFWwKXDJ9G4KwWJ+Wf3ksLOjYJOYWXvyg== X-Received: from qtbfd13.prod.google.com ([2002:a05:622a:4d0d:b0:46f:c959:9b05]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:4a8a:b0:467:5082:74bd with SMTP id d75a77b69052e-46fd0b89816mr321391971cf.34.1738593059957; Mon, 03 Feb 2025 06:30:59 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:38 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-9-edumazet@google.com> Subject: [PATCH v2 net 08/16] udp: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org UDP uses of dev_net() are safe, change them to dev_net_rcu() to get LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/udp.c | 19 ++++++++++--------- net/ipv6/udp.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index a9bb9ce5438eaa9f9ceede1e4ac080dc6ab74588..fc1e37eb49190cb7e2671ebd54ac4fca54b77ac2 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -750,7 +750,7 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb, { const struct iphdr *iph = ip_hdr(skb); - return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport, + return __udp4_lib_lookup(dev_net_rcu(skb->dev), iph->saddr, sport, iph->daddr, dport, inet_iif(skb), inet_sdif(skb), udptable, skb); } @@ -760,7 +760,7 @@ struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb, { const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation]; const struct iphdr *iph = (struct iphdr *)(skb->data + offset); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); int iif, sdif; inet_get_iif_sdif(skb, &iif, &sdif); @@ -934,13 +934,13 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) struct inet_sock *inet; const struct iphdr *iph = (const struct iphdr *)skb->data; struct udphdr *uh = (struct udphdr *)(skb->data+(iph->ihl<<2)); + struct net *net = dev_net_rcu(skb->dev); const int type = icmp_hdr(skb)->type; const int code = icmp_hdr(skb)->code; bool tunnel = false; struct sock *sk; int harderr; int err; - struct net *net = dev_net(skb->dev); sk = __udp4_lib_lookup(net, iph->daddr, uh->dest, iph->saddr, uh->source, skb->dev->ifindex, @@ -1025,7 +1025,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) int udp_err(struct sk_buff *skb, u32 info) { - return __udp4_lib_err(skb, info, dev_net(skb->dev)->ipv4.udp_table); + return __udp4_lib_err(skb, info, dev_net_rcu(skb->dev)->ipv4.udp_table); } /* @@ -2466,7 +2466,7 @@ static int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) udp_post_segment_fix_csum(skb); ret = udp_queue_rcv_one_skb(sk, skb); if (ret > 0) - ip_protocol_deliver_rcu(dev_net(skb->dev), skb, ret); + ip_protocol_deliver_rcu(dev_net_rcu(skb->dev), skb, ret); } return 0; } @@ -2632,12 +2632,12 @@ static int udp_unicast_rcv_skb(struct sock *sk, struct sk_buff *skb, int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, int proto) { + struct net *net = dev_net_rcu(skb->dev); + struct rtable *rt = skb_rtable(skb); struct sock *sk = NULL; struct udphdr *uh; unsigned short ulen; - struct rtable *rt = skb_rtable(skb); __be32 saddr, daddr; - struct net *net = dev_net(skb->dev); bool refcounted; int drop_reason; @@ -2804,7 +2804,7 @@ static struct sock *__udp4_lib_demux_lookup(struct net *net, int udp_v4_early_demux(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); struct in_device *in_dev = NULL; const struct iphdr *iph; const struct udphdr *uh; @@ -2873,7 +2873,8 @@ int udp_v4_early_demux(struct sk_buff *skb) int udp_rcv(struct sk_buff *skb) { - return __udp4_lib_rcv(skb, dev_net(skb->dev)->ipv4.udp_table, IPPROTO_UDP); + return __udp4_lib_rcv(skb, dev_net_rcu(skb->dev)->ipv4.udp_table, + IPPROTO_UDP); } void udp_destroy_sock(struct sock *sk) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index c6ea438b5c7588edd2971997f21382c26446a45c..d0b8f724e4362ec35352dae547e916c912716cab 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -410,7 +410,7 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, { const struct ipv6hdr *iph = ipv6_hdr(skb); - return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport, + return __udp6_lib_lookup(dev_net_rcu(skb->dev), &iph->saddr, sport, &iph->daddr, dport, inet6_iif(skb), inet6_sdif(skb), udptable, skb); } @@ -420,7 +420,7 @@ struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb, { const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation]; const struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + offset); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); int iif, sdif; inet6_get_iif_sdif(skb, &iif, &sdif); @@ -702,16 +702,16 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, u8 type, u8 code, int offset, __be32 info, struct udp_table *udptable) { - struct ipv6_pinfo *np; const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; const struct in6_addr *saddr = &hdr->saddr; const struct in6_addr *daddr = seg6_get_daddr(skb, opt) ? : &hdr->daddr; struct udphdr *uh = (struct udphdr *)(skb->data+offset); + struct net *net = dev_net_rcu(skb->dev); + struct ipv6_pinfo *np; bool tunnel = false; struct sock *sk; int harderr; int err; - struct net *net = dev_net(skb->dev); sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source, inet6_iif(skb), inet6_sdif(skb), udptable, NULL); @@ -818,7 +818,7 @@ static __inline__ int udpv6_err(struct sk_buff *skb, u8 code, int offset, __be32 info) { return __udp6_lib_err(skb, opt, type, code, offset, info, - dev_net(skb->dev)->ipv4.udp_table); + dev_net_rcu(skb->dev)->ipv4.udp_table); } static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) @@ -929,7 +929,7 @@ static int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) udp_post_segment_fix_csum(skb); ret = udpv6_queue_rcv_one_skb(sk, skb); if (ret > 0) - ip6_protocol_deliver_rcu(dev_net(skb->dev), skb, ret, + ip6_protocol_deliver_rcu(dev_net_rcu(skb->dev), skb, ret, true); } return 0; @@ -1071,8 +1071,8 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, int proto) { enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; + struct net *net = dev_net_rcu(skb->dev); const struct in6_addr *saddr, *daddr; - struct net *net = dev_net(skb->dev); struct sock *sk = NULL; struct udphdr *uh; bool refcounted; @@ -1220,7 +1220,7 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net, void udp_v6_early_demux(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); const struct udphdr *uh; struct sock *sk; struct dst_entry *dst; @@ -1262,7 +1262,7 @@ void udp_v6_early_demux(struct sk_buff *skb) INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb) { - return __udp6_lib_rcv(skb, dev_net(skb->dev)->ipv4.udp_table, IPPROTO_UDP); + return __udp6_lib_rcv(skb, dev_net_rcu(skb->dev)->ipv4.udp_table, IPPROTO_UDP); } /* From patchwork Mon Feb 3 14:30:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957608 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ua1-f73.google.com (mail-ua1-f73.google.com [209.85.222.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7399B212F94 for ; Mon, 3 Feb 2025 14:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593064; cv=none; b=A0fbtErHppZJOR19dawCT+p0+jzQZ21PlUOccpBAJJWp88cwp3fP9ML8FsZUg2rbk2aixVtbnn1/ywRSNJWEG6MmxV8OrTW4tm8TsTSuWkZ97rXWekzaxAX7n1dUoaoTmoOe4v4s0rUOWvm51S8FywFnTWTbQX/BuJdqdMxvJj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593064; c=relaxed/simple; bh=d3dj99GwhO57qeQ2adh9xlLxNv6SasSECy9c0wvM8hA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fPNTbusXoYc46V2HgrbaNtoDGtVerC7RlpJYAdhEbGxOWhrKBMBrdihtG/Layspe7ZeHOy0gHms3H37AdBjVP+amAjzsexfiBS0fSmNWd6f0vYHbPkFRjueEsNEzjEeV8BprfY+jDMUdip0iUzlM5aIg/W00ZdWCHaMqjzZEjEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mehIXYGI; arc=none smtp.client-ip=209.85.222.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mehIXYGI" Received: by mail-ua1-f73.google.com with SMTP id a1e0cc1a2514c-86109879700so449537241.2 for ; Mon, 03 Feb 2025 06:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593061; x=1739197861; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E+ZMNVR2H63jr3rmlUpqr5AzS7G4WJne1EULmAVBdRU=; b=mehIXYGIVCyO00plH0Kgw5eTfZ+wfky+q+RGeIQzyyTwtvposu9xHrQ5efqyyVv0tA LaCsk1uP1ShdaibO1CuR2iqEY0NlQh9tuGLU/JU4UIRR/5UB+L6YNO0AWrCBFfyyBTd7 +Od960N/WAC68/U2+jQR2e+Xf+pkCPKnbnD4HLILwRE2185LxnSchgqsy+/8KjX72DfC G6AFS3L6dtRtEKYmemIW7tOa/3Jfq5oSmCdwoWACEObNxHpac/YhA/iYz+9u3nmBTcgf 0ok000iho71YwRVufCnkzJURM3P3besvY12TJx5HswF44pI0zinQpMxjtUcusplK1Tv0 U31Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593061; x=1739197861; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E+ZMNVR2H63jr3rmlUpqr5AzS7G4WJne1EULmAVBdRU=; b=I7wonv8k8tjiGGAOJn+6cD44eLu/D5AfQ1ICsibrtI7P6BCssRSpl1PDn4FopLxPsh TLEUvDICA3nPGZx7dII5juAk2Imq8qnYpUEpnagLZUPs3L289T091mK7d/zuGihaJ63l hiP96i90mhOhpDAsP8hmnMS6YMOrWWKpoLZ0iVpGAALDgQjfgoF8t+NJO3vI63rvIWCr v0lszg8c/mWbxvIZ2WurDi4Xv6FE2gN0RUH2lF96jr/+On6YbQlwZajiXP2HW3szmZPd V0Z4PllPqXAJimiss0j0F1rDHyi+42VxPly2l5+wQOo97yog58qPVCFiWGrxXh6sC9sx f/YQ== X-Gm-Message-State: AOJu0Yya0dey20INGWiDKX7U6vPCYSwoeizAzPU02oSBpkdm3hahaXPw CYDgwrjcmIq6TntyNwkC9VgmZAKGlyq/NZMxKPDo24mcZRkHCW+nL87gowrxi3U2FIUiRTsbOCw m7k/+U3gL2A== X-Google-Smtp-Source: AGHT+IEEwB8C7BPhqTDfCMdaqAhZaj5RWt0+s5JsxcAKBZBZy4hef2lkZyaNWPwOP1CDzyUrR0kMSqNdXl94oQ== X-Received: from vsvd34.prod.google.com ([2002:a05:6102:14a2:b0:4b4:53a9:4626]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:571b:b0:4b1:340a:ce63 with SMTP id ada2fe7eead31-4b9a4fa355dmr16459530137.11.1738593061244; Mon, 03 Feb 2025 06:31:01 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:39 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-10-edumazet@google.com> Subject: [PATCH v2 net 09/16] ipv4: icmp: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ICMP uses of dev_net() are safe, change them to dev_net_rcu() to get LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/icmp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 094084b61bff8a17c4e85c99019b84e9cba21599..19bf8edd6759872fe667af82790b77b01212271b 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -401,7 +401,7 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb) { struct ipcm_cookie ipc; struct rtable *rt = skb_rtable(skb); - struct net *net = dev_net(rt->dst.dev); + struct net *net = dev_net_rcu(rt->dst.dev); bool apply_ratelimit = false; struct flowi4 fl4; struct sock *sk; @@ -611,9 +611,9 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, goto out; if (rt->dst.dev) - net = dev_net(rt->dst.dev); + net = dev_net_rcu(rt->dst.dev); else if (skb_in->dev) - net = dev_net(skb_in->dev); + net = dev_net_rcu(skb_in->dev); else goto out; @@ -834,7 +834,7 @@ static void icmp_socket_deliver(struct sk_buff *skb, u32 info) * avoid additional coding at protocol handlers. */ if (!pskb_may_pull(skb, iph->ihl * 4 + 8)) { - __ICMP_INC_STATS(dev_net(skb->dev), ICMP_MIB_INERRORS); + __ICMP_INC_STATS(dev_net_rcu(skb->dev), ICMP_MIB_INERRORS); return; } @@ -868,7 +868,7 @@ static enum skb_drop_reason icmp_unreach(struct sk_buff *skb) struct net *net; u32 info = 0; - net = dev_net(skb_dst(skb)->dev); + net = dev_net_rcu(skb_dst(skb)->dev); /* * Incomplete header ? @@ -979,7 +979,7 @@ static enum skb_drop_reason icmp_unreach(struct sk_buff *skb) static enum skb_drop_reason icmp_redirect(struct sk_buff *skb) { if (skb->len < sizeof(struct iphdr)) { - __ICMP_INC_STATS(dev_net(skb->dev), ICMP_MIB_INERRORS); + __ICMP_INC_STATS(dev_net_rcu(skb->dev), ICMP_MIB_INERRORS); return SKB_DROP_REASON_PKT_TOO_SMALL; } @@ -1011,7 +1011,7 @@ static enum skb_drop_reason icmp_echo(struct sk_buff *skb) struct icmp_bxm icmp_param; struct net *net; - net = dev_net(skb_dst(skb)->dev); + net = dev_net_rcu(skb_dst(skb)->dev); /* should there be an ICMP stat for ignored echos? */ if (READ_ONCE(net->ipv4.sysctl_icmp_echo_ignore_all)) return SKB_NOT_DROPPED_YET; @@ -1040,9 +1040,9 @@ static enum skb_drop_reason icmp_echo(struct sk_buff *skb) bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr) { + struct net *net = dev_net_rcu(skb->dev); struct icmp_ext_hdr *ext_hdr, _ext_hdr; struct icmp_ext_echo_iio *iio, _iio; - struct net *net = dev_net(skb->dev); struct inet6_dev *in6_dev; struct in_device *in_dev; struct net_device *dev; @@ -1181,7 +1181,7 @@ static enum skb_drop_reason icmp_timestamp(struct sk_buff *skb) return SKB_NOT_DROPPED_YET; out_err: - __ICMP_INC_STATS(dev_net(skb_dst(skb)->dev), ICMP_MIB_INERRORS); + __ICMP_INC_STATS(dev_net_rcu(skb_dst(skb)->dev), ICMP_MIB_INERRORS); return SKB_DROP_REASON_PKT_TOO_SMALL; } @@ -1198,7 +1198,7 @@ int icmp_rcv(struct sk_buff *skb) { enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; struct rtable *rt = skb_rtable(skb); - struct net *net = dev_net(rt->dst.dev); + struct net *net = dev_net_rcu(rt->dst.dev); struct icmphdr *icmph; if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { @@ -1371,9 +1371,9 @@ int icmp_err(struct sk_buff *skb, u32 info) struct iphdr *iph = (struct iphdr *)skb->data; int offset = iph->ihl<<2; struct icmphdr *icmph = (struct icmphdr *)(skb->data + offset); + struct net *net = dev_net_rcu(skb->dev); int type = icmp_hdr(skb)->type; int code = icmp_hdr(skb)->code; - struct net *net = dev_net(skb->dev); /* * Use ping_err to handle all icmp errors except those From patchwork Mon Feb 3 14:30:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957609 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1256212F91 for ; Mon, 3 Feb 2025 14:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593065; cv=none; b=FuJDTE1Yi+e12hlVMavdgceJyUuBziIoFJO+Bdzso076+dGxF1imOV8sWWjFqrlIW0UvELkvM95yL+akR5Tw0wT3WvTDkUXtbxFVX2oPOHZIh4uoqX7WB95eezJg+h+GOgT+8dOE1lZlf/6uV4r/mqQgTwM71Ky1D7vRK3MZVaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593065; c=relaxed/simple; bh=UAREnimGDnAPmblWyRsCCH95nTc2i7eXgPYT9YVWUrA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=d8l/n9qfFx/nQWI5c/CbC52MpwQfE7lVCpOQduDzswMUlNnEnel1odY3LRY+5zEWLixM30gGi16JCl4Dz4yXnUSZiBOjwOlE7R/HN04VV0ZzXATV1Rnv8WuTJEsg334xXPi91UQyAe4HWhjf9hlHcZCU34x7gNHovnRg86TROLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GGqoYF5x; arc=none smtp.client-ip=209.85.222.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GGqoYF5x" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7b6e1b036e9so417609885a.1 for ; Mon, 03 Feb 2025 06:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593062; x=1739197862; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1EiXpuWGhqESdC70TCk7qzohz2NCfhSMk5sOznVLWlQ=; b=GGqoYF5x6dF4fmx/Q4AnxEGTpEJvnwphk2d5uFt5BOAUhyfLk8hoUylqKE2DVUhfjb RVh4u9ZHy8Ml93R/7twZbEyEGRnikNoyt/CF4UoRHaOES45ViaiBzgAKQhOSD3kgwWY+ zso8ghO2DO1jpm+VYKWGitIfrO8VZmhZbfoKX5ck0bskG6sVpyuCNJ5EZpuEBH6RvU5i gvSsvBjWaH4CEUGqtXoBdXMOva5EZxLfiPR4opUksjhYxvulzTJQmmJryK+Y69ODL8w0 IcPtFrJ4lGWSaaTmNbqhg78gPOa6Ab2BZRCa9mep/NY3GbRW5uTp+zVT3qg3vPR8UyPc SFrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593062; x=1739197862; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1EiXpuWGhqESdC70TCk7qzohz2NCfhSMk5sOznVLWlQ=; b=C+ryOpwT9liSwZgMFyNYOM6S0jWCttXD39827UwqWhsJ12OhxWXy1sIjfKKZ3Y/9te 5tvxM9R7zYf1iNBzR+AJkO6u4AAVtGcVucny3BIqT/d8ycpIjoLytDycSSGurePQQFwG +tkC+HXRV8s6FdTHQM3DUAEFNzurVDz2OPPO0GkzusUbqh8fMXQYuV8BuQFPN64dDJYK zlX2tLE198QC3ULa3eeenbXywa0gV/myQm7Z1OOJI13fn9qtd1Yh58CrpjUshfwYlxup 5+K8tXl/YdRzr9WbZWzngk5tSwwhTACLTN7Dl9nMktjlIjoMIgVuVjwWlBY+HgWF7oW5 p5gg== X-Gm-Message-State: AOJu0Ywi7LeB4B6KR6WovIxrTQgg8N3R5waJP0fHPkGzdNvh7nUjRdvO qkxgFPzInJVMHSpv/aPMtia9AkmJjaZ5bX72KaF4QPOGUxEvsRyR/Ea2QIQ7OYwI9nTUZgp801N KH7Wrd/0jkg== X-Google-Smtp-Source: AGHT+IF63rVFKnnWHqxn8Q5uGvjSVxi8vYoKC9hGpYP2xvCQbLN0mh90UpnDaOzPh6aWjERzm5MpNDIUqHHGPg== X-Received: from qkbdz28.prod.google.com ([2002:a05:620a:2b9c:b0:7b6:f191:b68b]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:4608:b0:7b1:4327:7b63 with SMTP id af79cd13be357-7bffcd0e923mr3351382585a.32.1738593062548; Mon, 03 Feb 2025 06:31:02 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:40 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-11-edumazet@google.com> Subject: [PATCH v2 net 10/16] ipv6: icmp: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ICMP uses of dev_net() are safe, change them to dev_net_rcu() to get LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv6/icmp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index a6984a29fdb9dd972a11ca9f8d5e794c443bac6f..cb9ba5d8b6bab340fd4900f2fa99baa1ebeacb0f 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -76,7 +76,7 @@ static int icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, { /* icmpv6_notify checks 8 bytes can be pulled, icmp6hdr is 8 bytes */ struct icmp6hdr *icmp6 = (struct icmp6hdr *) (skb->data + offset); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); if (type == ICMPV6_PKT_TOOBIG) ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0, sock_net_uid(net, NULL)); @@ -473,7 +473,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, if (!skb->dev) return; - net = dev_net(skb->dev); + net = dev_net_rcu(skb->dev); mark = IP6_REPLY_MARK(net, skb->mark); /* * Make sure we respect the rules @@ -679,8 +679,8 @@ int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type, skb_pull(skb2, nhs); skb_reset_network_header(skb2); - rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, - skb, 0); + rt = rt6_lookup(dev_net_rcu(skb->dev), &ipv6_hdr(skb2)->saddr, + NULL, 0, skb, 0); if (rt && rt->dst.dev) skb2->dev = rt->dst.dev; @@ -717,7 +717,7 @@ EXPORT_SYMBOL(ip6_err_gen_icmpv6_unreach); static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); struct sock *sk; struct inet6_dev *idev; struct ipv6_pinfo *np; @@ -832,7 +832,7 @@ enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info) { struct inet6_skb_parm *opt = IP6CB(skb); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); const struct inet6_protocol *ipprot; enum skb_drop_reason reason; int inner_offset; @@ -889,7 +889,7 @@ enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type, static int icmpv6_rcv(struct sk_buff *skb) { enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); struct net_device *dev = icmp6_dev(skb); struct inet6_dev *idev = __in6_dev_get(dev); const struct in6_addr *saddr, *daddr; @@ -921,7 +921,7 @@ static int icmpv6_rcv(struct sk_buff *skb) skb_set_network_header(skb, nh); } - __ICMP6_INC_STATS(dev_net(dev), idev, ICMP6_MIB_INMSGS); + __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_INMSGS); saddr = &ipv6_hdr(skb)->saddr; daddr = &ipv6_hdr(skb)->daddr; @@ -939,7 +939,7 @@ static int icmpv6_rcv(struct sk_buff *skb) type = hdr->icmp6_type; - ICMP6MSGIN_INC_STATS(dev_net(dev), idev, type); + ICMP6MSGIN_INC_STATS(dev_net_rcu(dev), idev, type); switch (type) { case ICMPV6_ECHO_REQUEST: @@ -1034,9 +1034,9 @@ static int icmpv6_rcv(struct sk_buff *skb) csum_error: reason = SKB_DROP_REASON_ICMP_CSUM; - __ICMP6_INC_STATS(dev_net(dev), idev, ICMP6_MIB_CSUMERRORS); + __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_CSUMERRORS); discard_it: - __ICMP6_INC_STATS(dev_net(dev), idev, ICMP6_MIB_INERRORS); + __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_INERRORS); drop_no_count: kfree_skb_reason(skb, reason); return 0; From patchwork Mon Feb 3 14:30:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957610 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2D0212FA9 for ; Mon, 3 Feb 2025 14:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593066; cv=none; b=Dp4mq/nKtBoRdfPByUPEVEwvXDeJxoLu9ISyn71Stq2aAjeYS+H4C41wBOuIj88UE2CHrotbyYNOkqWiTVrbKb69vKeTWgEYT/C1HLzUiQWMfd0gBBBAYLCYohEhbV0Vfj26I3Wv15r78bYtwDlS7N98u0JdyZqE4Y+qy9BLjas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593066; c=relaxed/simple; bh=aVvJrJ1SNcCktf1pQeSHpv9lzkWbBlZMrIEN1xAcgKE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uQIYKGfQZhqhuPsfMjGW1pN+Bc7dmyBUAlAQ+kprJk+aEI+8OUREYeSCdjdRswEvr24D6bsxTLxrfrvCHWT5K0bvQxqSWxQ/dvSfSKifO0Q4yiSbN6mXQK7VC5Vwv+PwrWncz3p09Z8imZ9niEkMBdeqWAMjuAtUpqkg/d4f0is= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SCqW3N9r; arc=none smtp.client-ip=209.85.222.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SCqW3N9r" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7be6ccb09f9so417163885a.2 for ; Mon, 03 Feb 2025 06:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593064; x=1739197864; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iOhcfL8xgGzqzFZgJPYOqzYxywHOMdwlzghIyI1cDsc=; b=SCqW3N9rzhNpTFrZatm/H8CAMlM8VmZMgj8OFj1RXJQbMOrABIrJ0cbwp5wxNiXshd jsscNGHBd2is4SpqagdG44cqHNh4TxOOKHdEI04eshrgp7jWp8Z4G/0l5yHobak1Kb4N y1i69BIzP5e/sYJCPwVKOwCE6jk83wkKvXVyndRov0SeYf2MZSvMcQsKLwE5+zsAeaPO dOToMbtrQKMteDLt8am8U2OWL30WnGv+9OjB9QK+n5NlV5N0c8hlwoMuWa5HN1+PbdBR S/pcIVKsMRbEkuwDext/cPrbgOLyUZLLEFBBN+yBFU9uGgkhVkvLhH0kU2MKk6n0U0ZB MVDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593064; x=1739197864; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iOhcfL8xgGzqzFZgJPYOqzYxywHOMdwlzghIyI1cDsc=; b=fqR1k7ygcdQSj8N4334wGxhtJdFue6+M+s6SpC3GytPxcbvpTIfLEKlb9jcdn9fKcb 2Qif7GSxt4uHD/b4wCqzeECYHjAFjkpqRqjonUoQTBRg+yZwyBStr+wquDbvmfsERd26 689l4/HLK9Mq0houEzMTq35M6MWpM3nL4ErNuAoOzca9H4mianGgwlvrBqT+/i9sPVrr i0GaM2WW5oCKKZvMJjf7ZAGojslsiofjZ8eIm6FaleasZPeFxaVB6JPDyw2uBkiWYs0C j7HWEKWXaSrgGFz4xgxD6nY0XRJ7KakrbmBdEAJrGm471AW3imXGMXvonX2uU/yHnjFZ 7RVQ== X-Gm-Message-State: AOJu0YxPPU30vZ1HCTBDycQAjexs5GOf37Srn++OD87Qc2Udl2oIvm1Q kpUqtTcaz0Di9yxUCVpPA983aC33RdZ3v/CyKZ8wMiR48XLM3aGBEy/lFZ+mD1uKQo3nihUbpzZ hcwjVFazqyQ== X-Google-Smtp-Source: AGHT+IECcHu98EmshGvwgbCNylQ8wOzOBoO0e5rpAv5bHzRWBuL7tYUNK6vekb9QQpv4Qy8vw/gKY9TS5NYNcQ== X-Received: from qkbea21.prod.google.com ([2002:a05:620a:4895:b0:7be:55fd:843b]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:278e:b0:7b6:dd82:ac9c with SMTP id af79cd13be357-7bffccc91e0mr3082182585a.12.1738593064043; Mon, 03 Feb 2025 06:31:04 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:41 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-12-edumazet@google.com> Subject: [PATCH v2 net 11/16] ipv6: input: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org dev_net() calls from net/ipv6/ip6_input.c seem to happen under RCU protection. Convert them to dev_net_rcu() to ensure LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv6/ip6_input.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 70c0e16c0ae6837d1c64d0036829c8b61799578b..4030527ebe098e86764f37c9068d2f2f9af2d183 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -301,7 +301,7 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); skb = ip6_rcv_core(skb, dev, net); if (skb == NULL) @@ -330,7 +330,7 @@ void ipv6_list_rcv(struct list_head *head, struct packet_type *pt, list_for_each_entry_safe(skb, next, head, list) { struct net_device *dev = skb->dev; - struct net *net = dev_net(dev); + struct net *net = dev_net_rcu(dev); skb_list_del_init(skb); skb = ip6_rcv_core(skb, dev, net); @@ -488,7 +488,7 @@ static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *sk int ip6_input(struct sk_buff *skb) { return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_IN, - dev_net(skb->dev), NULL, skb, skb->dev, NULL, + dev_net_rcu(skb->dev), NULL, skb, skb->dev, NULL, ip6_input_finish); } EXPORT_SYMBOL_GPL(ip6_input); @@ -500,14 +500,14 @@ int ip6_mc_input(struct sk_buff *skb) struct net_device *dev; bool deliver; - __IP6_UPD_PO_STATS(dev_net(skb_dst(skb)->dev), + __IP6_UPD_PO_STATS(dev_net_rcu(skb_dst(skb)->dev), __in6_dev_get_safely(skb->dev), IPSTATS_MIB_INMCAST, skb->len); /* skb->dev passed may be master dev for vrfs. */ if (sdif) { rcu_read_lock(); - dev = dev_get_by_index_rcu(dev_net(skb->dev), sdif); + dev = dev_get_by_index_rcu(dev_net_rcu(skb->dev), sdif); if (!dev) { rcu_read_unlock(); kfree_skb(skb); @@ -526,7 +526,7 @@ int ip6_mc_input(struct sk_buff *skb) /* * IPv6 multicast router mode is now supported ;) */ - if (atomic_read(&dev_net(skb->dev)->ipv6.devconf_all->mc_forwarding) && + if (atomic_read(&dev_net_rcu(skb->dev)->ipv6.devconf_all->mc_forwarding) && !(ipv6_addr_type(&hdr->daddr) & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)) && likely(!(IP6CB(skb)->flags & IP6SKB_FORWARDED))) { From patchwork Mon Feb 3 14:30:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957611 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B698212FB6 for ; Mon, 3 Feb 2025 14:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593068; cv=none; b=ojHBmw9XWChdbXC80rowyHbqlk809wd+RKh3nPhjoXixV0T/GVmjuX0Oi89zMMaeRqQwUo4T/uimZ41PiOqBiHZJEggly2s3Cwr6VCr2o30m2qkn+UoBO519idmmbrIGzifdpEjWFaG94HiBwD+j4qnnQYWIMo4oPwQjwKYESfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593068; c=relaxed/simple; bh=EBbPvxOWDuVZT9dCKcZQ7dF5vOxnJ2dsyERiuGzIvv8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Wul+fHnTdbencUI2HA9OoRlR+YGLgO7YVxGpFgRw3NxXRRiRzA6va2pVnotBa5wrT82JfJWxdb5J+7ZuSnhGrtoFcqVPhdnk66JzRgKqlt65JVWj3udDRzDrtueihaeccZEpq/qCqU15hDl2aZXMXAQT3jG1+ulSmsRHIM3nvDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qvSGTTzA; arc=none smtp.client-ip=209.85.219.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qvSGTTzA" Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6d8fe8a0371so70558206d6.1 for ; Mon, 03 Feb 2025 06:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593065; x=1739197865; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=W/SVdRvkLIsGq6su81v12UHC6PsBXnXjKLGYhsQefYE=; b=qvSGTTzAQL6m7ySS4RJkY2vhca83aDesTi7mqtvaCfA2WnJyATXq8i9OFDQj8lQu40 srec0IeZs2RCQuMmuCG62PQC9SGlFyGcn6SzcvHl+2Z2FE0SGOsgdpVtPTyPh1DqiMi/ Mxsmz+yKRhaa04riX9tl6p4O1eJaYXjNThcjHjcsbOz0P8DWINWrc704/dOODJ/BU/sG 8Bquxc2fwly+FgAaO9zBgXG6UNEW3ZoynnAmrujYzZqtq6rL0Om+omtCfLerge4SmpPC GCc7jZj6ZHhW/vjRjUzqYEJiZd46QljTopjCwcePN4FcghhrRjV+cPoRQTV6KxSbcsq5 MQKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593065; x=1739197865; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W/SVdRvkLIsGq6su81v12UHC6PsBXnXjKLGYhsQefYE=; b=ay/JP/xfVQM7HOnKe6vncuM14C16xm24flNKTLzd36B/NbWGVamBcYWja6Ri++85FB I9GbwwRnwa8h2vDEUDc3W7m5XsVkljbQGBw/A9G96L35KxaRGYR2LzOaZNDamHxCVJh2 fKwrw4gwBgYkhG1oQpfbGTtI3r4xEMzP/q1iSst9WiJwZ/q7mtHu6R3yVf6sNlYOFgWR n0J1qLpyXp654cR4+NCc6bj6GFGsoHixfb64TQ3GFZtXS61kbyKx5il9LL/iiT0is6lP j0q+BKJLSvun3B/5dsdpKIUraMq+cqPW4SUtxlA9S4Ag3Ht4E5rugYpoYrP0BRMiscL7 GI+A== X-Gm-Message-State: AOJu0YwvFDSnNduzorBq0cuuoAHdtOIh2PXR6h/wE3D4O2eMvrq8qlJa 5jruR6xSd3VdRuXo5sGeY440mgFuoEgJGRBpSCAvrEKaTNsBh6WJQFE8KPwONz5eEBgYz5p8WgH Ek9SuDABUTQ== X-Google-Smtp-Source: AGHT+IGw3EetgSeKPNRgsQbu0MeSYCUMrSM6H/uqiv6/c+lfoXxTzw2xlwuE4qvQuQ1FoPMP4lmV/LXIjPiKKg== X-Received: from qvboq11.prod.google.com ([2002:a05:6214:460b:b0:6e2:355c:1fa9]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:412:b0:6d8:a84b:b508 with SMTP id 6a1803df08f44-6e243bb84e7mr291283806d6.12.1738593065417; Mon, 03 Feb 2025 06:31:05 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:42 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-13-edumazet@google.com> Subject: [PATCH v2 net 12/16] ipv6: output: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org dev_net() calls from net/ipv6/ip6_output.c and net/ipv6/output_core.c are happening under RCU protection. Convert them to dev_net_rcu() to ensure LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv6/ip6_output.c | 4 ++-- net/ipv6/output_core.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index d577bf2f3053873d27b241029592cdbb0a124ad7..4c73a4cdcb23f76d81e572d5b1bd0f6902447c0e 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -393,7 +393,7 @@ static int ip6_call_ra_chain(struct sk_buff *skb, int sel) sk->sk_bound_dev_if == skb->dev->ifindex)) { if (inet6_test_bit(RTALERT_ISOLATE, sk) && - !net_eq(sock_net(sk), dev_net(skb->dev))) { + !net_eq(sock_net(sk), dev_net_rcu(skb->dev))) { continue; } if (last) { @@ -503,7 +503,7 @@ int ip6_forward(struct sk_buff *skb) struct dst_entry *dst = skb_dst(skb); struct ipv6hdr *hdr = ipv6_hdr(skb); struct inet6_skb_parm *opt = IP6CB(skb); - struct net *net = dev_net(dst->dev); + struct net *net = dev_net_rcu(dst->dev); struct inet6_dev *idev; SKB_DR(reason); u32 mtu; diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c index 806d4b5dd1e60b27726facbb59bbef97d6fee7f5..94438fd4f0e833bb8f5ea4822c7312376ea79304 100644 --- a/net/ipv6/output_core.c +++ b/net/ipv6/output_core.c @@ -113,7 +113,7 @@ int ip6_dst_hoplimit(struct dst_entry *dst) if (idev) hoplimit = READ_ONCE(idev->cnf.hop_limit); else - hoplimit = READ_ONCE(dev_net(dev)->ipv6.devconf_all->hop_limit); + hoplimit = READ_ONCE(dev_net_rcu(dev)->ipv6.devconf_all->hop_limit); rcu_read_unlock(); } return hoplimit; From patchwork Mon Feb 3 14:30:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957612 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 136ED212FAF for ; Mon, 3 Feb 2025 14:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593069; cv=none; b=kbiFfV0AxEb5KibJ3+ShqtSjRcWwvuKvyaEgRyHb21azDYzilWCf6eCy1yp0QYGKBSJ1+JPrgnwgRZkF6Vbu3xZW1PD1wqhE02QxSzFuQl5Oohbr2lZvsGhEmQCSfqbYe7vfq2Mc6TzMNdK+oiwkAXU8+G+zdPtaHUN5hjHeOcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593069; c=relaxed/simple; bh=prnXcbt2huvfvhxZLdActDxMXy0yTt0im8WFkYLwVDo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CDVFSn91gxXErQ5D5t0FODcFd/vXMkaCyhuFrULMpAgVPFA7lZgXrd9mOBR89DZTNfizMaSbXw87BbkzNg4rIwzwo96TnaggPiJ+Ph/F7JGz5YIgOi3Af0EwD866m2CmVKLh9lAatYlhCiyUJCoy7lHZ2Mrs0MaOu6ELPvJlkhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B/WQ6SsK; arc=none smtp.client-ip=209.85.219.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B/WQ6SsK" Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6dd43b16631so50286476d6.2 for ; Mon, 03 Feb 2025 06:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593067; x=1739197867; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9L3PBsjMaEaZKuEqPtTlZplZbWwE3hgdPgBONKRJuy8=; b=B/WQ6SsKRJzxDMGQDxSxzYEcexJKhjC9BaQUx39zgltT0OOd7lQF+RPTdMPhN/3jQa 9CaC7bY9EO4GaFV7+FMpe19OGfwvttzyqTB4yQD+7rUNsQ/r3HuEIy93BFdvSw3yvhQF 4lgJX+VtIJY/0ntzXsuHdxQyVyO20HVCFVAsx4Tl0GXN1uHDmiEL7pCILkesKQlzD1be lH4LPZAyTRTsj3f8BLfks1YpUmjdlxaozfahbnrs55ueX6iHMmZ/f6EqSVFbxbI2iQsF U4LlgZsdC94HX9z09ypsOwkTf7dehVSelqWktCkmMubmUnWXVlcZ0NP1z7o1cOhAgPCI sqYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593067; x=1739197867; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9L3PBsjMaEaZKuEqPtTlZplZbWwE3hgdPgBONKRJuy8=; b=BYJZ7MPx8/Y7sQe51g68xgI4Y+i7raHwy/CLPQYOBnbSNK0MvjnBnGQjPCY8Qp0Q6H Zr6ykf/qkT45av5e90oX/5VHDj8ItuzyWCJXfzDDMNK00rxpuClgCqKBqqFaI0zyHMes 2PIopOyuoWXf3Ts8nOTq15RW1k9ECEF+FqcpwUYPS4amXnRVQ5zV+EP8CzitNCeZQOok B2TyErucns5TwqaMSkcbaq264g+6MpXZBiPPE5qW0Dc2Q6zWOyWIkuJIF9sU2G5OohqD gSYzaI9dq4dBaRVQ3KIA7ilG1Za7fjmFztE8AU8iZi5nPubGjpcM+xXhuozMmfGm+fRK wVoA== X-Gm-Message-State: AOJu0Yz+trmlmE4Aj1Vo5B5QRqqcC7qvhV7ZPfi4BMSHsyVJU1FLG5Zv +ORL6hn3PyAAtEGu/UeQt3++3qZotoIBtPM9vBb07Xee6AfeBE2LuvMtJo0pIQJBsshqF6bvt7p aFUUSDWSFPQ== X-Google-Smtp-Source: AGHT+IF2DnzYK53Vvyw+YH1v173mBxe750NiYvXf7//be7mcTVmHwL2BP/0Re1Xwgxux8Tc951OCHJBBR7Wwmg== X-Received: from qvbqr7.prod.google.com ([2002:a0c:f207:0:b0:6d8:aa93:951c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:1bc7:b0:6d8:96a6:ec27 with SMTP id 6a1803df08f44-6e243c63d6cmr320971406d6.35.1738593066846; Mon, 03 Feb 2025 06:31:06 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:43 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-14-edumazet@google.com> Subject: [PATCH v2 net 13/16] ipv6: use RCU protection in ip6_default_advmss() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ip6_default_advmss() needs rcu protection to make sure the net structure it reads does not disappear. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv6/route.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 78362822b9070df138a0724dc76003b63026f9e2..ef2d23a1e3d532f5db37ca94ca482c5522dddffc 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3196,13 +3196,18 @@ static unsigned int ip6_default_advmss(const struct dst_entry *dst) { struct net_device *dev = dst->dev; unsigned int mtu = dst_mtu(dst); - struct net *net = dev_net(dev); + struct net *net; mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); + rcu_read_lock(); + + net = dev_net_rcu(dev); if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) mtu = net->ipv6.sysctl.ip6_rt_min_advmss; + rcu_read_unlock(); + /* * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and * corresponding MSS is IPV6_MAXPLEN - tcp_header_size. From patchwork Mon Feb 3 14:30:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957613 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88C61212F94 for ; Mon, 3 Feb 2025 14:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593071; cv=none; b=SSIEzVYYcj2vkFA84PWMFnFK6+za0bF/SM5/n9Fwwzmjo0T+twFNQBwP2zmqfqBVGk2VDLwuUofi8Z0ZtDIOjTH1N9HPSWOvhU4aPysf9g7saaZKkfCCp5EScM+n8SsWnLi8ra6sxvry5tf9wkqYGmpRyuyc7UgILZfpuTfV6+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593071; c=relaxed/simple; bh=bCrUEuXphnjaajetK5d7E+Vl/pwtSltcGVcBJpV2W7s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=P3j6H3seM7g9O8TeMyFbphCKYDLD92ljcWYrk9l36tL4+xE7mwj1NmQSM+RPJeOkOFafI9FZS4NAzglWR/SpAb305LYsamEimGgLIaLlS4KAQxvIexhEtsQH6sL6WKc859p5koA8hMgaYIsOPvQbNL0reOpVd4SgWSubGFv/8vg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=32fV2SOP; arc=none smtp.client-ip=209.85.219.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="32fV2SOP" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6d8f8b9d43aso80312486d6.0 for ; Mon, 03 Feb 2025 06:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593068; x=1739197868; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FdwFRR960fzI8SNxNneTg6AR0rewjjfndjH2F50AsxA=; b=32fV2SOPQiqotO862ZoOE6qY40kw7nA/f6Ur6XqOXf08PJUUikFaH0OrJUjUR6qPIm Tn1Yo8RU9HXn1ydFTsmGGnCJeUQ4iDQONJrFtiCTiv6xAVjtPExcAOq48FFRqVkQhrUg k1DijDiGmgmxWvs/BbvdblJf+9ndoPh6mQOgILjZJ4dYclqZYx6DaBQwjRDD5T/9A9nS svNwhlSykowhKehFQsuvBQPW9gnnZBO1zaUlZamm9su5ujW2oqNGQTOyEZbAYuhjryfu taJDG06kf+yRvxZm/7kDR2dICeTluFK42iibH6HI/dSbVb1jHJa7/EYP4aQt5afGeYeV 1R5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593068; x=1739197868; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FdwFRR960fzI8SNxNneTg6AR0rewjjfndjH2F50AsxA=; b=OJeMNZtKnd7kiCrMjwlBAvaB1UBj9qWxhfKzMcbJngpniLtWhL6x7j64XW63mauKGl m6H6kUMl5uaEle1/pq4/CMdqZeho92+Cf2up34Kx95jdsxlfRcxPrCevpgoHcSq99Kef FwkHZ7MIrmiflWZgxY1qAJlOgaBaw+aWj5qt3/RDRoLw83l4fxZ3bcJt+AZPYCRg3wsf 4XmgJQsqo83OmZZuNM/mGb8++ei7XQsksLUrIb/BrafS0XsSlVoPDZNMlcnGaPwea+qE BJEM07GTFNDCvpp7lScaw4kCAN/FcLdYTlA4YM0aHIZNDNTkcU/Ub/XIYupue7I8AsD+ HHEg== X-Gm-Message-State: AOJu0Yx8/rPe1qzoli8fQMlk6OEY9gLLvpffvukaH/jp3xN7sqEUaMXq cXPfr5e7AYvZuEp3XDrhjGlbNlSWKhft6DEAx03sQmiBqHw1NoXW+Byj71TSmvdheO0AJj/FWzj h8cVStAUevw== X-Google-Smtp-Source: AGHT+IE5ZhpgsXUG4yVzeJPJ96POBJ0bLZqZaR/4U13cO5Q1WO6T0KUOJ8dID27oBtqg0gaK+KdzGOCBtsnlIw== X-Received: from qvbkf3.prod.google.com ([2002:a05:6214:5243:b0:6e2:4dfe:895d]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:3285:b0:6e1:a078:f40f with SMTP id 6a1803df08f44-6e243c7a9e7mr284058316d6.44.1738593068399; Mon, 03 Feb 2025 06:31:08 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:44 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-15-edumazet@google.com> Subject: [PATCH v2 net 14/16] net: filter: convert to dev_net_rcu() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All calls to dev_net() from net/core/filter.c are currently done under rcu_read_lock(). Convert them to dev_net_rcu() to ensure LOCKDEP support. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/core/filter.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 2ec162dd83c463640dcf3c151327206f519b217a..4db537a982d55fa9b42aaa70820cb337d5283299 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2244,7 +2244,7 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, struct bpf_nh_params *nh) { const struct ipv6hdr *ip6h = ipv6_hdr(skb); - struct net *net = dev_net(dev); + struct net *net = dev_net_rcu(dev); int err, ret = NET_XMIT_DROP; if (!nh) { @@ -2348,7 +2348,7 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, struct bpf_nh_params *nh) { const struct iphdr *ip4h = ip_hdr(skb); - struct net *net = dev_net(dev); + struct net *net = dev_net_rcu(dev); int err, ret = NET_XMIT_DROP; if (!nh) { @@ -2438,7 +2438,7 @@ BPF_CALL_3(bpf_clone_redirect, struct sk_buff *, skb, u32, ifindex, u64, flags) if (unlikely(flags & (~(BPF_F_INGRESS) | BPF_F_REDIRECT_INTERNAL))) return -EINVAL; - dev = dev_get_by_index_rcu(dev_net(skb->dev), ifindex); + dev = dev_get_by_index_rcu(dev_net_rcu(skb->dev), ifindex); if (unlikely(!dev)) return -EINVAL; @@ -2482,7 +2482,7 @@ static struct net_device *skb_get_peer_dev(struct net_device *dev) int skb_do_redirect(struct sk_buff *skb) { struct bpf_redirect_info *ri = bpf_net_ctx_get_ri(); - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); struct net_device *dev; u32 flags = ri->flags; @@ -2497,7 +2497,7 @@ int skb_do_redirect(struct sk_buff *skb) dev = skb_get_peer_dev(dev); if (unlikely(!dev || !(dev->flags & IFF_UP) || - net_eq(net, dev_net(dev)))) + net_eq(net, dev_net_rcu(dev)))) goto out_drop; skb->dev = dev; dev_sw_netstats_rx_add(dev, skb->len); @@ -4425,7 +4425,7 @@ __xdp_do_redirect_frame(struct bpf_redirect_info *ri, struct net_device *dev, break; case BPF_MAP_TYPE_UNSPEC: if (map_id == INT_MAX) { - fwd = dev_get_by_index_rcu(dev_net(dev), ri->tgt_index); + fwd = dev_get_by_index_rcu(dev_net_rcu(dev), ri->tgt_index); if (unlikely(!fwd)) { err = -EINVAL; break; @@ -4550,7 +4550,7 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb, ri->map_type = BPF_MAP_TYPE_UNSPEC; if (map_type == BPF_MAP_TYPE_UNSPEC && map_id == INT_MAX) { - fwd = dev_get_by_index_rcu(dev_net(dev), ri->tgt_index); + fwd = dev_get_by_index_rcu(dev_net_rcu(dev), ri->tgt_index); if (unlikely(!fwd)) { err = -EINVAL; goto err; @@ -6203,12 +6203,12 @@ BPF_CALL_4(bpf_xdp_fib_lookup, struct xdp_buff *, ctx, switch (params->family) { #if IS_ENABLED(CONFIG_INET) case AF_INET: - return bpf_ipv4_fib_lookup(dev_net(ctx->rxq->dev), params, + return bpf_ipv4_fib_lookup(dev_net_rcu(ctx->rxq->dev), params, flags, true); #endif #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: - return bpf_ipv6_fib_lookup(dev_net(ctx->rxq->dev), params, + return bpf_ipv6_fib_lookup(dev_net_rcu(ctx->rxq->dev), params, flags, true); #endif } @@ -6228,7 +6228,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = { BPF_CALL_4(bpf_skb_fib_lookup, struct sk_buff *, skb, struct bpf_fib_lookup *, params, int, plen, u32, flags) { - struct net *net = dev_net(skb->dev); + struct net *net = dev_net_rcu(skb->dev); int rc = -EAFNOSUPPORT; bool check_mtu = false; @@ -6283,7 +6283,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = { static struct net_device *__dev_via_ifindex(struct net_device *dev_curr, u32 ifindex) { - struct net *netns = dev_net(dev_curr); + struct net *netns = dev_net_rcu(dev_curr); /* Non-redirect use-cases can use ifindex=0 and save ifindex lookup */ if (ifindex == 0) @@ -6806,7 +6806,7 @@ bpf_skc_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, int ifindex; if (skb->dev) { - caller_net = dev_net(skb->dev); + caller_net = dev_net_rcu(skb->dev); ifindex = skb->dev->ifindex; } else { caller_net = sock_net(skb->sk); @@ -6906,7 +6906,7 @@ BPF_CALL_5(bpf_tc_skc_lookup_tcp, struct sk_buff *, skb, { struct net_device *dev = skb->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_skc_lookup(skb, tuple, len, caller_net, ifindex, IPPROTO_TCP, netns_id, @@ -6930,7 +6930,7 @@ BPF_CALL_5(bpf_tc_sk_lookup_tcp, struct sk_buff *, skb, { struct net_device *dev = skb->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_sk_lookup(skb, tuple, len, caller_net, ifindex, IPPROTO_TCP, netns_id, @@ -6954,7 +6954,7 @@ BPF_CALL_5(bpf_tc_sk_lookup_udp, struct sk_buff *, skb, { struct net_device *dev = skb->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_sk_lookup(skb, tuple, len, caller_net, ifindex, IPPROTO_UDP, netns_id, @@ -6992,7 +6992,7 @@ BPF_CALL_5(bpf_xdp_sk_lookup_udp, struct xdp_buff *, ctx, { struct net_device *dev = ctx->rxq->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_sk_lookup(NULL, tuple, len, caller_net, ifindex, IPPROTO_UDP, netns_id, @@ -7016,7 +7016,7 @@ BPF_CALL_5(bpf_xdp_skc_lookup_tcp, struct xdp_buff *, ctx, { struct net_device *dev = ctx->rxq->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_skc_lookup(NULL, tuple, len, caller_net, ifindex, IPPROTO_TCP, netns_id, @@ -7040,7 +7040,7 @@ BPF_CALL_5(bpf_xdp_sk_lookup_tcp, struct xdp_buff *, ctx, { struct net_device *dev = ctx->rxq->dev; int ifindex = dev->ifindex, sdif = dev_sdif(dev); - struct net *caller_net = dev_net(dev); + struct net *caller_net = dev_net_rcu(dev); return (unsigned long)__bpf_sk_lookup(NULL, tuple, len, caller_net, ifindex, IPPROTO_TCP, netns_id, @@ -7510,7 +7510,7 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags) return -EINVAL; if (!skb_at_tc_ingress(skb)) return -EOPNOTSUPP; - if (unlikely(dev_net(skb->dev) != sock_net(sk))) + if (unlikely(dev_net_rcu(skb->dev) != sock_net(sk))) return -ENETUNREACH; if (sk_unhashed(sk)) return -EOPNOTSUPP; @@ -11985,7 +11985,7 @@ __bpf_kfunc int bpf_sk_assign_tcp_reqsk(struct __sk_buff *s, struct sock *sk, if (!skb_at_tc_ingress(skb)) return -EINVAL; - net = dev_net(skb->dev); + net = dev_net_rcu(skb->dev); if (net != sock_net(sk)) return -ENETUNREACH; From patchwork Mon Feb 3 14:30:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957614 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 367CC21323B for ; Mon, 3 Feb 2025 14:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593072; cv=none; b=Egrhj19tgmJbb3h7qUbG6+/aFtPAcAATQiZV2TyVggcyf9Tf9cNT+GNUdHb8C0Spg81OcATm0Ph6Hd+eXkXs/4KHtPfPD+C/dKCvQpeMFNlJYiWE/hBrGb3bCxLi/8cv5rD4jdzlWhtrJ8oh8doD80rF4xdcMMt9f/pKr5vMKcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593072; c=relaxed/simple; bh=61JFgdUJmDeeiN7N16KSRF1ODvG6bk9e92yKxXiKpG4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eaC3baatUhgrZTmNzwPtNW4kJFwHEqrKTA+C3FEZKnd9yyI8WBGp83ATJ1Uh5my+Oh5ULweJzINhT1Y1zWq9oMQ/1CkIAYyX3FWekOOyF43FA5EghxCQjw5QaXRNleGMJ4R0VztrhDL59A7sQZYfx/xMY42NNiYslE3ElWZZF2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IYhukk/u; arc=none smtp.client-ip=209.85.219.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IYhukk/u" Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6d8f6b89dcdso80269776d6.3 for ; Mon, 03 Feb 2025 06:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593070; x=1739197870; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UBI7ETjPQaZc4LNnxDqzKU2PtlRuMJYL7UoYXTXXF3w=; b=IYhukk/uxvWdm/v0Srzn1bXkni6+uaVsQpr4m2Th25xFjBGEkxz7TLH6CKWHoYuoA5 86DlRxTZgZ/4Lpdfo3TguXR+a0Giv3IKs3bHVB4qoOPkRgDnDc2+If+U2C7XMy6xDAP5 MP1dru9imF3DzdwFxtREhWd9dnMwUeRo7cQkvJ6sZTEXZAktsPcSdidEUvrImZ0a2sMR L57tZFxFozHbu9DVjhnDeeV+4Ekwci+/Tj+iK3v314rji3YtswaF450XJ/roUR/i2ADC ZvFPg6syMZKWZwjXEt9ioceDSJrH/sgm9PwEtyxyBUcmHQYkth8U1iIKOQ1hvmcRlQuf nUjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593070; x=1739197870; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UBI7ETjPQaZc4LNnxDqzKU2PtlRuMJYL7UoYXTXXF3w=; b=FYbjBSsj4o0MPKUTpD92PhHiqsEENonh+wkYOb0OhMUeCf3OTBy/NYB4kKmYiCnBPt EMYPw5U0xdLsJtiH0AtZW/Ki9dJdeCUma1ldICYv2pDWAU/WCcqn0OvX6bJi5FIve7Kb xqpOIMAgQKnpRYDkkxUgppQfyoh1wlvOM3wzvMv39YAVmjrgqJb6pe7rADAXWQOxMr8X xmFdNHa4Hra9LMpe3DjCmgGqam9f2L25FOm3u/5qRIcJm0fRstO8eAcd6DHuH1Dx/QT5 UjZvrMlNKwr+K0/LRz3ZmDMn9gTNto3W4m3yun9NTnlYJJGGK76LDf3SMHFlHdFXa3Uv e+IA== X-Gm-Message-State: AOJu0Yy5fwCNVXHWG34S2LnSTRbrfhSc73n+0yGjEvLcLAY+YxlOOlH3 b3L7WAr7Lqh06B8EqLPaAOmBh+5CtdEkCKCkXc4GShxUuX94jbygH1wO6gt219Uoboz0yTK+eEk j+cepjlYs0Q== X-Google-Smtp-Source: AGHT+IEUnGr38fjvZMrnke5JrAC8BKwHX7rPMgt8yW2Fe9BtbLB+TM0v42IiAbEK+P1aaatpgjO2MaTJ/BrG/A== X-Received: from qvboh10.prod.google.com ([2002:a05:6214:438a:b0:6d4:16f0:f91f]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:4893:b0:6d8:9872:adc1 with SMTP id 6a1803df08f44-6e243c7bafemr346634596d6.38.1738593070023; Mon, 03 Feb 2025 06:31:10 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:45 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-16-edumazet@google.com> Subject: [PATCH v2 net 15/16] flow_dissector: use rcu protection to fetch dev_net() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org __skb_flow_dissect() can be called from arbitrary contexts. It must extend its rcu protection section to include the call to dev_net(), which can become dev_net_rcu(). This makes sure the net structure can not disappear under us. Fixes: 9b52e3f267a6 ("flow_dissector: handle no-skb use case")flow_dissect") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/core/flow_dissector.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 0e638a37aa0961de6281deeed227b3e7ef70e546..5db41bf2ed93e0df721c216ca4557dad16aa5f83 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1108,10 +1108,12 @@ bool __skb_flow_dissect(const struct net *net, FLOW_DISSECTOR_KEY_BASIC, target_container); + rcu_read_lock(); + if (skb) { if (!net) { if (skb->dev) - net = dev_net(skb->dev); + net = dev_net_rcu(skb->dev); else if (skb->sk) net = sock_net(skb->sk); } @@ -1122,7 +1124,6 @@ bool __skb_flow_dissect(const struct net *net, enum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR; struct bpf_prog_array *run_array; - rcu_read_lock(); run_array = rcu_dereference(init_net.bpf.run_array[type]); if (!run_array) run_array = rcu_dereference(net->bpf.run_array[type]); @@ -1150,17 +1151,17 @@ bool __skb_flow_dissect(const struct net *net, prog = READ_ONCE(run_array->items[0].prog); result = bpf_flow_dissect(prog, &ctx, n_proto, nhoff, hlen, flags); - if (result == BPF_FLOW_DISSECTOR_CONTINUE) - goto dissect_continue; - __skb_flow_bpf_to_target(&flow_keys, flow_dissector, - target_container); - rcu_read_unlock(); - return result == BPF_OK; + if (result != BPF_FLOW_DISSECTOR_CONTINUE) { + __skb_flow_bpf_to_target(&flow_keys, flow_dissector, + target_container); + rcu_read_unlock(); + return result == BPF_OK; + } } -dissect_continue: - rcu_read_unlock(); } + rcu_read_unlock(); + if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { struct ethhdr *eth = eth_hdr(skb); From patchwork Mon Feb 3 14:30:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13957615 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ua1-f74.google.com (mail-ua1-f74.google.com [209.85.222.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E677B21324E for ; Mon, 3 Feb 2025 14:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593074; cv=none; b=qwRb2s09Lyur3wo9UPHGQN/vl+RnPDPEUeHBgh+ZCg+CCQCrtARwCE/2DiGsaEHXnkH2L3eliDDMxvNBR4XsKBxKTXdX+MOfHe+2W21HeAc/aq7nojmPCSjjjJIVGA0N1uqxwIdRz4ywGUQFcp+q/Kl3OmxCLzJmkDc7GnxWJuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738593074; c=relaxed/simple; bh=IjoS0wZAHK91Jak8vmBaki/M3ogZdNysqnPdn+F/nUU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BB9qDdXIAKUgIaAJpd11oPcmZnsQyGGyfFD5Wf+uJ6OwdOQufHzGcrJAvhCWNtlJl8k8nlxgP5H3D4qLI+oEnadaRtsbDrU+mcNixv7970d5Uix7l1Y0NgQh797oJjjQt8WcL9OOPOO2KTuhdHPsthqs5DJ4YZuqt6zUK9GLuJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gQhOZsRU; arc=none smtp.client-ip=209.85.222.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gQhOZsRU" Received: by mail-ua1-f74.google.com with SMTP id a1e0cc1a2514c-8618bb82d64so3527455241.2 for ; Mon, 03 Feb 2025 06:31:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738593072; x=1739197872; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=W7cOpAiJ3jNVE76pwOVOdST2btjk2f5QzQeM6NMvd44=; b=gQhOZsRUQumfhnwn8CqZ0rAGRoKc7f8Xdb7XV+z2IIq7z7IpG5D4x7ATfjBZVb6ZUP Y8CaWkSgdzuMuCH4P9rcCjGIVPKzzBcQYKedK9r+5n1qpn0vQ6OdOMkkA1Uwhx6wOkNF HcLj2a0SyxyTfJGyOx5s37mBJDxxyeB6VNDdaNpx/+Eqe8pfKNhZ2bXbaC9w2n5NklX2 FK4DxWRd9fYhSp0vg92iXUzfw3YA3Ls5VOiNaaLmNUnR0wZZ1pK2lERLrMLEux25TnXe F/JQepAZ6WEd38DPkueJj27BnAQ85NJuUr4xMEmzkQ4M89OeYrLCPaAyM3uLKckswGkZ ky6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593072; x=1739197872; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W7cOpAiJ3jNVE76pwOVOdST2btjk2f5QzQeM6NMvd44=; b=qJ3ZYbp2cNV/YUGGI4/knbU9j8E0fcHQNpOZ8Ageufa4PYYdsaENhuhm/6QAAk0n9D aq19gIbtLkLFNJ/T6dH6MKgeA3A37YghBiJIVi3FCBXap+/mIm0qHRMUNECbPn0BLwel pvhPujwfiCUHMF9c1F318S4NGDJrTeDO/GVe4G4ctPgBlrvUMBlT6p/hYWdENDtz40Sk Vaq0kNdROd7+LuMVXKrct8d42tfnM+F7iAqJ1GEE3iQfnRG7Y6gD+HfE4SoBEK+0hrkm vz0XrB8+GcptRBw8MP/OCJ7Ka83ZINQXvxhBgyypurMY4thJd///TTViwZro66ejNf59 udbA== X-Gm-Message-State: AOJu0YzNZqhRYusOqF3Lc3pOHtHjFQfhDeGmwictx+FWJt/rZ2EQ6kLT No3A/VS7hdRTDMEcRyBjoRGzWqOzn39saXZNGmI9tAqTAtrsdezofMdkEmOXayuCvwyh1REYbvI EHjIoLzm9bw== X-Google-Smtp-Source: AGHT+IFFz3SCpMPRTODCQql3IkyG5Q3sc9i0uOkafAh/IYFDjBycQAls+X0GwOt+xnOG2FMzoXon51p3iAc0LQ== X-Received: from vsvj37.prod.google.com ([2002:a05:6102:3e25:b0:4b6:8e99:b5b8]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:2c03:b0:4af:de39:8daa with SMTP id ada2fe7eead31-4b9a4f27c13mr16417753137.4.1738593071820; Mon, 03 Feb 2025 06:31:11 -0800 (PST) Date: Mon, 3 Feb 2025 14:30:46 +0000 In-Reply-To: <20250203143046.3029343-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250203143046.3029343-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250203143046.3029343-17-edumazet@google.com> Subject: [PATCH v2 net 16/16] ipv4: use RCU protection in inet_select_addr() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Kuniyuki Iwashima , Simon Horman , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org inet_select_addr() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: c4544c724322 ("[NETNS]: Process inet_select_addr inside a namespace.") Signed-off-by: Eric Dumazet --- net/ipv4/devinet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index c8b3cf5fba4c02941b919687a6a657cf68f5f99a..55b8151759bc9f76ebdbfae27544d6ee666a4809 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1371,10 +1371,11 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) __be32 addr = 0; unsigned char localnet_scope = RT_SCOPE_HOST; struct in_device *in_dev; - struct net *net = dev_net(dev); + struct net *net; int master_idx; rcu_read_lock(); + net = dev_net_rcu(dev); in_dev = __in_dev_get_rcu(dev); if (!in_dev) goto no_in_dev;