Re: [PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-06-02 Thread David Miller
From: Leon Yu 
Date: Sun,  1 Jun 2014 05:37:25 +

> __sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
> rework/optimize internal BPF interpreter's instruction set) so that it should
> have uncharged memory once things went wrong. However that work isn't 
> complete.
> Error is handled only in __sk_migrate_filter() while memory can still leak in
> the error path right after sk_chk_filter().
> 
> Signed-off-by: Leon Yu 

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-06-02 Thread David Miller
From: Leon Yu chianglun...@gmail.com
Date: Sun,  1 Jun 2014 05:37:25 +

 __sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
 rework/optimize internal BPF interpreter's instruction set) so that it should
 have uncharged memory once things went wrong. However that work isn't 
 complete.
 Error is handled only in __sk_migrate_filter() while memory can still leak in
 the error path right after sk_chk_filter().
 
 Signed-off-by: Leon Yu chianglun...@gmail.com

Applied, thanks.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-06-01 Thread Alexei Starovoitov
On Sat, May 31, 2014 at 10:37 PM, Leon Yu  wrote:
> __sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
> rework/optimize internal BPF interpreter's instruction set) so that it should
> have uncharged memory once things went wrong. However that work isn't 
> complete.
> Error is handled only in __sk_migrate_filter() while memory can still leak in
> the error path right after sk_chk_filter().
>
> Signed-off-by: Leon Yu 

Nice catch. Thanks!
kmemleak confirmed the leak.

Acked-by: Alexei Starovoitov 
Tested-by: Alexei Starovoitov 
Fixes: bd4cf0ed331a ("net: filter: rework/optimize internal BPF
interpreter's instruction set")

Thankfully the fix doesn't have any conflicts with pending net-next patches.

> ---
>  net/core/filter.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 9d79ca0..4aec7b9 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -1559,8 +1559,13 @@ static struct sk_filter *__sk_prepare_filter(struct 
> sk_filter *fp,
> fp->jited = 0;
>
> err = sk_chk_filter(fp->insns, fp->len);
> -   if (err)
> +   if (err) {
> +   if (sk != NULL)
> +   sk_filter_uncharge(sk, fp);
> +   else
> +   kfree(fp);
> return ERR_PTR(err);
> +   }
>
> /* Probe if we can JIT compile the filter and if so, do
>  * the compilation of the filter.
> --
> 1.9.3
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-06-01 Thread Alexei Starovoitov
On Sat, May 31, 2014 at 10:37 PM, Leon Yu chianglun...@gmail.com wrote:
 __sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
 rework/optimize internal BPF interpreter's instruction set) so that it should
 have uncharged memory once things went wrong. However that work isn't 
 complete.
 Error is handled only in __sk_migrate_filter() while memory can still leak in
 the error path right after sk_chk_filter().

 Signed-off-by: Leon Yu chianglun...@gmail.com

Nice catch. Thanks!
kmemleak confirmed the leak.

Acked-by: Alexei Starovoitov a...@plumgrid.com
Tested-by: Alexei Starovoitov a...@plumgrid.com
Fixes: bd4cf0ed331a (net: filter: rework/optimize internal BPF
interpreter's instruction set)

Thankfully the fix doesn't have any conflicts with pending net-next patches.

 ---
  net/core/filter.c | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

 diff --git a/net/core/filter.c b/net/core/filter.c
 index 9d79ca0..4aec7b9 100644
 --- a/net/core/filter.c
 +++ b/net/core/filter.c
 @@ -1559,8 +1559,13 @@ static struct sk_filter *__sk_prepare_filter(struct 
 sk_filter *fp,
 fp-jited = 0;

 err = sk_chk_filter(fp-insns, fp-len);
 -   if (err)
 +   if (err) {
 +   if (sk != NULL)
 +   sk_filter_uncharge(sk, fp);
 +   else
 +   kfree(fp);
 return ERR_PTR(err);
 +   }

 /* Probe if we can JIT compile the filter and if so, do
  * the compilation of the filter.
 --
 1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-05-31 Thread Leon Yu
__sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
rework/optimize internal BPF interpreter's instruction set) so that it should
have uncharged memory once things went wrong. However that work isn't complete.
Error is handled only in __sk_migrate_filter() while memory can still leak in
the error path right after sk_chk_filter().

Signed-off-by: Leon Yu 
---
 net/core/filter.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 9d79ca0..4aec7b9 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1559,8 +1559,13 @@ static struct sk_filter *__sk_prepare_filter(struct 
sk_filter *fp,
fp->jited = 0;
 
err = sk_chk_filter(fp->insns, fp->len);
-   if (err)
+   if (err) {
+   if (sk != NULL)
+   sk_filter_uncharge(sk, fp);
+   else
+   kfree(fp);
return ERR_PTR(err);
+   }
 
/* Probe if we can JIT compile the filter and if so, do
 * the compilation of the filter.
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] net: filter: fix possible memory leak in __sk_prepare_filter()

2014-05-31 Thread Leon Yu
__sk_prepare_filter() was reworked in commit bd4cf0ed3 (net: filter:
rework/optimize internal BPF interpreter's instruction set) so that it should
have uncharged memory once things went wrong. However that work isn't complete.
Error is handled only in __sk_migrate_filter() while memory can still leak in
the error path right after sk_chk_filter().

Signed-off-by: Leon Yu chianglun...@gmail.com
---
 net/core/filter.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 9d79ca0..4aec7b9 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1559,8 +1559,13 @@ static struct sk_filter *__sk_prepare_filter(struct 
sk_filter *fp,
fp-jited = 0;
 
err = sk_chk_filter(fp-insns, fp-len);
-   if (err)
+   if (err) {
+   if (sk != NULL)
+   sk_filter_uncharge(sk, fp);
+   else
+   kfree(fp);
return ERR_PTR(err);
+   }
 
/* Probe if we can JIT compile the filter and if so, do
 * the compilation of the filter.
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/