public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: don't forget to free sk_filter
@ 2013-11-06 15:51 Andrey Vagin
  2013-11-06 16:39 ` Alexei Starovoitov
  2013-11-06 19:19 ` Daniel Borkmann
  0 siblings, 2 replies; 9+ messages in thread
From: Andrey Vagin @ 2013-11-06 15:51 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrey Vagin, Alexei Starovoitov, Eric Dumazet,
	David S. Miller, stable

sk_filter isn't freed if bpf_func is equal to sk_run_filter.

This memory leak was introduced by
commit d45ed4a4e33ae103053c0a53d280014e7101bb5c
Author: Alexei Starovoitov <ast@plumgrid.com>
Date:   Fri Oct 4 00:14:06 2013 -0700

    net: fix unsafe set_memory_rw from softirq

Before this patch sk_filter was freed in sk_filter_release_rcu,
now it is freed in bpf_jit_free.

Here is output of kmemleak:
unreferenced object 0xffff8800b774eab0 (size 128):
  comm "systemd", pid 1, jiffies 4294669014 (age 124.062s)
  hex dump (first 32 bytes):
    00 00 00 00 0b 00 00 00 20 63 7f b7 00 88 ff ff  ........ c......
    60 d4 55 81 ff ff ff ff 30 d9 55 81 ff ff ff ff  `.U.....0.U.....
  backtrace:
    [<ffffffff816444be>] kmemleak_alloc+0x4e/0xb0
    [<ffffffff811845af>] __kmalloc+0xef/0x260
    [<ffffffff81534028>] sock_kmalloc+0x38/0x60
    [<ffffffff8155d4dd>] sk_attach_filter+0x5d/0x190
    [<ffffffff815378a1>] sock_setsockopt+0x991/0x9e0
    [<ffffffff81531bd6>] SyS_setsockopt+0xb6/0xd0
    [<ffffffff8165f3e9>] system_call_fastpath+0x16/0x1b
    [<ffffffffffffffff>] 0xffffffffffffffff

Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: stable@vger.kernel.org # 3.12
Signed-off-by: Andrey Vagin <avagin@openvz.org>
---
 arch/x86/net/bpf_jit_comp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 516593e..3c55de5 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -788,5 +788,6 @@ void bpf_jit_free(struct sk_filter *fp)
 	if (fp->bpf_func != sk_run_filter) {
 		INIT_WORK(&fp->work, bpf_jit_free_deferred);
 		schedule_work(&fp->work);
-	}
+	} else
+		kfree(fp);
 }
-- 
1.8.3.1

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 15:51 [PATCH] net: don't forget to free sk_filter Andrey Vagin
@ 2013-11-06 16:39 ` Alexei Starovoitov
  2013-11-06 19:19 ` Daniel Borkmann
  1 sibling, 0 replies; 9+ messages in thread
From: Alexei Starovoitov @ 2013-11-06 16:39 UTC (permalink / raw)
  To: Andrey Vagin; +Cc: netdev, Eric Dumazet, David S. Miller

On Wed, Nov 6, 2013 at 7:51 AM, Andrey Vagin <avagin@openvz.org> wrote:
> sk_filter isn't freed if bpf_func is equal to sk_run_filter.

good catch! thanks.

> This memory leak was introduced by
> commit d45ed4a4e33ae103053c0a53d280014e7101bb5c
> Author: Alexei Starovoitov <ast@plumgrid.com>
> Date:   Fri Oct 4 00:14:06 2013 -0700
>
>     net: fix unsafe set_memory_rw from softirq
>
> Before this patch sk_filter was freed in sk_filter_release_rcu,
> now it is freed in bpf_jit_free.
>
> Here is output of kmemleak:
> unreferenced object 0xffff8800b774eab0 (size 128):
>   comm "systemd", pid 1, jiffies 4294669014 (age 124.062s)
>   hex dump (first 32 bytes):
>     00 00 00 00 0b 00 00 00 20 63 7f b7 00 88 ff ff  ........ c......
>     60 d4 55 81 ff ff ff ff 30 d9 55 81 ff ff ff ff  `.U.....0.U.....
>   backtrace:
>     [<ffffffff816444be>] kmemleak_alloc+0x4e/0xb0
>     [<ffffffff811845af>] __kmalloc+0xef/0x260
>     [<ffffffff81534028>] sock_kmalloc+0x38/0x60
>     [<ffffffff8155d4dd>] sk_attach_filter+0x5d/0x190
>     [<ffffffff815378a1>] sock_setsockopt+0x991/0x9e0
>     [<ffffffff81531bd6>] SyS_setsockopt+0xb6/0xd0
>     [<ffffffff8165f3e9>] system_call_fastpath+0x16/0x1b
>     [<ffffffffffffffff>] 0xffffffffffffffff
>
> Cc: Alexei Starovoitov <ast@plumgrid.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: stable@vger.kernel.org # 3.12
> Signed-off-by: Andrey Vagin <avagin@openvz.org>
> ---
>  arch/x86/net/bpf_jit_comp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 516593e..3c55de5 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -788,5 +788,6 @@ void bpf_jit_free(struct sk_filter *fp)
>         if (fp->bpf_func != sk_run_filter) {
>                 INIT_WORK(&fp->work, bpf_jit_free_deferred);
>                 schedule_work(&fp->work);
> -       }
> +       } else
> +               kfree(fp);

