netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option()
@ 2020-02-24 18:55 Matteo Croce
  2020-02-24 19:11 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Matteo Croce @ 2020-02-24 18:55 UTC (permalink / raw)
  To: netfilter-devel, coreteam, netdev
  Cc: linux-kernel, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, Jakub Kicinski,
	Stephen Suryaputra

As in commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()")
and commit 3e72dfdf8227 ("ipv4: ensure rcu_read_lock() in cipso_v4_error()"),
__ip_options_compile() must be called under rcu protection.

Fixes: dbb5281a1f84 ("netfilter: nf_tables: add support for matching IPv4 options")
Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
 net/netfilter/nft_exthdr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
index a5e8469859e3..752264b3043a 100644
--- a/net/netfilter/nft_exthdr.c
+++ b/net/netfilter/nft_exthdr.c
@@ -77,6 +77,7 @@ static int ipv4_find_option(struct net *net, struct sk_buff *skb,
 	bool found = false;
 	__be32 info;
 	int optlen;
+	int ret;
 
 	iph = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
 	if (!iph)
@@ -95,7 +96,11 @@ static int ipv4_find_option(struct net *net, struct sk_buff *skb,
 		return -EBADMSG;
 	opt->optlen = optlen;
 
-	if (__ip_options_compile(net, opt, NULL, &info))
+	rcu_read_lock();
+	ret = __ip_options_compile(net, opt, NULL, &info);
+	rcu_read_unlock();
+
+	if (ret)
 		return -EBADMSG;
 
 	switch (target) {
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option()
  2020-02-24 18:55 [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option() Matteo Croce
@ 2020-02-24 19:11 ` Florian Westphal
  2020-02-24 19:42   ` Matteo Croce
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2020-02-24 19:11 UTC (permalink / raw)
  To: Matteo Croce
  Cc: netfilter-devel, coreteam, netdev, linux-kernel,
	Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Stephen Suryaputra

Matteo Croce <mcroce@redhat.com> wrote:
> As in commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()")
> and commit 3e72dfdf8227 ("ipv4: ensure rcu_read_lock() in cipso_v4_error()"),
> __ip_options_compile() must be called under rcu protection.

This is not needed, all netfilter hooks run with rcu_read_lock held.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option()
  2020-02-24 19:11 ` Florian Westphal
@ 2020-02-24 19:42   ` Matteo Croce
  2020-02-24 19:47     ` Matteo Croce
  0 siblings, 1 reply; 4+ messages in thread
From: Matteo Croce @ 2020-02-24 19:42 UTC (permalink / raw)
  To: Florian Westphal
  Cc: netfilter-devel, coreteam, netdev, LKML, Pablo Neira Ayuso,
	Jozsef Kadlecsik, David S. Miller, Jakub Kicinski,
	Stephen Suryaputra

On Mon, Feb 24, 2020 at 8:12 PM Florian Westphal <fw@strlen.de> wrote:
>
> Matteo Croce <mcroce@redhat.com> wrote:
> > As in commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()")
> > and commit 3e72dfdf8227 ("ipv4: ensure rcu_read_lock() in cipso_v4_error()"),
> > __ip_options_compile() must be called under rcu protection.
>
> This is not needed, all netfilter hooks run with rcu_read_lock held.
>

Ok, so let's drop it, thanks.

-- 
Matteo Croce
per aspera ad upstream


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option()
  2020-02-24 19:42   ` Matteo Croce
@ 2020-02-24 19:47     ` Matteo Croce
  0 siblings, 0 replies; 4+ messages in thread
From: Matteo Croce @ 2020-02-24 19:47 UTC (permalink / raw)
  To: Florian Westphal
  Cc: netfilter-devel, coreteam, netdev, LKML, Pablo Neira Ayuso,
	Jozsef Kadlecsik, David S. Miller, Jakub Kicinski,
	Stephen Suryaputra

On Mon, Feb 24, 2020 at 8:42 PM Matteo Croce <mcroce@redhat.com> wrote:
>
> On Mon, Feb 24, 2020 at 8:12 PM Florian Westphal <fw@strlen.de> wrote:
> >
> > Matteo Croce <mcroce@redhat.com> wrote:
> > > As in commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()")
> > > and commit 3e72dfdf8227 ("ipv4: ensure rcu_read_lock() in cipso_v4_error()"),
> > > __ip_options_compile() must be called under rcu protection.
> >
> > This is not needed, all netfilter hooks run with rcu_read_lock held.
> >
>
> Ok, so let's drop it, thanks.

What about adding a RCU_LOCKDEP_WARN() in __ip_options_compile() to
protect against future errors? Something like:

----------------------------------%<-------------------------------------
@@ -262,6 +262,9 @@ int __ip_options_compile(struct net *net,
  unsigned char *iph;
  int optlen, l;

+ RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
+ __FUNC__ " needs rcu_read_lock() protection");
+
  if (skb) {
  rt = skb_rtable(skb);
  optptr = (unsigned char *)&(ip_hdr(skb)[1]);
---------------------------------->%-------------------------------------

Bye,
-- 
Matteo Croce
per aspera ad upstream


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-24 19:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 18:55 [PATCH nf] netfilter: ensure rcu_read_lock() in ipv4_find_option() Matteo Croce
2020-02-24 19:11 ` Florian Westphal
2020-02-24 19:42   ` Matteo Croce
2020-02-24 19:47     ` Matteo Croce

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).