From patchwork Wed Feb 5 15:51:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961419 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 583D218A6D2 for ; Wed, 5 Feb 2025 15:51:24 +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=1738770685; cv=none; b=bWjYNnvXfYsAUmn3Uf0VpMCZeeCIGt2Enc/+7kWKJNBZIfR3iB760rMysD3ciWmqx0/bvCWuZx6EZTU4ejwfV16F+y0ELD8ejsFn8fhN5oWjrAUt87khpNoGZgMfl9e4psJ41DMJT55VtijiglczV7GTpALIuxbgmrAuJD0hVUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770685; c=relaxed/simple; bh=7jVWSrjoPsJTlYuJUx7Ve86JID2VuVx3RWFZAEwPwns=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MDCA3fr1aPmcVkxWgeqnv01ezIQMpe60FWLLqtGxgwm4bfiv/uWr1SrL8rhQ6GcpjrEyt8DWH0gFBCsbGrotZ2eu1Eb4yyntYn1icLm5/v1+vhS3SCDgiFXgA0R81IzEN1PYjpWgBdMR2fLpet+k4VogM3iNNljuGtPfA4vmLVk= 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=sJ/3AeTe; 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="sJ/3AeTe" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-467b0b0aed4so137448281cf.2 for ; Wed, 05 Feb 2025 07:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770683; x=1739375483; 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=YltdPh2DTLHaaVWal9d771nvesQr3cOmFN62LjAnwTE=; b=sJ/3AeTeiSCpOsYHJ4TgS6cXFYWtUQyqafb197XFSyT9xMCrJZdoeLw61xnASwOaRh gTmrmc0n4M03MyXTbtdwenYvia5VTLDO0OC902VAUVKW+s4C9mE5oan1rkIoXrMOvUbE Ce6YLKUJ/9fJ1kNb/uu+0fIo0YcUmmwoeH2vVlYH83/WQxG5a1jRtJKFz980RJzIbPrm IoBRZWH6fgUghqxZn2c2KcDS97pTI+UXm6LVxKpbPtT4bPYWuiYwdTfnqE7hmphNozY2 O7PjmaQzT5PvEYYXqQPSfcBM/J/uowrGlBvMWcxQITCu0o/688Y4cMUhIRG/X7Gyuf/L qBgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770683; x=1739375483; 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=YltdPh2DTLHaaVWal9d771nvesQr3cOmFN62LjAnwTE=; b=UvhYasHZzLoP4/kud0RAOCJSg+dT2MCsJ6B3Zxd4JQN93HL3PhKuUHikqgf8xCJYxa ZZbnUimXHREKDa7NswPjhmVywJBX9W2q1uFb7THZUQXKJ5WH6tWJX9UoDt+vgaYgTxrE c6SffhjrQgVrHgLVacivG1RBQJNU72hf89O7V+Kweifu/7CLT5mhpopiDm8lyCVxLqTO w285+nSmNgcT1G6ynSfapFuFc/Zdv7KJjOX2Lnn/OtPeFB+BSyobvMegZpogQEVOujrp ZCbMt/5QNZeG288bwCkpvfk8vrPg/Gwf7AH7A7XMcd5UFmaw2NDMp8N23JBI/P7m5daG 6HLQ== X-Gm-Message-State: AOJu0Yxc0y8hhx4g4v/GFEi5kpWvnzF2iZlfoq2ZuKHEgz/FB0ZZX39+ VKpZC7pfe2OzkfhmFasJhlPvJEDhytFivtqzIqzhqszQVwM1OdMuyQmdc5w33SRKUNmB328OJAa xwAiY4yl94A== X-Google-Smtp-Source: AGHT+IHm3fMPwnevcP+FLKeSdTZciLhxA2Tmq4nyN6eRB9TaEsQ9A3JEwOY6HaRYZ2cQCMfLdZbrVmsnJt/JqQ== X-Received: from qtbcr16.prod.google.com ([2002:a05:622a:4290:b0:466:928b:3b7c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:7fd3:0:b0:46d:d23c:99f5 with SMTP id d75a77b69052e-470282de21dmr46008701cf.33.1738770683242; Wed, 05 Feb 2025 07:51:23 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:09 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-2-edumazet@google.com> Subject: [PATCH v4 net 01/12] 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 03bb584c62cf8a920b12c673dcc438eb1cc41499..c0a86afb85daa2b50e26a1ca238707a24a1842ad 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 Wed Feb 5 15:51:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961420 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 C586B192598 for ; Wed, 5 Feb 2025 15:51:25 +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=1738770687; cv=none; b=bEDR03gTwjHroqbOoH0s9AhHzdzYbcYi0R5USIzlPVjNo2oloP9t3pX8waVRcxrmzklqg48nQYwn3Gai7Glxl5gA/c0quCjmkygnCqtA5cD/eZMdSHx22zOjvoYNliy/XI90ykLnMcuR6Dc73MJmRNG+11SVm9yRKY30T4jbe38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770687; c=relaxed/simple; bh=BjDBT6Ld/KkPV9e18e0rFMjRoUhNxwx0+3f23tk62VA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=etyNI42fOODdD1eB9b5SX4/f4S6klbL7TvdQD7bQbpQzxf4aBOovMgD8GhasFV9H/vvDPizgKJF/gg51kjlko7afg1/4z+xY9Y5Q7FopmXplnOuthRCJvy3d1tGgT/HKT9aro5F3iimlQR4Eyv9Nr+yhbq62AXIoTICl4H8nB7k= 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=VZqrekVH; 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="VZqrekVH" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7b6ecd22efbso217687285a.0 for ; Wed, 05 Feb 2025 07:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770684; x=1739375484; 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=VZqrekVHdvGvH1Vf9dv6emBB+8UEdNZy8+8aH3RMrmnIFqPPvT0n8kNDXN8N6FLO8t S7pc7MdwvTuSCeQDvR0JZxQGfoB6EtpGdE2J1Y4/KMWvQFLBbNrX4mDovA6akoWjkuYc OL9uybgVXE6aCZtw0NX27iDdBAEBiPT2p4cj2yCknxXgXmud+VWc18DS4i/eqdqzUUuH EFWzgoU4PAprrmP8qdcHdB7tz1QgkEmd2cICFt4IdGr/CKayHb0wUUz8uZpyltpKBpiA rnaKvz0gQk+kKi7GcEXtCRz3Etxn3QR3Ag8zM1PKZoRTvCTyQlZ+pdEbSLQTkPe+gjg6 zT4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770684; x=1739375484; 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=GDYb7sW9aP8/759Sm+3lmUAdG6Q1mXrOCUfclLVHeS8446OwTeaY2a88rN0wbew6cZ ozMdxW9bKfWMMeICO4U97dt4d4XM+8M42Pcfke/Tl9f8eo1JJPs5DCGSfSXg4BukrdSd 59KfsDMVo70PPrJq064HwXBaaFEVw86a6vEik0kkCMnYUIyYMvtNaVCOngOCQLwsvOLN W77VZz+zKX2cW9KusfhOBFVc1fPRvwrLOldqCuppNQzYrXWs852iDVBmf0ge/M5wHjRG VU+Rh59EsiptE71mS1mhymv7mmQbJJi4+aeJZKUwNaPG5hjkZ2jO41fb2gLT4gltZg5z tYIQ== X-Gm-Message-State: AOJu0YxiYVFBVtpn8tCd/Q7knRTIc+88rnBAnBcKzPQrJXbxJIiWHTwe a2BQ9vrwtn7gUfBVe00pZtHEnIApLgZCTj97LO4iJeZjGq7y0xiiYJS7p3QI5+WdsGTlSRimi1F EN2qguIpvPQ== X-Google-Smtp-Source: AGHT+IENwIwyNlm4WcVRoWMuKWAGEuHfcG1l9gl3G+Z8JY9plrBqcC3Eb4M9F4GZR4EkZQAzC3YYWXgsp/spaw== X-Received: from qknpz5.prod.google.com ([2002:a05:620a:6405:b0:7b6:d922:f129]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:19a8:b0:7b6:f278:fa9b with SMTP id af79cd13be357-7c039aa5e42mr562966985a.12.1738770684523; Wed, 05 Feb 2025 07:51:24 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:10 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-3-edumazet@google.com> Subject: [PATCH v4 net 02/12] 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 Wed Feb 5 15:51:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961421 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 E375C192D97 for ; Wed, 5 Feb 2025 15:51:26 +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=1738770688; cv=none; b=h98wUFZvgus2u2FdDPmriQzXVApCXQdaoD9rxY/TmthjKWD7/40wDl8Cz3JTP2aKnSx+mKDBwIHi57j9QiHSVckOIgNfLMCEtQ0wr93nu/BdBECDECMwX3t/ReVnvRgHHqbBOpdn8A19hfcZ+AclUy5m3hh78RVeNwjEg4UYiFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770688; c=relaxed/simple; bh=Tv9lP/iKol3DOwtqFgPyYFOYlq/ggjrKRjQnoathmaA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M6IHz8jvQvqgGCQtzvr5QdtwSTW2Zw71JaueOiFHKfUSwdEnfUhlmSBit9xTCdJ7VfFHnDCanPDjpDk+tO3mgWf7AI7875xkHTupqGpJW4ZDk3EQCRzDenJqmUkRSDNkLM0RDs1+AQ9L22LccV4FVhyQ4KaFQYigrSzDSwB1M+s= 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=OtiyYOKH; 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="OtiyYOKH" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-46792701b64so129335971cf.3 for ; Wed, 05 Feb 2025 07:51:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770686; x=1739375486; 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=OtiyYOKHSPSxHwTcmwtGVFxW3AzSSHLwm7BHG6r05wIEmFEOH4MFmhoWyf+8OjaXWD mVdylrXN6Npnuju0n/0G/eaDKW3jVNNRw8X4qN9iAQAPb9gOlIL60CfWcIP3b943HXED gNkmRlshHbac9JKo/gnhskw3Facx52dIy/rPQFUF5USs7D80cMplz+HZSv4fN0RVZHn3 5OzGP0OKHL4WhqfwXv4rEDX1TA0PCGiA3n39cErr2WxE+zv0RmggQBxV811chCP7kMzC Rf9PAIoIJk7h9s8MuK//0WKR84+7VUD/zbaKHwyfdcgPsEvDnBKCjggYIWK1uj0C7t/5 ZjTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770686; x=1739375486; 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=EZgK6yy0BVeb78QYdSrwdrZki8thms3TJJ1JrEm3Urz29twKwRYEe3Jru3GE5dlN2w I8uUXIZAtQ01vF5ummp9hAibOj4lCAI25Jg5s4fSMcaICbwplxcvJp0k2FQ6DUMvrRKW Sm/h5s6Q/TDMRNkGMhS7ZN7/9qCsDLxN4/I6kieMQuPKZlvD+2HC45R9U/hH4giez3Ur 0vH9GCEMJ05x1kIq2cfxJTdnX9e/eVaz9eQTfghLULjcYieg78RrgL7+mXNXgQa+u6DV xHEyxI63NgLzPCKAvWjzOWZ2TQDHf6QhvNNojldFNFcoAf8Psh7xMXQguJAqXC4FK/e6 RecQ== X-Gm-Message-State: AOJu0YwZCoVjHqM3oa/tbUbp1DL0/Jkdiox7pp0EOHYKDeukewoSfF5S 6RyueeDG3QaGxkEpiwQVfRaDM++WkLM6FgKnxR8e6nQNJB8WUBWuPp81wollg9xn4mcDY/YqPp8 sGSgx4bT1eQ== X-Google-Smtp-Source: AGHT+IFjyeiB4mPpQSboKcMqBTl9u1fzTXg5WA3OM8OoEXWq8wethkHISLWfjBSm771GQt6bAntHD7T5sMMPIg== X-Received: from qtbey18.prod.google.com ([2002:a05:622a:4c12:b0:467:6ece:2e03]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:5989:b0:46d:d8be:d2c1 with SMTP id d75a77b69052e-47028009d11mr45316421cf.0.1738770685859; Wed, 05 Feb 2025 07:51:25 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:11 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-4-edumazet@google.com> Subject: [PATCH v4 net 03/12] 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 Wed Feb 5 15:51:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961422 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 592051990B7 for ; Wed, 5 Feb 2025 15:51:27 +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=1738770689; cv=none; b=erMDvkzxVqZ3vIa90b1W1fCN78hy2AzO4xGAVV1Ud08lLG6IqEjRMC/6//KoZs7kFgt3qGfGmCoUVh9D/4nwViadlddLCWUWuPW+vvtvyi4pnXHu/XkSLjb+18UqgTb3oOdl5MkOP2YM4I7fmoVwCNWigYYARnC8v7XXtq46NoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770689; c=relaxed/simple; bh=H8JH/QPjFfGxbrJtRbDkCum9cREuE5YKVIPC//b1qCs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NfqpYY1QtHdgrhpUUx1VWyUXm6KsX0c+djPuHgVTCI9JRQXQT2xtS4sg2sGoSmoMuf8g7+hqDdHZUbVwkFnVuZGnFaUKH48gI0K2sZ+73nL1L852QEsGUxmkFUcFkoRG8Z0PoGSA1KhIAq7iBwG9Y3DpZc7N1yxGXQ+9I3m5Sxg= 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=QMjxGcj9; 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="QMjxGcj9" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6e42e3cb051so34681686d6.0 for ; Wed, 05 Feb 2025 07:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770687; x=1739375487; 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=QMjxGcj9tjQY49Q9wI4gGwaNbVLqo5wCMAmYjoPqBJpuTntYyvRQ7N5D0pYwDXS2Li ZfcXKMDIliCEP9Ps4Gzhnr/FZE7VNozQ025BklcsWafxVG3qtG8RVhTLSGMXrNdJRqkj n2ZgHyPQxyPYof4dTHyRbgfuqj0Tm1BC1+atOOTOl7TNzixd1mNEXZNx48KGLGf3qu5j 5iGmADe+pMuR/ZP69Ao3wz1xu3Kav5UK3l3fu6OLucciHbErkMl8al8MTq8qU8m4kabM ybvqYP7xTzfqe1Zr2nGwe+ZSJw2zeddeOivbhWRty8HRBkF3acdXs9UPZjyBe9q/cvH8 gToQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770687; x=1739375487; 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=SnyFk+3elcJ6gfTlubrX+nD5ymQT80R0SUjRt23nkn4uoe/VJD44oyz4w42puCP0LK t0ipiLIBVqc7BlC25aDetahUORQ7jYnJyUrbKiZqlxgko/u5TMW8tF9IA8SFioBGzXmB zSzdcG7Iyj5nD2En+EZOe3k6irRiccJt3dou59+Q9J4eQu2uZriaSidfbPTqOnrII/ev AeRZqi1rrWf5a3rD6g4EgyL5VeYQ9f6/BrrL+s+2peSGxZ/a6ktJTIl7nENG6J39rKTA xeWw0tWD7fGw8Fit7V95C59jMKY1OUXZJtGVd9MdQTWtLEgCynDNPivDW0I9+UHSiLZO 4MxQ== X-Gm-Message-State: AOJu0YwBK1q+Nc2JhLQtRPxMRED60XAsJZL/eplxHIlySmKz+wZkbywH ppcIGxFor97xJpLnV+KDw0MZe/4dZk2jLRLemiSn97p+KZ1qh+kL5K/smT7LziZs1Jg3SZ7LOHv olpeAfkJ37w== X-Google-Smtp-Source: AGHT+IEED/sXUFR8e5BcIPk0aFSPDj3FXn4V8c/ldayogRX7uDzKvpe0Hxl6B9psUVHWEAUTHY5p0BRxkYT+LQ== X-Received: from qknru10.prod.google.com ([2002:a05:620a:684a:b0:7bc:de89:fc31]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:43a6:b0:7b6:753b:9b5d with SMTP id af79cd13be357-7c03a036f63mr575155085a.36.1738770687191; Wed, 05 Feb 2025 07:51:27 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:12 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-5-edumazet@google.com> Subject: [PATCH v4 net 04/12] 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 Wed Feb 5 15:51:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961423 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 9C66219F121 for ; Wed, 5 Feb 2025 15:51:29 +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=1738770691; cv=none; b=Q+iBdWNQTSa47wmu8bAiQBfgdpdRNzfusF291g9g4JVW2ymk96D0fUPhbRtTaTupzVyUdSEXgjUERPmrjrKDnVodk0foCwOZigXC1847h80iSfIWwoGcyg8OucsbO+JSuATDI6DA7ndRJhdGlVnoBNsIQKXj6VAibl/w9I7efTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770691; c=relaxed/simple; bh=wBUlXxqCOHC5mb4l82j/huFvC/81SsSroryG3eWs92Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BKDHsqNRX39swuQ7xEjMFqRxwKIXiKMO7m0+5R//OsSYHoA5wtPIscvt7Rkq8L2dU+Vcp9znk8Yg6v0/e0eVC25gdECcg1ASbFxw67bt9Nze3kayC++oChfdpxlXNJuyE7Y6onPVJPdtFs1VYicscyoxfD5KpMIUU4yxDRtwznA= 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=Fx0TAyZg; 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="Fx0TAyZg" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6e43050c8d0so20876766d6.0 for ; Wed, 05 Feb 2025 07:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770688; x=1739375488; 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=H0DPhFcYIwCjlPd5Kix9DbDaw6MNxiwJUB+YXQT63GU=; b=Fx0TAyZgbmv3bbyLnREjHYCV21mOd2YUsKf47XyHCXW3BVNoLQfkmiKcLru0DYX04X TvJyeqc6FGQmRKfG0/HIfqIEU9jqiGf69401zhSG38G25jMAqvhDzT22OzbEi3GyYMwu 9nGlMy+9OK6IxTnjA7HPsDgYWGcsFflou1H3IiWiZQ6YcTL6dC6qTa/RG9js3YhxpaPB 5aO4msnJ0KW4gcSyh5078m8C/mvTRJPfKAIECS6EpYaO6V2MdwCwB91PrLSp773/1ORR tg88jixM+Atmj3aYzcMiiNGsQ9C5NogwV55b+iMVfUESsghHZLyCsFWn9YpNySkGXrFr VqIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770688; x=1739375488; 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=H0DPhFcYIwCjlPd5Kix9DbDaw6MNxiwJUB+YXQT63GU=; b=ek8p91bIQzywp6ziEPj0pGP5/N/JKQlakV6XdDw2XuWI//q0x0bYsms/eqGWSUIzNt vyU+42CzZZfj9MbUV7QM553F/+OQrDZZLJnjKOXCQQ8Qw9lZ5oHBwe06Fv9xcAeBe9de 58PKJnYgqmQNjuReFvfErWe8RdlFSQlYpBXnCuHmRLK57zpkSFIBNoRYQ/nrpe7KgQom M0XNoy8mb3WSixKohmTSY3b2z9ZF/vNtGhCffpi5qPmO6kTAluppyMN33fqOw4tM0eeo z93YMSg+22+wBe6fYF7uvikoDn9DHBHDv1T0PoVHbLRp2KIzCCiN3YdSM1SrRNuLr6/S wrjg== X-Gm-Message-State: AOJu0Yw+3FDyRTZkJBvmgeVFP+Z2M3BzsAIt6Res3AUTOOygLt9IMKFH /m6nQgXBw2paPWzWLe4Xxi7hMW5NwqO07ggp0PL5kWUqIp2n1Jq8JxlfMkuEoKjYpkp156vcgkz 5Bb6rY1PqxA== X-Google-Smtp-Source: AGHT+IE0+sLvaMrnxAg8/P8TmgBBh7jPDtZrtr0M41PhkgTXsLXjVDzxLnGlQE/xc2G0TNQgg1Ck2aomCZx5LQ== X-Received: from qvbnw3.prod.google.com ([2002:a05:6214:3a03:b0:6dd:d16:e8ab]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:5085:b0:6dd:d317:e0aa with SMTP id 6a1803df08f44-6e42fb0aa0fmr44982636d6.8.1738770688459; Wed, 05 Feb 2025 07:51:28 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:13 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-6-edumazet@google.com> Subject: [PATCH v4 net 05/12] 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. Fixes: e84f84f27647 ("netns: place rt_genid into struct net") 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 Wed Feb 5 15:51:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961424 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 9CB3C1A7AFD for ; Wed, 5 Feb 2025 15:51:30 +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=1738770692; cv=none; b=XWz2TRpAmbx7LJ/g3xFGswBM5vWwfGaopHH5igv5oZlXBwXQgUjvAfLUbxST2t2I3utTWAXR/j5e2u+rwG6eAsslt4ja0v7P4L78CJw0qxvqhcM4Jl/yldiSY0do91tgOt1kA6bDO7lCmtsDsIK0cb/i75orIJlI10GP6zbgkPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770692; 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=Z2lb/M6Se88U0hCeRnDp0kdhlUNs8AVGywlOTFR7hz61BxfMGOP+ztrHEbYcZ79mB0rR3pys1qWawJrG8lxQqjOfTsf7PHa3UvRGqYnA9geOqkR6qRk+VIeuPcRgf4vAJKsSbSqCjt8fZqHEt1tMyBthv2BFcQgmlVnH6bMZY3s= 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=ztKPalBJ; 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="ztKPalBJ" Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6e4244f9de8so44159946d6.1 for ; Wed, 05 Feb 2025 07:51:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770690; x=1739375490; 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=ztKPalBJ5gyfRJ5jqNXFMBVmJkllMec9mpJ0PwvAGzHhsz3h5/g339x5m7ARB4Qf/L CS3spk/AnkPIgStDm0o6mm+eY8TwK9jZcuBANRfThRG6QOiSFFIxmroVRjN6SssYJvJ7 A59xG/R7Rw12FhMRZTqJ528yvxjnzl2pKWP1yRUsofUAhPOrO5t+JTNM/kXtUWyKKX23 BJ9Cby/B64hTE4E60Ufel6HIae7CzrHlTll1EDPfT/Pakdgqvb9dATx/khcY0+Pk9S8y HMucd5phFDcSgZ/kqmCAKSNfX4NJGjWz6hUxpvVBm8I54CoHH2rQSxWc9W8MFRKUQqwx 12Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770690; x=1739375490; 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=jLDXJWa5iM3mjrk/IzswZ2atSLaDko2lckr3fJluNAHoRJ4yqXTEV4C9+dcKkOcvIa 9gQU3JXZOgrCqJNIuHm9SBbY6GAaEk8K7K54MlAtlYAaPjTscwea1swPnOe9jMrDpelA 5fd5pNHdfGIR9EjEcdMnor/uLT/9Mqxvw3UOLEt2Hn+CyJi/TeI3SwbnbmjCc53LzqFv Xe2r3nDRARzWJ4e5Yb/+mvbkJnaw3CVVun01wSZ4wya1kLQM3B9/1Retx0w8PvMV5m/P Q4vG4goMQASATvsdpkxwhCS/5HZf+WE/kk3BPvUdGG3Ec228btQHSo3guThUq5vtiXjk c+Pg== X-Gm-Message-State: AOJu0YzJQUeJgsvHKmXthvw44DffGu9U2EE4fXL1jVKqacUDJacuMKSn diNUd3/lYj2SqBm9QIH/lxYgW0FWMmFYbCycFmdtLtoJrrtjuVGC2M10bry+AKx3qJkN79OLAD4 ytUwtUUI6WA== X-Google-Smtp-Source: AGHT+IEnHVCGbyVE46EL2MLk+lE/S3ZwV7TvsyZSKm0+Mnf454fsTzdIJlkZu3o7HbyJzUDkYvXjuSoRhzgJbg== X-Received: from qvbof6.prod.google.com ([2002:a05:6214:4346:b0:6e4:3725:e7a0]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ad4:5ec6:0:b0:6d8:8cb0:b40d with SMTP id 6a1803df08f44-6e42fc70219mr42473856d6.39.1738770689824; Wed, 05 Feb 2025 07:51:29 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:14 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-7-edumazet@google.com> Subject: [PATCH v4 net 06/12] 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; From patchwork Wed Feb 5 15:51:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961425 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-vk1-f201.google.com (mail-vk1-f201.google.com [209.85.221.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 5B1781D86C6 for ; Wed, 5 Feb 2025 15:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770693; cv=none; b=U3ASKSAnAl/Sf9azXNsnKg0WpYq1Ztxjw9fSEm1+zRFjB147Wp6jjKR0F9BuBYJnBOD/kpNC/92mK2IAgIKtf+tOknHq08rglrM75SDPsO8a6YyzI0kfLa9Oib3dWcrI5McsNsAsdkcMrwyHepP+c69iefpOkwaTI+2F3vfgFCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770693; c=relaxed/simple; bh=lloKHtDl/tPsHuM5V2tqfCv3EJggBESTK/ainZtC6ZM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MiyFG6g81Ux8H8X58/J8QodzycLPhpur+WS3y/cPB82c4ZhEodDbP7wTkPItE8wjPTNeneP71oBfEubKz8F2hQOxFP4BhbhKUr68RJfgaIV+NSnlN+DUDevZ0BEg1uRRzyCL59oi98NpHpgNbrgPbFjNA/A22ukzRnn5d+9+2fk= 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=1/Q4FOLS; arc=none smtp.client-ip=209.85.221.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="1/Q4FOLS" Received: by mail-vk1-f201.google.com with SMTP id 71dfb90a1353d-5174d5ad373so1460610e0c.1 for ; Wed, 05 Feb 2025 07:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770691; x=1739375491; 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=S+6z75ZBLIdNGYoGaeip7gqrPtogtnUcuG9JIWxEt9s=; b=1/Q4FOLSEKteFftbEtbGypI3feXVfcjIIA2ZRb3B8EcTHkrTIAbCiqUctVRdD2Flxf eGYNl6Acuxaqj22VJVNCXbCv0MH8WIZl0fSpZMmfzBW8Vhb8LbCv7SLEszsnic7CVxAA D/REw17mJYHHcPaExGIBSQz8ZgEwEFah3TgjXqUJ/P0ZVtI34+Ek2q6DjK9ses7V3kTC 1eBE9HCHCHOY+tI9uZer+VeFgpwoq2UPTj05yqdwCJ5URIh9e4VEGnUsQNKJXEJynAUF EroUxOEiGPxec1Olj+OHSvKfMs0z9Mu1qVijHWLu/QczjgdOInabnMdMrCEr/FRD6Qoh kG3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770691; x=1739375491; 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=S+6z75ZBLIdNGYoGaeip7gqrPtogtnUcuG9JIWxEt9s=; b=jXluaZrXSdERnmKJlcppiY7cXyoRj8/EDKXfeHpHlVcnzUG3v6KHIpOEsyWQcBcAZ4 Myujin7E6ZpA083+tlpUJ+jER80mPIwqzErDcy1m/P5sds9b32AkGfblPWzjkvwHPkEJ WwuDxPNNpg2Bq8Y3vIvqdoApvQYCQxqGZQeqIyEZFwJhiqYTC57FF0wM9qVkrTE5CrD6 HrKjU1IDakW7aKMRJnnHdnq1sgvfd2x/cgJXcO6Ew9bCGeawQyR4G9x7vl3IroBRs0vC TQ5tAi+LIIKfpQiH8tkCbVNEb70e2WL6gXOVcKzw6/OUD1hCWlcXYhrncgls9pQOdQJx /nqw== X-Gm-Message-State: AOJu0YwmjQWgl2J9/rOUZcZF5ZNxLjDU+1yFeZjFI4YXP4K/33pK6WcE bLewSI4canXxp2zXAUOMzNamJ4pw+05B+xwZBk313lLaxxhQijwdNsl7SnZyUsnqV7Ha0Sb54x9 rgHaF14cB4A== X-Google-Smtp-Source: AGHT+IHx8b7c5rUKa2+cCXQnilAczzNxas3R2E8mhxf9yJ0O+bnvNXQtWOTUN8pUAE9VLywW12m2eHC37zC7rA== X-Received: from vsbdd1.prod.google.com ([2002:a05:6102:5681:b0:4b6:3e49:b1b3]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:2c11:b0:4b4:e5c6:4c66 with SMTP id ada2fe7eead31-4ba478b45c5mr2335037137.6.1738770691220; Wed, 05 Feb 2025 07:51:31 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:15 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-8-edumazet@google.com> Subject: [PATCH v4 net 07/12] ipv4: use RCU protection in __ip_rt_update_pmtu() 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_rt_update_pmtu() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: 2fbc6e89b2f1 ("ipv4: Update exception handling for multipath routes via same device") Fixes: 1de6b15a434c ("Namespaceify min_pmtu sysctl") Signed-off-by: Eric Dumazet --- net/ipv4/route.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index e959327c0ba8979ce5c7ca8c46ae41068824edc6..753704f75b2c65d79c9c4dc19a329de5cdbd8514 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1008,9 +1008,9 @@ out: kfree_skb_reason(skb, reason); static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) { struct dst_entry *dst = &rt->dst; - struct net *net = dev_net(dst->dev); struct fib_result res; bool lock = false; + struct net *net; u32 old_mtu; if (ip_mtu_locked(dst)) @@ -1020,6 +1020,8 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) if (old_mtu < mtu) return; + rcu_read_lock(); + net = dev_net_rcu(dst->dev); if (mtu < net->ipv4.ip_rt_min_pmtu) { lock = true; mtu = min(old_mtu, net->ipv4.ip_rt_min_pmtu); @@ -1027,9 +1029,8 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) if (rt->rt_pmtu == mtu && !lock && time_before(jiffies, dst->expires - net->ipv4.ip_rt_mtu_expires / 2)) - return; + goto out; - rcu_read_lock(); if (fib_lookup(net, fl4, &res, 0) == 0) { struct fib_nh_common *nhc; @@ -1043,14 +1044,14 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock, jiffies + net->ipv4.ip_rt_mtu_expires); } - rcu_read_unlock(); - return; + goto out; } #endif /* CONFIG_IP_ROUTE_MULTIPATH */ nhc = FIB_RES_NHC(res); update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock, jiffies + net->ipv4.ip_rt_mtu_expires); } +out: rcu_read_unlock(); } From patchwork Wed Feb 5 15:51:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961426 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 886ED190676 for ; Wed, 5 Feb 2025 15:51:33 +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=1738770695; cv=none; b=gVrWxmL8lwjzJWiHecIztAJnFURLqcJJlnK1+6a8fUZhvgSwQ8VtreqVFcH6FEwjfXXa4GlySe6Er++mYPRIZogOkokx9ExyBhgi4AmQhLdLCE7WJuVdX2fZNh08GdBg+HK0X3nT5kK4aQUtQqeMsMUm5ciTwN0/w98+pOFGAYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770695; c=relaxed/simple; bh=vDaWHHNgn1bWEPl0PRv7zsig9RoElCDHRaoQj0cC/Q4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qWw7MrMupmjPIFm2ZzopGJU+20YMLwN9t3AMIOOr76kyRdSJS+kk1z43KnJc2l1NtmpfK4MIodOAANddShAY9X7MUKe0RHbOxa/HpSjBDbQXsq4JC6rDVP8Xu8zM6y3WQrj60Bgo2UCiuZXqggfR31pItQ+XesWC3Df/cA46gt8= 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=DHgh+gzj; 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="DHgh+gzj" Received: by mail-qv1-f73.google.com with SMTP id 6a1803df08f44-6e4237b6cf0so31525696d6.1 for ; Wed, 05 Feb 2025 07:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770692; x=1739375492; 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=e3VvVkXoQOBpW0WsqT7kuoRLQqr+20O8tQ41NFxntCc=; b=DHgh+gzjDKuRrXgaCkqgiXsCE4pFob/v3I6RYqhFoYI/ztXQwSOn4N8hP89R1fEHl6 pHb1xatAoU3lEsARZXCnqIOLSJSxi+RYkx+D5ITSP/hFfChBsI6KvSx+NajfqmnVQH13 WyL2qmJrcffUmpCSFW4jn4GMA4xQPdUpeiI+YcWlMJkY9NGsZ1P5PNknOo9XbI4+6zyN 68YEphXgOFeN0bp5oXYww7wj0ssGEcMrM+jXRAMN26pf0/jRI9Zjsa32NzOZaGFM4h5e u3NK8Rz9emkdXbUC944hfC/1xzkAMaMhRkBHDSvkHjlR+VDucbJa8Zjp6keh8jCAoo8u EEqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770692; x=1739375492; 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=e3VvVkXoQOBpW0WsqT7kuoRLQqr+20O8tQ41NFxntCc=; b=pH8fmoPk4PT0YoWJKrsUQKdrGn5rYWrK//QhQtYYcb71fnG1qeF8xXdVsUbLSGNEet XW2SI1butsRTYRmRiYy/SsuIsFkQEDl/EPl9yNiIF/JKAYKNp5YIsD5Lm7QE8Al2PDXB Dk3pTUrs3pZUL4MJqTzASR8k6Ten3m7yD3lCpEwp48d5S3jcVtFc5zn9KYJcMgHYIdg4 ESIchTdjhZYakvimM8aRR5cLYXrkNexcSULeG3K4Z8g6lqbkt+2eIBDglFnhgJG1M9wN VPeux2ohHer3IV4PQckytbvkj9/NtOJJdWknVWRGiVcb3Ilu7YYgG8c+ZmR3SdLgBZQJ 5I0A== X-Gm-Message-State: AOJu0Yx2lONvRRGbUVeJYuabzBLlDb45E4cuVgGJE0zDUMWYqREuD246 fip7y9hRC4jOm3IwjaiD0wD/6+Rpksj8m+Oer+BZzIfeY5P0RKWZgER70FP78Rd2xNZRaZXsBYh 4VkYWkIVg0Q== X-Google-Smtp-Source: AGHT+IHATkkvPF0N+tQw8EXYeZKAAC9VFQszl64ErivYrZfBroKVNJXooLDN3Sb/ARgvXROqk/Hl+qKKqcaMeg== X-Received: from qvblh5.prod.google.com ([2002:a05:6214:54c5:b0:6e4:1e22:3bc1]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:598e:b0:6e2:383f:4ad2 with SMTP id 6a1803df08f44-6e42fbc6ccamr47736696d6.15.1738770692322; Wed, 05 Feb 2025 07:51:32 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:16 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-9-edumazet@google.com> Subject: [PATCH v4 net 08/12] 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_send() must ensure rcu_read_lock() is held, as spotted by Jakub. Other ICMP uses of dev_net() seem safe, change them to dev_net_rcu() to get LOCKDEP support. Fixes: dde1bc0e6f86 ("[NETNS]: Add namespace for ICMP replying code.") Closes: https://lore.kernel.org/netdev/20250203153633.46ce0337@kernel.org/ Reported-by: Jakub Kicinski Signed-off-by: Eric Dumazet --- net/ipv4/icmp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 094084b61bff8a17c4e85c99019b84e9cba21599..5482edb5aade2bc25a39d75ab16feba476bb08ac 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -399,10 +399,10 @@ static void icmp_push_reply(struct sock *sk, 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 ipcm_cookie ipc; struct flowi4 fl4; struct sock *sk; struct inet_sock *inet; @@ -608,12 +608,14 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, struct sock *sk; if (!rt) - goto out; + return; + + rcu_read_lock(); 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; @@ -785,7 +787,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, icmp_xmit_unlock(sk); out_bh_enable: local_bh_enable(); -out:; +out: + rcu_read_unlock(); } EXPORT_SYMBOL(__icmp_send); @@ -834,7 +837,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 +871,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 +982,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 +1014,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 +1043,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 +1184,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 +1201,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 +1374,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 Wed Feb 5 15:51:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961427 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 ECE9A18FDDB for ; Wed, 5 Feb 2025 15:51:34 +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=1738770696; cv=none; b=TKfwiem5bugMcSTfmWa4JJd3sf1aSq9bEzRMPLVGZXJJv3R47Fu+SoclpFE1X4LUSRXT0P6BH+fj5YWclf7VwUbneneq8f/TNgQ6b71agjEJjf0vTLXKXeADUNvxm1W0iSbSAv70Fqj60bu9oVrGGRbPP3CSEL1NZoKXm279amI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770696; c=relaxed/simple; bh=Xc8ff5ueAC8bLQ/pO9eiqyPVl+q6SognJLrujsKU+d4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QeNWZTAPAPgv38+WYiz1pMjYMjfVDgunAi9h6mJqHnLLHcwwrbntNtS2tieXzgJs371RxNfK/8CNC/eVfJUCsU9Vznsap1yPmEv4vLu2fhYPap3ygvHRL3J/5jU7EbDS4GXNCIBOo9xnYeSeeHQFO7LDW4yC3ASOx/WwRbZH6QQ= 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=008YTxKZ; 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="008YTxKZ" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4679aeb21e6so113415321cf.0 for ; Wed, 05 Feb 2025 07:51:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770693; x=1739375493; 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=kIxXoaa9w3rNZaVQW+3hpdC1hH2TURbw45AnZmrH++Y=; b=008YTxKZ6yeKKea7LLsAfeP/WAHThw0CIt41MhkI25678NU12O2dTj/bm2rPk1yyHh msKwm9AM70WahshgflvQbEPTE27EWYEbeuXSmzILk9dDLtxkaT+iVuLIpbY4Iq1QH6F+ 2o2pQxNxhQ6dhU1QeZswap2Khb8OpCPvhVxwKwrJ/Z8ttPhzw2tht9mYGXMxS+COiu6b 0Aev93FdB0AoFJbBMxDGof5YKMprYj0jzXExR4N9D60vGZjMP2caKsX0Iux2vn2RENsB 1zHLUuO+QncTl+HtIhcfX/BqWn2ENy7KXsRFNmpAVNSyKw5qhq1HrrUVTiJMv+d/+3xf 1LbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770694; x=1739375494; 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=kIxXoaa9w3rNZaVQW+3hpdC1hH2TURbw45AnZmrH++Y=; b=ebszkAyN7udgonrc08x2Huvi5MtYzsuvtVv46NCLbBaxTh8a5gIt7XAasRDP5mmTR3 D/TIYbhf0gEYadEK09h3C9RZkIfkQh7sRs8wJ/6O0zxrNd12kGSNRec/adY5RYtuzbL2 l2C0+LCwrphDX+rwFkLamZcrBiyHDRSOEt/BAjI7qppXlcvCzU6l0oTFlGU2shQWyMym WwuYhwjlJssBpJoxioQl1WG0Op8cbrOkkEIRcQWdThgFbAxacHwWHNLzt0KoyuI8sWq7 itmjA30X36C4o8Uz1buB6pGJw5Y0RjbE+eagDlQIYU+WrZCro38xA+L2iY/CsTp5TEe/ fYCg== X-Gm-Message-State: AOJu0YwG6NxCXh4r70OrHI6vCwul/cMDivnvyBJy5dobslc4NLL6Ql3X 1KNiIwjdCQTBGpxIH8hwzRojQd0KU6Qx00iLYlTHbF8TdvgeuHzg22m15ecAFPyVD/mWG7PDsIi b25QXVi6j6Q== X-Google-Smtp-Source: AGHT+IEGaHN+W+Q/8Nzoe8mWsOMS3YbZPpeCQ6gFrx0eWkOMT7eZBVee7HUjNo+BZmXdGx4Wq+y8u2GUZElI/g== X-Received: from qtbhj10.prod.google.com ([2002:a05:622a:620a:b0:46f:c959:9b05]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:5989:b0:46d:d8be:d2c1 with SMTP id d75a77b69052e-47028009d11mr45322631cf.0.1738770693739; Wed, 05 Feb 2025 07:51:33 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:17 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-10-edumazet@google.com> Subject: [PATCH v4 net 09/12] 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") 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 Wed Feb 5 15:51:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961428 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 3BD8C1DB127 for ; Wed, 5 Feb 2025 15:51:36 +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=1738770697; cv=none; b=TXVjJ4cuCPRYx9aSuT9qUySyMpuo/1HfUPr0oiIWO3f0i6VzUzyvl2kC9oX24E7duq2xIjxMMGd+JwzGXKabTpxI1YNQ8M/LPooyRkNPkF6Gm6CH+Dd2AP/NJ6KSlVh9sbGdmegY8EFxwjabwA7hX70sZaDiDiq7gW/ub7vHi1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770697; c=relaxed/simple; bh=u+DZYCZ71qEmcoaM8BqYeimI8o1k+MxdZFJa9VQVe5c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TKZFJl+83I0KmyEWoZWUk0Zs3c4HZNTHfzPNroEMCkFbuqr02MlepzhpFZE8EoKIqhZmFgBdV+pbX5AbCAoxTZcAD+pzymHkAPXPTBoU26ZhKaslkfimMhrmKQN9SbU5fdSQrYyD0SxTx5cvSeAN9wq4eOWv/oI6KoIjC2RXeFk= 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=SxwHKbOW; 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="SxwHKbOW" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-46dd301a429so143134601cf.1 for ; Wed, 05 Feb 2025 07:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770695; x=1739375495; 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=xkUZ2e8rWS1eur8t+u5qtaW84WZ8tA0iHVb0xvGzMSA=; b=SxwHKbOW+JAnbtQ6D5t4AIV4ufQGCIDpYATiwx6S2OIWBGYdkIiFw/PRcTByZOfntn gIcluCx1Q5xX2DFxCCYbZKRw6k6NvzT5BjnTUaLdW2rN7ApcloV134Z57OBUfqDNTkzu N3V0O8fKZiPsgbr1p25NWSYcWQ03+buHQKo7aoI6ww1yMAiTiMbbl9MhOfywhB0+6B4d vWwB3zmSGEDSSQKOFk9nXVygrKORqR1K5t51J4jB2zjWNa2pXsTg3rVA8V1wmzqTudYR ldIJ/LY5SwpbARWEaFvGY8i24suX/cAKLdkqz/eMP+8U110mHF9xy44Mfnqeo+wNliRu uZsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770695; x=1739375495; 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=xkUZ2e8rWS1eur8t+u5qtaW84WZ8tA0iHVb0xvGzMSA=; b=HUOF4kFAZSWfcCrgUIt7+o0yrmNOYoFaLCT3ElhhNiZ+5q2N0f2xhFoZRb+Jssfu8t Fk4fgWPZmauCj9CzdqPLp6rduPjRGxFrxmtsNaNq923s+CRiJR7VikNXOsF6W2Uafldo NCrqBHM9xdCaKMU1iF+koFw5BO26rZ2kFZfQ9Nn5vareIuuVatthUDQ25rECeH1P3TZd 7/8A/Ggfq5+OazyH0/crT6lo+vTvXWpaqawnok993DDAMuevc0bC5goXEQDS8SZOgRNQ Rt2Oz7/M3JvlSIoj4pebX2Q5dwvldL5rWLMXV28MOIDlGUUxkx03xuuqc7GhxiYX+5wF vHZg== X-Gm-Message-State: AOJu0YzEAbsqMxYIhMZG7IsAXxjQQX78K7+iTxv5A0pyBiKOMv4UQL47 z6mHD5CKIhsT0dnZ43p7oiZFgTvoFkrEjblpO2VDRa8Ejc6hpCZ/AfnPkaf+Ri5oeI1ZkNZBB7O sdR2kHg+tZg== X-Google-Smtp-Source: AGHT+IFLKxDzKfAGHl5zrgXfoiIZb4rgaIU3svpbMHUsdpbH6OVCRB58g8yp07a4Toi4vlR9iv0vBT+noLXN0w== X-Received: from qtbeo9.prod.google.com ([2002:a05:622a:5449:b0:467:5293:b05f]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:5fcc:0:b0:46e:4de6:8a06 with SMTP id d75a77b69052e-470282df32dmr38040241cf.52.1738770695183; Wed, 05 Feb 2025 07:51:35 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:18 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-11-edumazet@google.com> Subject: [PATCH v4 net 10/12] 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. Fixes: 5578689a4e3c ("[NETNS][IPV6] route6 - make route6 per namespace") 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 Wed Feb 5 15:51:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961429 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 ECBA51DC19D for ; Wed, 5 Feb 2025 15:51:37 +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=1738770699; cv=none; b=MHV7SSQ/azLLMpyKG9FDICsR+TJ97wIKOLLISCdUIzuBomAuL+eDMZCPasrgTqPJKVW7LEuqNnNN6PFPoRn+tFSuz2kqHtwSGK5n5vJMHkBQsXSVP2eqOZSmHPOYPj+4iiFP+kWkhLOTaCVsxtsCrPeIisysRxDl3bWPZRiRPTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770699; c=relaxed/simple; bh=U2kX53Sg+dT2QzomNtvGlbWRO8/OdC8wBUIn0TCpjBM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q50fwEmaI9ECJaXH8uNPbdklFNhtqwfD1eezGm4yCi25QBQK2DpiDd3oHh5mfy+s3VW+27GxkvJGJ7wkXPb+RRrJ52qmM+ztI6G0FmyiZ2QqdlwzFZLxtpqTOJbM3TEW+uPcaybTWIE76C5FRHJ7UvIM2TbtdG8I8v41oJxL0q8= 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=dggopWDv; 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="dggopWDv" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4678f97242fso187496991cf.0 for ; Wed, 05 Feb 2025 07:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770697; x=1739375497; 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=zszYcJFJYdWef4gkJGhQ49R4MBi7sue+kr7ORa+aE30=; b=dggopWDvJ6aKcLDGfz/L0GNRI2rj/i34lbzn6XxQpXITcZKmkPJsI28y8UZkB/xn9Y kD6DwnSsdT7Vlx4ilNPkmrMLhAB0AXu5PI4JhSXuPy99vQNl//PN9zkqBwo7ShxTx50t zio95mqorwUfsjJRqq4LH+JhQmbFCbTvzuwUJ/O/Gn6mqg6Rkl7c9nDwFKBni1mST3uD SWk1GVwUXnxRtRQRkCG7ivUKJPBtohos9TUQk1V/Vjlq415JTzoWwPO8KVY2qlCguJPb FX/ycDrdeBBP+XlGdvEvyIh4cJh1nglByvt9rlRT3v43BoIAOWy4Wg7ZEv7f5lgP3yys thUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770697; x=1739375497; 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=zszYcJFJYdWef4gkJGhQ49R4MBi7sue+kr7ORa+aE30=; b=VerxPGAoPXll4jUqdaVeSGUXOQvSFh5isHlhfH+91MJCb25bu8s5E59HFAA24oKE3D rgSLWYSyNPts5N7cMNrOZosS0+w1WQLi98BY3eirEVLUaI2aYCvGisQ4HtTXqCtCBOpU YKSioZoyC1Jpmtpk9LNaqCB0MInLAqE5yyLcjVgAcWg41RNRrSbOrv3YVYGEWrckjWGo uGLpJm4IpgqI1I971ShN2WxIzioTU8oNX0dFmQDc0JfD8bjkSHUxy/pmet4qow7WN0so ht4VL56w0N8FuJqzBsP7JqRtVn0NS89wRySbnFXlLCz6kf7I4cL5rXJ7c8yo9sinppRi zXKQ== X-Gm-Message-State: AOJu0YzLbrgTA2pZfmiAToT2PL2z+FYolc3n9arXJeLritA/V0HXTQoK JQAigiLn+FgHDeu8YD3yy0XpUANAcBvfqYwkJY62p17P5s7HmyK6ol4f5tLBUk5hXX8umiKfERe P1PJilF7qkg== X-Google-Smtp-Source: AGHT+IGbd/+oJHM6TirW7H5yPo35H5mReONoHPz0xWqgOw08EugnYp3zZdq9/dUohYYdS081sq4BevKwlCi3wA== X-Received: from qtbbq13.prod.google.com ([2002:a05:622a:1c0d:b0:46b:1ac5:905c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:156:b0:461:5571:5cc6 with SMTP id d75a77b69052e-470282d6974mr45310731cf.46.1738770696990; Wed, 05 Feb 2025 07:51:36 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:19 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-12-edumazet@google.com> Subject: [PATCH v4 net 11/12] 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 icmp6_send() must acquire rcu_read_lock() sooner to ensure the dev_net() call done from a safe context. Other ICMPv6 uses of dev_net() seem safe, change them to dev_net_rcu() to get LOCKDEP support to catch bugs. Fixes: 9a43b709a230 ("[NETNS][IPV6] icmp6 - make icmpv6_socket per namespace") Signed-off-by: Eric Dumazet --- net/ipv6/icmp.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index a6984a29fdb9dd972a11ca9f8d5e794c443bac6f..4d14ab7f7e99f152cd5f5adaa023f0280957f275 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,10 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, if (!skb->dev) return; - net = dev_net(skb->dev); + + rcu_read_lock(); + + net = dev_net_rcu(skb->dev); mark = IP6_REPLY_MARK(net, skb->mark); /* * Make sure we respect the rules @@ -496,7 +499,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, !(type == ICMPV6_PARAMPROB && code == ICMPV6_UNK_OPTION && (opt_unrec(skb, info)))) - return; + goto out; saddr = NULL; } @@ -526,7 +529,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, if ((addr_type == IPV6_ADDR_ANY) || (addr_type & IPV6_ADDR_MULTICAST)) { net_dbg_ratelimited("icmp6_send: addr_any/mcast source [%pI6c > %pI6c]\n", &hdr->saddr, &hdr->daddr); - return; + goto out; } /* @@ -535,7 +538,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, if (is_ineligible(skb)) { net_dbg_ratelimited("icmp6_send: no reply to icmp error [%pI6c > %pI6c]\n", &hdr->saddr, &hdr->daddr); - return; + goto out; } /* Needed by both icmpv6_global_allow and icmpv6_xmit_lock */ @@ -582,7 +585,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, np = inet6_sk(sk); if (!icmpv6_xrlim_allow(sk, type, &fl6, apply_ratelimit)) - goto out; + goto out_unlock; tmp_hdr.icmp6_type = type; tmp_hdr.icmp6_code = code; @@ -600,7 +603,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, dst = icmpv6_route_lookup(net, skb, sk, &fl6); if (IS_ERR(dst)) - goto out; + goto out_unlock; ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst); @@ -616,7 +619,6 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, goto out_dst_release; } - rcu_read_lock(); idev = __in6_dev_get(skb->dev); if (ip6_append_data(sk, icmpv6_getfrag, &msg, @@ -630,13 +632,15 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr, len + sizeof(struct icmp6hdr)); } - rcu_read_unlock(); + out_dst_release: dst_release(dst); -out: +out_unlock: icmpv6_xmit_unlock(sk); out_bh_enable: local_bh_enable(); +out: + rcu_read_unlock(); } EXPORT_SYMBOL(icmp6_send); @@ -679,8 +683,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 +721,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 +836,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 +893,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 +925,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 +943,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 +1038,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 Wed Feb 5 15:51:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13961430 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 B283D1DB127 for ; Wed, 5 Feb 2025 15:51:39 +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=1738770701; cv=none; b=JvCIA9yRT5v1upgDkFyBVUy4+3zeDA/HXAU37jkA9C73Pt1slNNElbGFQ14N+LLt3B2Kmx0hcHbgBDtk0WgszEAr/BVxCsvXIi5/RUHHWVFCHcTb8DHsx5IdlR//4sNqtWHqv6nEoJESz/imbaP6H8EC5cTxOC6nBVJ+sXZdx+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738770701; c=relaxed/simple; bh=23btmb5/UGDMEubSQ5Azq+B7dPv8F6BoOi2IZq4hR/I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=e6YLOq5cLKuAVOb3oFvaS4aMejxqNpZ/l5yCFbs0m9RGS1OL5dsqPaDSXmAN2UZBCkyNi2DpJ2i8HDG97JZrxRJag5Te62tfCujBd50maAWGaz5B6bfFGkx5KkJbHEQDx9MgBBkQfCXeE3T0dezFAHa1Zc/5ZwNYz2BbShPur6E= 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=T0T2HoXs; 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="T0T2HoXs" Received: by mail-ua1-f74.google.com with SMTP id a1e0cc1a2514c-866d5db2621so290538241.1 for ; Wed, 05 Feb 2025 07:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738770698; x=1739375498; 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=GZPHU7iJV+gVRf/1/qTDUGCBeN90sukc7iRL0L2hF0Y=; b=T0T2HoXssK8hPXipIavCYuUQLpgnubfg9iNzdAOorbmCB+RWy07O8IvCW8zM7/JV+b SsDDgRpyLjcnnhUtc+JCSpMRUZh1HZ3l9hmHt4AC+e7yyr3bSv13C2v2a29EMhn/1Hr8 I+2P97BMb4qcq5C9YTM2JMO0K6pEfoHFq15jA6BAE2SZ+mAFWcHbek4x+XpxpCVriVXA HLeE/ZrbvdHT2mz1y8iLOmng0IJ3WKLwTyC1SCZ5fEHtIIhuPBsL0KH8EjuDg9zbRZpj 1AnF1Rjyfgl1kL4uSoXsPtTig3rVkCWLdy7apPu3RGGdkCmqnJUlYIzJvpbk1VfKK+ov Xz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738770698; x=1739375498; 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=GZPHU7iJV+gVRf/1/qTDUGCBeN90sukc7iRL0L2hF0Y=; b=R8JGGEobKFWt5q6Kwjfq9gay3L81GAUZzigj3FYnOPjqiEdSfqzajffh+k+a1MWRLV pv68Mb33y3EOa+jb3VuaeP9o4tCYLY6mDwWG0jOgE899RImgz8tdcEDUGfmSkN2nQzbk LwQ7iEI7Z5xUDfrn55dTdvONI53ayoP1lLey8GGcasb8kCVL6OtuXzui6fzF1JeQNdAf Su90Ar/ggHWfphWtCyc+T9w0px8P2RDznIb3/hvHwmQzVhL/nJ/C7xLiRsC/CYbLQTNQ aBisSHuONuOtxBneHr7cFGUFiyMsAzvxsHfNteSy0QH1P4F1WajB1sx5bZKXL7gi6KiY hD7A== X-Gm-Message-State: AOJu0YxY1RHqSBOHSsjFB4yNSQYDDJkwIiaz9k3kggYTtenj4a79NLFd JS1M/LAls4nVthk4DhO89kD8KQCBCKdEbY4nKOh41tC8I1wqf5nfdq+SP/RAcjczi2f0p8hDJsj fBwNSsdWggw== X-Google-Smtp-Source: AGHT+IHvy0h/7LxWaCeK6GtBpxkhBAwSQUDHtuvyezO0K+qKUFvpONGgjVslW6dvfYq31p5QCjfjwFAXut099Q== X-Received: from vsvj15.prod.google.com ([2002:a05:6102:3e0f:b0:4af:e21c:a8f3]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:508a:b0:4b4:3a28:6491 with SMTP id ada2fe7eead31-4ba47b1655bmr2101454137.25.1738770698629; Wed, 05 Feb 2025 07:51:38 -0800 (PST) Date: Wed, 5 Feb 2025 15:51:20 +0000 In-Reply-To: <20250205155120.1676781-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250205155120.1676781-1-edumazet@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250205155120.1676781-13-edumazet@google.com> Subject: [PATCH v4 net 12/12] ipv6: Use RCU in ip6_input() 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 Instead of grabbing rcu_read_lock() from ip6_input_finish(), do it earlier in is caller, so that ip6_input() access to dev_net() can be validated by LOCKDEP. Signed-off-by: Eric Dumazet --- net/ipv6/ip6_input.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 70c0e16c0ae6837d1c64d0036829c8b61799578b..39da6a7ce5f1245145dd74d4ac4eae63dd970939 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -477,9 +477,7 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { skb_clear_delivery_time(skb); - rcu_read_lock(); ip6_protocol_deliver_rcu(net, skb, 0, false); - rcu_read_unlock(); return 0; } @@ -487,9 +485,15 @@ 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, - ip6_input_finish); + int res; + + rcu_read_lock(); + res = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_IN, + dev_net_rcu(skb->dev), NULL, skb, skb->dev, NULL, + ip6_input_finish); + rcu_read_unlock(); + + return res; } EXPORT_SYMBOL_GPL(ip6_input);