please add extra { } after else

Thanks
Alexei

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 15:51 [PATCH] net: don't forget to free sk_filter Andrey Vagin
  2013-11-06 16:39 ` Alexei Starovoitov
@ 2013-11-06 19:19 ` Daniel Borkmann
  2013-11-06 19:28   ` Eric Dumazet
  1 sibling, 1 reply; 9+ messages in thread
From: Daniel Borkmann @ 2013-11-06 19:19 UTC (permalink / raw)
  To: Andrey Vagin
  Cc: netdev, linux-kernel, Alexei Starovoitov, Eric Dumazet,
	David S. Miller, stable

On 11/06/2013 04:51 PM, Andrey Vagin wrote:
> sk_filter isn't freed if bpf_func is equal to sk_run_filter.
>
> This memory leak was introduced by
> commit d45ed4a4e33ae103053c0a53d280014e7101bb5c
> Author: Alexei Starovoitov <ast@plumgrid.com>
> Date:   Fri Oct 4 00:14:06 2013 -0700
>
>      net: fix unsafe set_memory_rw from softirq
>
> Before this patch sk_filter was freed in sk_filter_release_rcu,
> now it is freed in bpf_jit_free.
>
> Here is output of kmemleak:
> unreferenced object 0xffff8800b774eab0 (size 128):
>    comm "systemd", pid 1, jiffies 4294669014 (age 124.062s)
>    hex dump (first 32 bytes):
>      00 00 00 00 0b 00 00 00 20 63 7f b7 00 88 ff ff  ........ c......
>      60 d4 55 81 ff ff ff ff 30 d9 55 81 ff ff ff ff  `.U.....0.U.....
>    backtrace:
>      [<ffffffff816444be>] kmemleak_alloc+0x4e/0xb0
>      [<ffffffff811845af>] __kmalloc+0xef/0x260
>      [<ffffffff81534028>] sock_kmalloc+0x38/0x60
>      [<ffffffff8155d4dd>] sk_attach_filter+0x5d/0x190
>      [<ffffffff815378a1>] sock_setsockopt+0x991/0x9e0
>      [<ffffffff81531bd6>] SyS_setsockopt+0xb6/0xd0
>      [<ffffffff8165f3e9>] system_call_fastpath+0x16/0x1b
>      [<ffffffffffffffff>] 0xffffffffffffffff
>
> Cc: Alexei Starovoitov <ast@plumgrid.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: stable@vger.kernel.org # 3.12

^^^^ vi Documentation/networking/netdev-FAQ.txt +155

> Signed-off-by: Andrey Vagin <avagin@openvz.org>

When you send v2 with Alexei's feedback, please also be more specific
in your subject like "net: x86: bpf: don't forget to free sk_filter"
or the like. Also it's enough to say 'This memory leak was introduced
by commit d45ed4a4e3 ("net: fix unsafe set_memory_rw from softirq")'
instead of copying the whole log. Anyways, for v2 with feedback included
then:

Acked-by: Daniel Borkmann <dborkman@redhat.com>

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 19:19 ` Daniel Borkmann
@ 2013-11-06 19:28   ` Eric Dumazet
  2013-11-06 19:31     ` Daniel Borkmann
                       ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Eric Dumazet @ 2013-11-06 19:28 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Andrey Vagin, netdev, linux-kernel, Alexei Starovoitov,
	Eric Dumazet, David S. Miller, stable

On Wed, 2013-11-06 at 20:19 +0100, Daniel Borkmann wrote:

> When you send v2 with Alexei's feedback, please also be more specific
> in your subject like "net: x86: bpf: don't forget to free sk_filter"
> or the like. Also it's enough to say 'This memory leak was introduced
> by commit d45ed4a4e3 ("net: fix unsafe set_memory_rw from softirq")'
> instead of copying the whole log. Anyways, for v2 with feedback included
> then:

Actually, the new way [1] of doing this would be to use the 'Fixes:' tag
as in :

Fixes: <12 digits SHA1> ("net: fix unsafe set_memory_rw from softirq")

[1] As discussed at last Kernel Summit

Example in 

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6920a1bd037374a632d585de127b6f945199dcb8

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 19:28   ` Eric Dumazet
@ 2013-11-06 19:31     ` Daniel Borkmann
  2013-11-06 19:44     ` Alexei Starovoitov
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Daniel Borkmann @ 2013-11-06 19:31 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Andrey Vagin, netdev, linux-kernel, Alexei Starovoitov,
	Eric Dumazet, David S. Miller, stable

On 11/06/2013 08:28 PM, Eric Dumazet wrote:
> On Wed, 2013-11-06 at 20:19 +0100, Daniel Borkmann wrote:
>
>> When you send v2 with Alexei's feedback, please also be more specific
>> in your subject like "net: x86: bpf: don't forget to free sk_filter"
>> or the like. Also it's enough to say 'This memory leak was introduced
>> by commit d45ed4a4e3 ("net: fix unsafe set_memory_rw from softirq")'
>> instead of copying the whole log. Anyways, for v2 with feedback included
>> then:
>
> Actually, the new way [1] of doing this would be to use the 'Fixes:' tag
> as in :
>
> Fixes: <12 digits SHA1> ("net: fix unsafe set_memory_rw from softirq")
>
> [1] As discussed at last Kernel Summit
>
> Example in
>
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6920a1bd037374a632d585de127b6f945199dcb8

Cool, good to know, that's even better!

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 19:28   ` Eric Dumazet
  2013-11-06 19:31     ` Daniel Borkmann
@ 2013-11-06 19:44     ` Alexei Starovoitov
  2013-11-06 20:24     ` David Miller
  2013-11-08  0:56     ` Keller, Jacob E
  3 siblings, 0 replies; 9+ messages in thread
From: Alexei Starovoitov @ 2013-11-06 19:44 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Daniel Borkmann, Andrey Vagin, netdev, linux-kernel, Eric Dumazet,
	David S. Miller

On Wed, Nov 6, 2013 at 11:28 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Actually, the new way [1] of doing this would be to use the 'Fixes:' tag
> as in :
>
> Fixes: <12 digits SHA1> ("net: fix unsafe set_memory_rw from softirq")
>
> [1] As discussed at last Kernel Summit

thx. good to know.
Unfortunately 2013 Kernel Summit proceedings are not public (yet?),
but available to paid LWN subscribers.

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 19:28   ` Eric Dumazet
  2013-11-06 19:31     ` Daniel Borkmann
  2013-11-06 19:44     ` Alexei Starovoitov
