stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patch "netfilter: ensure number of counters is >0 in do_replace()" has been added to the 3.14-stable tree
@ 2016-06-23  4:47 gregkh
  2016-06-23 17:13 ` Dave Jones
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2016-06-23  4:47 UTC (permalink / raw)
  To: davej, gregkh, pablo; +Cc: stable, stable-commits


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

    netfilter: ensure number of counters is >0 in do_replace()

to the 3.14-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:
     netfilter-ensure-number-of-counters-is-0-in-do_replace.patch
and it can be found in the queue-3.14 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 1086bbe97a074844188c6c988fa0b1a98c3ccbb9 Mon Sep 17 00:00:00 2001
From: Dave Jones <davej@codemonkey.org.uk>
Date: Tue, 19 May 2015 20:55:17 -0400
Subject: netfilter: ensure number of counters is >0 in do_replace()

From: Dave Jones <davej@codemonkey.org.uk>

commit 1086bbe97a074844188c6c988fa0b1a98c3ccbb9 upstream.

After improving setsockopt() coverage in trinity, I started triggering
vmalloc failures pretty reliably from this code path:

warn_alloc_failed+0xe9/0x140
__vmalloc_node_range+0x1be/0x270
vzalloc+0x4b/0x50
__do_replace+0x52/0x260 [ip_tables]
do_ipt_set_ctl+0x15d/0x1d0 [ip_tables]
nf_setsockopt+0x65/0x90
ip_setsockopt+0x61/0xa0
raw_setsockopt+0x16/0x60
sock_common_setsockopt+0x14/0x20
SyS_setsockopt+0x71/0xd0

It turns out we don't validate that the num_counters field in the
struct we pass in from userspace is initialized.

The same problem also exists in ebtables, arptables, ipv6, and the
compat variants.

Signed-off-by: Dave Jones <davej@codemonkey.org.uk>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 net/bridge/netfilter/ebtables.c |    4 ++++
 net/ipv4/netfilter/arp_tables.c |    6 ++++++
 net/ipv4/netfilter/ip_tables.c  |    6 ++++++
 net/ipv6/netfilter/ip6_tables.c |    6 ++++++
 4 files changed, 22 insertions(+)

--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1105,6 +1105,8 @@ static int do_replace(struct net *net, c
 		return -ENOMEM;
 	if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
 
 	tmp.name[sizeof(tmp.name) - 1] = 0;
 
@@ -2150,6 +2152,8 @@ static int compat_copy_ebt_replace_from_
 		return -ENOMEM;
 	if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
 
 	memcpy(repl, &tmp, offsetof(struct ebt_replace, hook_entry));
 
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -1081,6 +1081,9 @@ static int do_replace(struct net *net, c
 	/* overflow check */
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);
@@ -1495,6 +1498,9 @@ static int compat_do_replace(struct net
 		return -ENOMEM;
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1267,6 +1267,9 @@ do_replace(struct net *net, const void _
 	/* overflow check */
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);
@@ -1802,6 +1805,9 @@ compat_do_replace(struct net *net, void
 		return -ENOMEM;
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1277,6 +1277,9 @@ do_replace(struct net *net, const void _
 	/* overflow check */
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);
@@ -1811,6 +1814,9 @@ compat_do_replace(struct net *net, void
 		return -ENOMEM;
 	if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
 		return -ENOMEM;
+	if (tmp.num_counters == 0)
+		return -EINVAL;
+
 	tmp.name[sizeof(tmp.name)-1] = 0;
 
 	newinfo = xt_alloc_table_info(tmp.size);


Patches currently in stable-queue which might be from davej@codemonkey.org.uk are

queue-3.14/netfilter-ensure-number-of-counters-is-0-in-do_replace.patch

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

* Re: Patch "netfilter: ensure number of counters is >0 in do_replace()" has been added to the 3.14-stable tree
  2016-06-23  4:47 Patch "netfilter: ensure number of counters is >0 in do_replace()" has been added to the 3.14-stable tree gregkh
@ 2016-06-23 17:13 ` Dave Jones
  2016-06-24  2:48   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jones @ 2016-06-23 17:13 UTC (permalink / raw)
  To: gregkh; +Cc: pablo, stable, stable-commits

On Wed, Jun 22, 2016 at 09:47:06PM -0700, gregkh@linuxfoundation.org wrote:
 > 
 > This is a note to let you know that I've just added the patch titled
 > 
 >     netfilter: ensure number of counters is >0 in do_replace()
 > 
 > to the 3.14-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:
 >      netfilter-ensure-number-of-counters-is-0-in-do_replace.patch
 > and it can be found in the queue-3.14 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.

Make sure you pick up d26e2c9ffa385dd1b646f43c1397ba12af9ed431 too, or ebtables will break.

	Dave


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

* Re: Patch "netfilter: ensure number of counters is >0 in do_replace()" has been added to the 3.14-stable tree
  2016-06-23 17:13 ` Dave Jones
@ 2016-06-24  2:48   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2016-06-24  2:48 UTC (permalink / raw)
  To: Dave Jones; +Cc: pablo, stable, stable-commits

On Thu, Jun 23, 2016 at 01:13:35PM -0400, Dave Jones wrote:
> On Wed, Jun 22, 2016 at 09:47:06PM -0700, gregkh@linuxfoundation.org wrote:
>  > 
>  > This is a note to let you know that I've just added the patch titled
>  > 
>  >     netfilter: ensure number of counters is >0 in do_replace()
>  > 
>  > to the 3.14-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:
>  >      netfilter-ensure-number-of-counters-is-0-in-do_replace.patch
>  > and it can be found in the queue-3.14 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.
> 
> Make sure you pick up d26e2c9ffa385dd1b646f43c1397ba12af9ed431 too, or ebtables will break.

Yes, now got it, thanks.

greg k-h

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

end of thread, other threads:[~2016-06-24  2:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-23  4:47 Patch "netfilter: ensure number of counters is >0 in do_replace()" has been added to the 3.14-stable tree gregkh
2016-06-23 17:13 ` Dave Jones
2016-06-24  2:48   ` Greg KH

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