bpf: fix mem leak in error path of lwt bpf setup
Subsystems (2)
PATCH 1/1 bpf: fix mem leak in error path of lwt bpf setup
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.
--- net/core/lwt_bpf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/lwt_bpf.c +3 -1
@@ -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;
Signature · 1 line
2.16.1
Quoted 15 lines · Mathieu Xhonneux
In
bpf_parse_prog, ifbpf_prog_get_typefails, the function is immediately terminated without freeing the previously allocatedprog->name.
This patch adds a kfree before the return.Signed-off-by Mathieu Xhonneux <[email protected]>--- net/core/lwt_bpf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/core/lwt_bpf.c +0
-0
net/core/lwt_bpf.c static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog, · line 227
Quoted 6 lines
net/core/lwt_bpf.c +2
-1@@ -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".
Quoted 8 lines
net/core/lwt_bpf.c +1
-0return PTR_ERR (p); + } prog->prog = p;Signature · 1 line
2.16.1
Quoted 17 lines · Martin KaFai Lau
Quoted 16 lines · Mathieu Xhonneux
In
bpf_parse_prog, ifbpf_prog_get_typefails, the function is immediately terminated without freeing the previously allocatedprog->name.
This patch adds a kfree before the return.Signed-off-by Mathieu Xhonneux <[email protected]>--- net/core/lwt_bpf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/core/lwt_bpf.c +0
-0@@ -223,8 +223,10 @@ static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog,
Quoted 8 lines
net/core/lwt_bpf.c static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog, · line 227
Quoted 5 lines
net/core/lwt_bpf.c +2
-1fd =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()", doesbpf_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.
Quoted 8 lines
Quoted 8 lines
net/core/lwt_bpf.c +1
-0return PTR_ERR (p); + } prog->prog = p;Signature · 1 line
2.16.1