@ 2013-11-06 20:24     ` David Miller
  2013-11-08  0:56     ` Keller, Jacob E
  3 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2013-11-06 20:24 UTC (permalink / raw)
  To: eric.dumazet; +Cc: dborkman, avagin, netdev, linux-kernel, ast, edumazet

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 06 Nov 2013 11:28:18 -0800

> On Wed, 2013-11-06 at 20:19 +0100, Daniel Borkmann wrote:
> 
>> When you send v2 with Alexei's feedback, please also be more specific
>> in your subject like "net: x86: bpf: don't forget to free sk_filter"
>> or the like. Also it's enough to say 'This memory leak was introduced
>> by commit d45ed4a4e3 ("net: fix unsafe set_memory_rw from softirq")'
>> instead of copying the whole log. Anyways, for v2 with feedback included
>> then:
> 
> Actually, the new way [1] of doing this would be to use the 'Fixes:' tag
> as in :
> 
> Fixes: <12 digits SHA1> ("net: fix unsafe set_memory_rw from softirq")
> 
> [1] As discussed at last Kernel Summit
> 
> Example in 
> 
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6920a1bd037374a632d585de127b6f945199dcb8

Indeed, and I'm totally fine with this new mechanism too, please use it.

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-06 19:28   ` Eric Dumazet
                       ` (2 preceding siblings ...)
  2013-11-06 20:24     ` David Miller
@ 2013-11-08  0:56     ` Keller, Jacob E
  2013-11-08  0:58       ` Eric Dumazet
  3 siblings, 1 reply; 9+ messages in thread
From: Keller, Jacob E @ 2013-11-08  0:56 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Daniel Borkmann, Andrey Vagin, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Alexei Starovoitov, Eric Dumazet,
	David S. Miller, stable@vger.kernel.org.#.3.12

On Wed, 2013-11-06 at 11:28 -0800, Eric Dumazet wrote:
> On Wed, 2013-11-06 at 20:19 +0100, Daniel Borkmann wrote:
> 
> > When you send v2 with Alexei's feedback, please also be more specific
> > in your subject like "net: x86: bpf: don't forget to free sk_filter"
> > or the like. Also it's enough to say 'This memory leak was introduced
> > by commit d45ed4a4e3 ("net: fix unsafe set_memory_rw from softirq")'
> > instead of copying the whole log. Anyways, for v2 with feedback included
> > then:
> 
> Actually, the new way [1] of doing this would be to use the 'Fixes:' tag
> as in :
> 
> Fixes: <12 digits SHA1> ("net: fix unsafe set_memory_rw from softirq")
> 
> [1] As discussed at last Kernel Summit
> 
> Example in 
> 
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6920a1bd037374a632d585de127b6f945199dcb8
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Has there been any mention of a forthcoming patch
to ./Documentation/SubmittingPatches which documents this?

Thanks,
Jake

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

* Re: [PATCH] net: don't forget to free sk_filter
  2013-11-08  0:56     ` Keller, Jacob E
@ 2013-11-08  0:58       ` Eric Dumazet
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2013-11-08  0:58 UTC (permalink / raw)
  To: Keller, Jacob E
  Cc: Daniel Borkmann, Andrey Vagin, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Alexei Starovoitov, Eric Dumazet,
	David S. Miller, stable@vger.kernel.org.#.3.12

On Fri, 2013-11-08 at 00:56 +0000, Keller, Jacob E wrote:

> Has there been any mention of a forthcoming patch
> to ./Documentation/SubmittingPatches which documents this?

I do not remember if this point was raised, but you certainly
can submit a patch !

Thanks

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

end of thread, other threads:[~2013-11-08  0:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-06 15:51 [PATCH] net: don't forget to free sk_filter Andrey Vagin
2013-11-06 16:39 ` Alexei Starovoitov
2013-11-06 19:19 ` Daniel Borkmann
2013-11-06 19:28   ` Eric Dumazet
2013-11-06 19:31     ` Daniel Borkmann
2013-11-06 19:44     ` Alexei Starovoitov
2013-11-06 20:24     ` David Miller
2013-11-08  0:56     ` Keller, Jacob E
2013-11-08  0:58       ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox