netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp
@ 2015-10-30 12:33 Loganaden Velvindron
  2015-11-08 20:41 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Loganaden Velvindron @ 2015-10-30 12:33 UTC (permalink / raw)
  To: netfilter-devel

counterstmp is not cleared before it is used in get_counters(). it might be 
leaked partially when it is sent to userland later on.

Signed-off-by: Loganaden Velvindron <logan@elandsys.com>
---
 net/bridge/netfilter/ebtables.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index f46ca41..26922e9 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -989,7 +989,7 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
 	   the check on the size is done later, when we have the lock */
 	if (repl->num_counters) {
 		unsigned long size = repl->num_counters * sizeof(*counterstmp);
-		counterstmp = vmalloc(size);
+		counterstmp = vzalloc(size);
 		if (!counterstmp)
 			return -ENOMEM;
 	}
@@ -1410,7 +1410,7 @@ static int copy_counters_to_user(struct ebt_table *t,
 		return -EINVAL;
 	}
 
-	counterstmp = vmalloc(nentries * sizeof(*counterstmp));
+	counterstmp = vzalloc(nentries * sizeof(*counterstmp));
 	if (!counterstmp)
 		return -ENOMEM;
 
-- 
2.6.1

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

* Re: [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp
  2015-10-30 12:33 [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp Loganaden Velvindron
@ 2015-11-08 20:41 ` Pablo Neira Ayuso
  2015-11-08 20:52   ` Loganaden Velvindron
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2015-11-08 20:41 UTC (permalink / raw)
  To: Loganaden Velvindron; +Cc: netfilter-devel

On Fri, Oct 30, 2015 at 05:33:03AM -0700, Loganaden Velvindron wrote:
> counterstmp is not cleared before it is used in get_counters(). it might be 
> leaked partially when it is sent to userland later on.

get_counters() is memcpy'ing the old counter to the counterstmp area
and updating it.

Where is there leak?

> Signed-off-by: Loganaden Velvindron <logan@elandsys.com>
> ---
>  net/bridge/netfilter/ebtables.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
> index f46ca41..26922e9 100644
> --- a/net/bridge/netfilter/ebtables.c
> +++ b/net/bridge/netfilter/ebtables.c
> @@ -989,7 +989,7 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
>  	   the check on the size is done later, when we have the lock */
>  	if (repl->num_counters) {
>  		unsigned long size = repl->num_counters * sizeof(*counterstmp);
> -		counterstmp = vmalloc(size);
> +		counterstmp = vzalloc(size);
>  		if (!counterstmp)
>  			return -ENOMEM;
>  	}
> @@ -1410,7 +1410,7 @@ static int copy_counters_to_user(struct ebt_table *t,
>  		return -EINVAL;
>  	}
>  
> -	counterstmp = vmalloc(nentries * sizeof(*counterstmp));
> +	counterstmp = vzalloc(nentries * sizeof(*counterstmp));
>  	if (!counterstmp)
>  		return -ENOMEM;
>  
> -- 
> 2.6.1
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp
  2015-11-08 20:41 ` Pablo Neira Ayuso
@ 2015-11-08 20:52   ` Loganaden Velvindron
  2015-11-08 21:30     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Loganaden Velvindron @ 2015-11-08 20:52 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Loganaden Velvindron, netfilter-devel

On Sun, Nov 8, 2015 at 8:41 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Fri, Oct 30, 2015 at 05:33:03AM -0700, Loganaden Velvindron wrote:
>> counterstmp is not cleared before it is used in get_counters(). it might be
>> leaked partially when it is sent to userland later on.
>
> get_counters() is memcpy'ing the old counter to the counterstmp area
> and updating it.
>
> Where is there leak?
>

In this case, none, due to correct memcpy parameters in get_counters().

However, as this is exposed later on to userland through:

        if (copy_to_user(user, counterstmp,
           nentries * sizeof(struct ebt_counter)))

zero'ing counterstmp malloc'ed memory, looks like a good idea.

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

* Re: [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp
  2015-11-08 21:30     ` Pablo Neira Ayuso
@ 2015-11-08 21:26       ` Loganaden Velvindron
  0 siblings, 0 replies; 5+ messages in thread
From: Loganaden Velvindron @ 2015-11-08 21:26 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Loganaden Velvindron, netfilter-devel

On Sun, Nov 8, 2015 at 9:30 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Sun, Nov 08, 2015 at 08:52:50PM +0000, Loganaden Velvindron wrote:
>> On Sun, Nov 8, 2015 at 8:41 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>> > On Fri, Oct 30, 2015 at 05:33:03AM -0700, Loganaden Velvindron wrote:
>> >> counterstmp is not cleared before it is used in get_counters(). it might be
>> >> leaked partially when it is sent to userland later on.
>> >
>> > get_counters() is memcpy'ing the old counter to the counterstmp area
>> > and updating it.
>> >
>> > Where is there leak?
>> >
>>
>> In this case, none, due to correct memcpy parameters in get_counters().
>>
>> However, as this is exposed later on to userland through:
>>
>>         if (copy_to_user(user, counterstmp,
>>            nentries * sizeof(struct ebt_counter)))
>>
>> zero'ing counterstmp malloc'ed memory, looks like a good idea.
>
> We allocate room for nentries, then we get_counters() those nentries
> that memcpy that area, and we copy back to user nentries.
>
> Where is the problem?

None in this case.

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

* Re: [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp
  2015-11-08 20:52   ` Loganaden Velvindron
@ 2015-11-08 21:30     ` Pablo Neira Ayuso
  2015-11-08 21:26       ` Loganaden Velvindron
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2015-11-08 21:30 UTC (permalink / raw)
  To: Loganaden Velvindron; +Cc: Loganaden Velvindron, netfilter-devel

On Sun, Nov 08, 2015 at 08:52:50PM +0000, Loganaden Velvindron wrote:
> On Sun, Nov 8, 2015 at 8:41 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Fri, Oct 30, 2015 at 05:33:03AM -0700, Loganaden Velvindron wrote:
> >> counterstmp is not cleared before it is used in get_counters(). it might be
> >> leaked partially when it is sent to userland later on.
> >
> > get_counters() is memcpy'ing the old counter to the counterstmp area
> > and updating it.
> >
> > Where is there leak?
> >
> 
> In this case, none, due to correct memcpy parameters in get_counters().
> 
> However, as this is exposed later on to userland through:
> 
>         if (copy_to_user(user, counterstmp,
>            nentries * sizeof(struct ebt_counter)))
> 
> zero'ing counterstmp malloc'ed memory, looks like a good idea.

We allocate room for nentries, then we get_counters() those nentries
that memcpy that area, and we copy back to user nentries.

Where is the problem?

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

end of thread, other threads:[~2015-11-08 21:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-30 12:33 [PATCH 1/1 net-next] net: bridge: netfilter: use vzalloc() instead of vmalloc() for counterstmp Loganaden Velvindron
2015-11-08 20:41 ` Pablo Neira Ayuso
2015-11-08 20:52   ` Loganaden Velvindron
2015-11-08 21:30     ` Pablo Neira Ayuso
2015-11-08 21:26       ` Loganaden Velvindron

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