All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix handling of verdicts after NF_QUEUE
@ 2017-12-11 23:30 Debabrata Banerjee
  2017-12-12  0:23 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Debabrata Banerjee @ 2017-12-11 23:30 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: David S . Miller, netfilter-devel, coreteam, netdev, stable,
	dbanerje

A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
and a potential kernel panic via double free of skb's

This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
use switch() to handle verdict cases from nf_hook_slow()"). However that
commit cannot be cleanly cherry-picked to v4.9

Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>

---

This fix is only needed for v4.9 stable since v4.10+ does not have the
issue
---
 net/netfilter/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 004af030ef1a..d869ea50623e 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
 		ret = nf_queue(skb, state, &entry, verdict);
 		if (ret == 1 && entry)
 			goto next_hook;
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
 	}
 	return ret;
 }
-- 
2.15.1

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

* Re: [PATCH] Fix handling of verdicts after NF_QUEUE
  2017-12-11 23:30 [PATCH] Fix handling of verdicts after NF_QUEUE Debabrata Banerjee
@ 2017-12-12  0:23 ` Pablo Neira Ayuso
  2017-12-12  0:36   ` Banerjee, Debabrata
  0 siblings, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-12  0:23 UTC (permalink / raw)
  To: Debabrata Banerjee
  Cc: David S . Miller, netfilter-devel, coreteam, netdev, stable

Hi,

Thanks for catching up this, see below.

