* [PATCH] bpf: fix mem leak in error path of lwt bpf setup
@ 2018-05-20 13:08 Mathieu Xhonneux
2018-05-21 17:44 ` Martin KaFai Lau
0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Xhonneux @ 2018-05-20 13:08 UTC (permalink / raw)
To: netdev; +Cc: daniel, alexei.starovoitov
In bpf_parse_prog, if bpf_prog_get_type fails, the function is
immediately terminated without freeing the previously allocated
prog->name.
This patch adds a kfree before the return.
Signed-off-by: Mathieu Xhonneux <m.xhonneux@gmail.com>
---
net/core/lwt_bpf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index e7e626fb87bb..e142a7a32e46 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -223,8 +223,10 @@ static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog,
fd = nla_get_u32(tb[LWT_BPF_PROG_FD]);
p = bpf_prog_get_type(fd, type);
- if (IS_ERR(p))
+ if (IS_ERR(p)) {
+ kfree(prog->name);
return PTR_ERR(p);
+ }
prog->prog = p;
--
2.16.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] bpf: fix mem leak in error path of lwt bpf setup
2018-05-20 13:08 [PATCH] bpf: fix mem leak in error path of lwt bpf setup Mathieu Xhonneux
@ 2018-05-21 17:44 ` Martin KaFai Lau
2018-05-21 20:39 ` Daniel Borkmann
0 siblings, 1 reply; 3+ messages in thread
From: Martin KaFai Lau @ 2018-05-21 17:44 UTC (permalink / raw)
To: Mathieu Xhonneux; +Cc: netdev, daniel, alexei.starovoitov
On Sun, May 20, 2018 at 02:08:57PM +0100, Mathieu Xhonneux wrote:
> In bpf_parse_prog, if bpf_prog_get_type fails, the function is
> immediately terminated without freeing the previously allocated
> prog->name.
> This patch adds a kfree before the return.
>
> Signed-off-by: Mathieu Xhonneux <m.xhonneux@gmail.com>
> ---
> net/core/lwt_bpf.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
> index e7e626fb87bb..e142a7a32e46 100644
> --- a/net/core/lwt_bpf.c
> +++ b/net/core/lwt_bpf.c
> @@ -223,8 +223,10 @@ static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog,
>
> fd = nla_get_u32(tb[LWT_BPF_PROG_FD]);
> p = bpf_prog_get_type(fd, type);
> - if (IS_ERR(p))
> + if (IS_ERR(p)) {
> + kfree(prog->name);
I don't think it is needed.
The caller, "bpf_build_state()", does bpf_destroy_state() during error
out and it will eventually free up "name".
> return PTR_ERR(p);
> + }
>
> prog->prog = p;
>
> --
> 2.16.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bpf: fix mem leak in error path of lwt bpf setup
2018-05-21 17:44 ` Martin KaFai Lau
@ 2018-05-21 20:39 ` Daniel Borkmann
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-05-21 20:39 UTC (permalink / raw)
To: Martin KaFai Lau, Mathieu Xhonneux; +Cc: netdev, alexei.starovoitov
On 05/21/2018 07:44 PM, Martin KaFai Lau wrote:
> On Sun, May 20, 2018 at 02:08:57PM +0100, Mathieu Xhonneux wrote:
>> In bpf_parse_prog, if bpf_prog_get_type fails, the function is
>> immediately terminated without freeing the previously allocated
>> prog->name.
>> This patch adds a kfree before the return.
>>
>> Signed-off-by: Mathieu Xhonneux <m.xhonneux@gmail.com>
>> ---
>> net/core/lwt_bpf.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
>> index e7e626fb87bb..e142a7a32e46 100644
>> --- a/net/core/lwt_bpf.c
>> +++ b/net/core/lwt_bpf.c
>> @@ -223,8 +223,10 @@ static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog,
>>
>> fd = nla_get_u32(tb[LWT_BPF_PROG_FD]);
>> p = bpf_prog_get_type(fd, type);
>> - if (IS_ERR(p))
>> + if (IS_ERR(p)) {
>> + kfree(prog->name);
> I don't think it is needed.
> The caller, "bpf_build_state()", does bpf_destroy_state() during error
> out and it will eventually free up "name".
Agree, it's not needed in lwt/bpf due to call to destructor in error path.
>> return PTR_ERR(p);
>> + }
>>
>> prog->prog = p;
>>
>> --
>> 2.16.1
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-21 20:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-20 13:08 [PATCH] bpf: fix mem leak in error path of lwt bpf setup Mathieu Xhonneux
2018-05-21 17:44 ` Martin KaFai Lau
2018-05-21 20:39 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox