From: Paolo Abeni <pabeni@redhat.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>,
Eric Dumazet <edumazet@google.com>,
Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: [RFC PATCH 02/11] net: allow early demux to fetch noref socket
Date: Fri, 22 Sep 2017 23:06:26 +0200 [thread overview]
Message-ID: <e899d1802d51e022e47e88cff37ffcd2bf7a36cc.1506114055.git.pabeni@redhat.com> (raw)
In-Reply-To: <cover.1506114055.git.pabeni@redhat.com>
We must be careful to avoid leaking such sockets outside
the RCU section containing the early demux call; we clear
them on nonlocal delivery.
For ipv4 we clear sknoref even for multicast traffic entering
the ip_mr_input() path; we will lose the mcast early demux
optimization when the host is acting as multicast router, but
that will help to keep to code simple.
Also update all iptables/nftables extension that can
happen in the input chain and can transmit the skb outside
such patch, namely TEE, nft_dup and nfqueue.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/ipv4/ip_input.c | 8 ++++++++
net/ipv4/netfilter/nf_dup_ipv4.c | 3 +++
net/ipv6/ip6_input.c | 4 ++++
net/ipv6/netfilter/nf_dup_ipv6.c | 3 +++
net/netfilter/nf_queue.c | 3 +++
5 files changed, 21 insertions(+)
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index fa2dc8f692c6..5690ef09da28 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -351,6 +351,14 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
}
}
+ /* Since the sk has no reference to the socket, we must
+ * clear it before escaping this RCU section.
+ * The sk is just an hint and we know we are not going to use
+ * it outside the input path.
+ */
+ if (skb_dst(skb)->input != ip_local_deliver)
+ skb_clear_noref_sk(skb);
+
#ifdef CONFIG_IP_ROUTE_CLASSID
if (unlikely(skb_dst(skb)->tclassid)) {
struct ip_rt_acct *st = this_cpu_ptr(ip_rt_acct);
diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index 39895b9ddeb9..bf8b78492fc8 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -71,6 +71,9 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
nf_reset(skb);
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
#endif
+ /* Avoid leaking noref sk outside the input path */
+ skb_clear_noref_sk(skb);
+
/*
* If we are in PREROUTING/INPUT, decrease the TTL to mitigate potential
* loops between two hosts.
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 9ee208a348f5..e15ec2d36b9e 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -68,6 +68,10 @@ int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
if (!skb_valid_dst(skb))
ip6_route_input(skb);
+ /* see comment on ipv4 edmux */
+ if (skb_dst(skb)->input != ip6_input)
+ skb_clear_noref_sk(skb);
+
return dst_input(skb);
}
diff --git a/net/ipv6/netfilter/nf_dup_ipv6.c b/net/ipv6/netfilter/nf_dup_ipv6.c
index 4a7ddeddbaab..939f6a2238f9 100644
--- a/net/ipv6/netfilter/nf_dup_ipv6.c
+++ b/net/ipv6/netfilter/nf_dup_ipv6.c
@@ -60,6 +60,9 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
nf_reset(skb);
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
#endif
+ /* Avoid leaking noref sk outside the input path */
+ skb_clear_noref_sk(skb);
+
if (hooknum == NF_INET_PRE_ROUTING ||
hooknum == NF_INET_LOCAL_IN) {
struct ipv6hdr *iph = ipv6_hdr(skb);
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
index f7e21953b1de..100eff08cb51 100644
--- a/net/netfilter/nf_queue.c
+++ b/net/netfilter/nf_queue.c
@@ -145,6 +145,9 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
.size = sizeof(*entry) + afinfo->route_key_size,
};
+ /* Avoid leaking noref sk outside the input path */
+ skb_clear_noref_sk(skb);
+
nf_queue_entry_get_refs(entry);
skb_dst_force(skb);
afinfo->saveroute(skb, entry);
--
2.13.5
next prev parent reply other threads:[~2017-09-22 21:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 21:06 [RFC PATCH 00/11] udp: full early demux for unconnected sockets Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 01/11] net: add support for noref skb->sk Paolo Abeni
2017-09-22 21:06 ` Paolo Abeni [this message]
2017-09-22 21:06 ` [RFC PATCH 03/11] udp: do not touch socket refcount in early demux Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 04/11] net: add simple socket-like dst cache helpers Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 05/11] udp: perform full socket lookup in early demux Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 06/11] ip/route: factor out helper for local route creation Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 07/11] ipv6/addrconf: add an helper for inet6 address lookup Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 08/11] net: implement local route cache inside ifaddr Paolo Abeni
2017-09-22 21:06 ` [RFC PATCH 09/11] route: add ipv4/6 helpers to do partial route lookup vs local dst Paolo Abeni
2017-09-22 21:58 ` [RFC PATCH 00/11] udp: full early demux for unconnected sockets Eric Dumazet
2017-09-25 20:26 ` Paolo Abeni
2017-09-26 20:18 ` [RFC PATCH 10/11] IP: early demux can return an error code Paolo Abeni
2017-09-26 20:18 ` [RFC PATCH 11/11] udp: dst lookup in early demux for unconnected sockets Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e899d1802d51e022e47e88cff37ffcd2bf7a36cc.1506114055.git.pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=hannes@stressinduktion.org \
--cc=netdev@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).