On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
> A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
> and a potential kernel panic via double free of skb's
> 
> This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
> and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
> use switch() to handle verdict cases from nf_hook_slow()"). However that
> commit cannot be cleanly cherry-picked to v4.9
> 
> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
> 
> ---
> 
> This fix is only needed for v4.9 stable since v4.10+ does not have the
> issue
> ---
>  net/netfilter/core.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/netfilter/core.c b/net/netfilter/core.c
> index 004af030ef1a..d869ea50623e 100644
> --- a/net/netfilter/core.c
> +++ b/net/netfilter/core.c
> @@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
>  		ret = nf_queue(skb, state, &entry, verdict);
>  		if (ret == 1 && entry)
>  			goto next_hook;
> +	} else {
> +		/* Implicit handling for NF_STOLEN, as well as any other
> +		 * non conventional verdicts.
> +		 */
> +		ret = 0;

Another possibility (more simple?) would be this:

int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
{
        struct nf_hook_entry *entry;
        unsigned int verdict;
-       int ret = 0;
+       int ret;

        entry = rcu_dereference(state->hook_entries);
next_hook:
+       ret = 0;

Basically, make sure ret is set to zero when jumping to the next_hook
label.

Thanks!

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

* RE: [PATCH] Fix handling of verdicts after NF_QUEUE
  2017-12-12  0:23 ` Pablo Neira Ayuso
@ 2017-12-12  0:36   ` Banerjee, Debabrata
  2017-12-12 22:42     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Banerjee, Debabrata @ 2017-12-12  0:36 UTC (permalink / raw)
  To: 'Pablo Neira Ayuso'
  Cc: David S . Miller, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, netdev@vger.kernel.org,
	stable@vger.kernel.org

> From: Pablo Neira Ayuso [mailto:pablo@netfilter.org]
> On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
> > +	} else {
> > +		/* Implicit handling for NF_STOLEN, as well as any other
> > +		 * non conventional verdicts.
> > +		 */
> > +		ret = 0;
> 
> Another possibility (more simple?) would be this:
> 
> int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) {
>         struct nf_hook_entry *entry;
>         unsigned int verdict;
> -       int ret = 0;
> +       int ret;
> 
>         entry = rcu_dereference(state->hook_entries);
> next_hook:
> +       ret = 0;
> 
> Basically, make sure ret is set to zero when jumping to the next_hook label.

Many ways to fix it, but I thought including the comment was appropriate.
Happy to change it if we want simpler instead.

-Deb

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

* Re: [PATCH] Fix handling of verdicts after NF_QUEUE
  2017-12-12  0:36   ` Banerjee, Debabrata
@ 2017-12-12 22:42     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-12 22:42 UTC (permalink / raw)
  To: Banerjee, Debabrata
  Cc: David S . Miller, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, netdev@vger.kernel.org,
	stable@vger.kernel.org

On Tue, Dec 12, 2017 at 12:36:35AM +0000, Banerjee, Debabrata wrote:
> > From: Pablo Neira Ayuso [mailto:pablo@netfilter.org]
> > On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
> > > +	} else {
> > > +		/* Implicit handling for NF_STOLEN, as well as any other
> > > +		 * non conventional verdicts.
> > > +		 */
> > > +		ret = 0;
> > 
> > Another possibility (more simple?) would be this:
> > 
> > int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) {
> >         struct nf_hook_entry *entry;
> >         unsigned int verdict;
> > -       int ret = 0;
> > +       int ret;
> > 
> >         entry = rcu_dereference(state->hook_entries);
> > next_hook:
> > +       ret = 0;
> > 
> > Basically, make sure ret is set to zero when jumping to the next_hook label.
> 
> Many ways to fix it, but I thought including the comment was appropriate.
> Happy to change it if we want simpler instead.

OK, let's take this one.

Please, send a patch in git-format-patch, that we can pass to -stable.

Cc netfilter-devel@vger.kernel.org and stable@vger.kernel.org should
be fine, you can also include gregkh@linuxfoundation.org since he
maintains 4.9-stable.

I'll ack this by when you send it.

Thanks!

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

* [PATCH] Fix handling of verdicts after NF_QUEUE
@ 2017-12-13 20:33 Debabrata Banerjee
  2017-12-14 12:30 ` Pablo Neira Ayuso
  2017-12-14 17:43 ` Patch "Fix handling of verdicts after NF_QUEUE" has been added to the 4.9-stable tree gregkh
  0 siblings, 2 replies; 8+ messages in thread
From: Debabrata Banerjee @ 2017-12-13 20:33 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Greg Kroah-Hartman, David S . Miller, netfilter-devel, coreteam,
	netdev, stable, dbanerje

A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
and a potential kernel panic via double free of skb's

This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
use switch() to handle verdict cases from nf_hook_slow()"). However that
commit cannot be cleanly cherry-picked to v4.9

Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>

---

This fix is only needed for v4.9 stable since v4.10+ does not have the
issue
---
 net/netfilter/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 004af030ef1a..d869ea50623e 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
 		ret = nf_queue(skb, state, &entry, verdict);
 		if (ret == 1 && entry)
 			goto next_hook;
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
 	}
 	return ret;
 }
-- 
2.15.1

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

* Re: [PATCH] Fix handling of verdicts after NF_QUEUE
  2017-12-13 20:33 [PATCH] Fix handling of verdicts after NF_QUEUE Debabrata Banerjee
@ 2017-12-14 12:30 ` Pablo Neira Ayuso
  2017-12-14 17:39   ` Greg Kroah-Hartman
  2017-12-14 17:43 ` Patch "Fix handling of verdicts after NF_QUEUE" has been added to the 4.9-stable tree gregkh
  1 sibling, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-14 12:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Debabrata Banerjee, David S . Miller, netfilter-devel, coreteam,
	netdev, stable

Hi Greg,

I'd appreciate if you can take this patch into 4.9-stable. There is no
similar patch in tree, so this is not a backport.

On Wed, Dec 13, 2017 at 03:33:37PM -0500, Debabrata Banerjee wrote:
> A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
> and a potential kernel panic via double free of skb's
> 
> This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
> and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
> use switch() to handle verdict cases from nf_hook_slow()"). However that
> commit cannot be cleanly cherry-picked to v4.9
> 
> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Thanks a lot!

> ---
> 
> This fix is only needed for v4.9 stable since v4.10+ does not have the
> issue
> ---
>  net/netfilter/core.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/netfilter/core.c b/net/netfilter/core.c
> index 004af030ef1a..d869ea50623e 100644
> --- a/net/netfilter/core.c
> +++ b/net/netfilter/core.c
> @@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
>  		ret = nf_queue(skb, state, &entry, verdict);
>  		if (ret == 1 && entry)
>  			goto next_hook;
> +	} else {
> +		/* Implicit handling for NF_STOLEN, as well as any other
> +		 * non conventional verdicts.
> +		 */
> +		ret = 0;
>  	}
>  	return ret;
>  }
> -- 
> 2.15.1
> 

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

* Re: [PATCH] Fix handling of verdicts after NF_QUEUE
  2017-12-14 12:30 ` Pablo Neira Ayuso
@ 2017-12-14 17:39   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2017-12-14 17:39 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Debabrata Banerjee, David S . Miller, netfilter-devel, coreteam,
	netdev, stable

On Thu, Dec 14, 2017 at 01:30:08PM +0100, Pablo Neira Ayuso wrote:
> Hi Greg,
> 
> I'd appreciate if you can take this patch into 4.9-stable. There is no
> similar patch in tree, so this is not a backport.
> 
> On Wed, Dec 13, 2017 at 03:33:37PM -0500, Debabrata Banerjee wrote:
> > A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
> > and a potential kernel panic via double free of skb's
> > 
> > This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
> > and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
> > use switch() to handle verdict cases from nf_hook_slow()"). However that
> > commit cannot be cleanly cherry-picked to v4.9
> > 
> > Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
> 
> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> Thanks a lot!

Now applied, thanks.

greg k-h

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

* Patch "Fix handling of verdicts after NF_QUEUE" has been added to the 4.9-stable tree
  2017-12-13 20:33 [PATCH] Fix handling of verdicts after NF_QUEUE Debabrata Banerjee
  2017-12-14 12:30 ` Pablo Neira Ayuso
@ 2017-12-14 17:43 ` gregkh
  1 sibling, 0 replies; 8+ messages in thread
From: gregkh @ 2017-12-14 17:43 UTC (permalink / raw)
  To: dbanerje, davem, gregkh, pablo; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    Fix handling of verdicts after NF_QUEUE

to the 4.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     fix-handling-of-verdicts-after-nf_queue.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From dbanerje@akamai.com  Thu Dec 14 18:38:57 2017
From: Debabrata Banerjee <dbanerje@akamai.com>
Date: Wed, 13 Dec 2017 15:33:37 -0500
Subject: Fix handling of verdicts after NF_QUEUE
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "David S . Miller" <davem@davemloft.net>, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, stable@vger.kernel.org, dbanerje@akamai.com
Message-ID: <20171213203337.314-1-dbanerje@akamai.com>

From: Debabrata Banerjee <dbanerje@akamai.com>

[This fix is only needed for v4.9 stable since v4.10+ does not have the issue]

A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
and a potential kernel panic via double free of skb's

This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
use switch() to handle verdict cases from nf_hook_slow()"). However that
commit cannot be cleanly cherry-picked to v4.9

Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

---
 net/netfilter/core.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -364,6 +364,11 @@ next_hook:
 		ret = nf_queue(skb, state, &entry, verdict);
 		if (ret == 1 && entry)
 			goto next_hook;
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
 	}
 	return ret;
 }


Patches currently in stable-queue which might be from dbanerje@akamai.com are

queue-4.9/fix-handling-of-verdicts-after-nf_queue.patch

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

end of thread, other threads:[~2017-12-14 17:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13 20:33 [PATCH] Fix handling of verdicts after NF_QUEUE Debabrata Banerjee
2017-12-14 12:30 ` Pablo Neira Ayuso
2017-12-14 17:39   ` Greg Kroah-Hartman
2017-12-14 17:43 ` Patch "Fix handling of verdicts after NF_QUEUE" has been added to the 4.9-stable tree gregkh
  -- strict thread matches above, loose matches on Subject: below --
2017-12-11 23:30 [PATCH] Fix handling of verdicts after NF_QUEUE Debabrata Banerjee
2017-12-12  0:23 ` Pablo Neira Ayuso
2017-12-12  0:36   ` Banerjee, Debabrata
2017-12-12 22:42     ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.