* [PATCH v2 bpf] bpf: fix leak in LINK_UPDATE and enforce empty old_prog_fd
@ 2020-04-24 5:20 Andrii Nakryiko
2020-04-25 0:30 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-04-24 5:20 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
Fix bug of not putting bpf_link in LINK_UPDATE command.
Also enforce zeroed old_prog_fd if no BPF_F_REPLACE flag is specified.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
This version will merge with no conflicts with the upcoming LINK_UPDATE
refactoring patch (part of bpf_link observability patch set).
kernel/bpf/syscall.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index d85f37239540..bca58c235ac0 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3628,8 +3628,10 @@ static int link_update(union bpf_attr *attr)
return PTR_ERR(link);
new_prog = bpf_prog_get(attr->link_update.new_prog_fd);
- if (IS_ERR(new_prog))
- return PTR_ERR(new_prog);
+ if (IS_ERR(new_prog)) {
+ ret = PTR_ERR(new_prog);
+ goto out_put_link;
+ }
if (flags & BPF_F_REPLACE) {
old_prog = bpf_prog_get(attr->link_update.old_prog_fd);
@@ -3638,6 +3640,9 @@ static int link_update(union bpf_attr *attr)
old_prog = NULL;
goto out_put_progs;
}
+ } else if (attr->link_update.old_prog_fd) {
+ ret = -EINVAL;
+ goto out_put_progs;
}
#ifdef CONFIG_CGROUP_BPF
@@ -3653,6 +3658,8 @@ static int link_update(union bpf_attr *attr)
bpf_prog_put(old_prog);
if (ret)
bpf_prog_put(new_prog);
+out_put_link:
+ bpf_link_put(link);
return ret;
}
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 bpf] bpf: fix leak in LINK_UPDATE and enforce empty old_prog_fd
2020-04-24 5:20 [PATCH v2 bpf] bpf: fix leak in LINK_UPDATE and enforce empty old_prog_fd Andrii Nakryiko
@ 2020-04-25 0:30 ` Alexei Starovoitov
2020-04-25 2:12 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2020-04-25 0:30 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Kernel Team
On Thu, Apr 23, 2020 at 10:21 PM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Fix bug of not putting bpf_link in LINK_UPDATE command.
> Also enforce zeroed old_prog_fd if no BPF_F_REPLACE flag is specified.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Applied. Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 bpf] bpf: fix leak in LINK_UPDATE and enforce empty old_prog_fd
2020-04-25 0:30 ` Alexei Starovoitov
@ 2020-04-25 2:12 ` Andrii Nakryiko
0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-04-25 2:12 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrii Nakryiko, bpf, Network Development, Alexei Starovoitov,
Daniel Borkmann, Kernel Team
On Fri, Apr 24, 2020 at 5:31 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Apr 23, 2020 at 10:21 PM Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Fix bug of not putting bpf_link in LINK_UPDATE command.
> > Also enforce zeroed old_prog_fd if no BPF_F_REPLACE flag is specified.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Applied. Thanks
Oops, forgot to include Fixes tag :( If it's not too late, can you please add?
Fixes: 0c991ebc8c69 ("bpf: Implement bpf_prog replacement for an
active bpf_cgroup_link")
Thank you!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-25 2:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 5:20 [PATCH v2 bpf] bpf: fix leak in LINK_UPDATE and enforce empty old_prog_fd Andrii Nakryiko
2020-04-25 0:30 ` Alexei Starovoitov
2020-04-25 2:12 ` Andrii Nakryiko
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).