* [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value
@ 2023-03-24 18:42 Martin KaFai Lau
2023-03-24 19:20 ` Kui-Feng Lee
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Martin KaFai Lau @ 2023-03-24 18:42 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, syzbot+71ccc0fe37abb458406b
From: Martin KaFai Lau <martin.lau@kernel.org>
This patch fixes a mistake in checking NULL instead of
checking IS_ERR for the bpf_map_get() return value.
It also fixes the return value in link_update_map() from -EINVAL
to PTR_ERR(*_map).
Reported-by: syzbot+71ccc0fe37abb458406b@syzkaller.appspotmail.com
Fixes: 68b04864ca42 ("bpf: Create links for BPF struct_ops maps.")
Fixes: aef56f2e918b ("bpf: Update the struct_ops of a bpf_link.")
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
---
kernel/bpf/bpf_struct_ops.c | 4 ++--
kernel/bpf/syscall.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 6401deca3b56..d3f0a4825fa6 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -871,8 +871,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
int err;
map = bpf_map_get(attr->link_create.map_fd);
- if (!map)
- return -EINVAL;
+ if (IS_ERR(map))
+ return PTR_ERR(map);
st_map = (struct bpf_struct_ops_map *)map;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index b4d758fa5981..a09597c95029 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -4689,12 +4689,12 @@ static int link_update_map(struct bpf_link *link, union bpf_attr *attr)
new_map = bpf_map_get(attr->link_update.new_map_fd);
if (IS_ERR(new_map))
- return -EINVAL;
+ return PTR_ERR(new_map);
if (attr->link_update.flags & BPF_F_REPLACE) {
old_map = bpf_map_get(attr->link_update.old_map_fd);
if (IS_ERR(old_map)) {
- ret = -EINVAL;
+ ret = PTR_ERR(old_map);
goto out_put;
}
} else if (attr->link_update.old_map_fd) {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value
2023-03-24 18:42 [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value Martin KaFai Lau
@ 2023-03-24 19:20 ` Kui-Feng Lee
2023-03-24 19:37 ` Stanislav Fomichev
2023-03-24 19:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Kui-Feng Lee @ 2023-03-24 19:20 UTC (permalink / raw)
To: Martin KaFai Lau, bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, syzbot+71ccc0fe37abb458406b
This fix makes sense to me.
Thank you for fixing this.
Acked-by: Kui-Feng Lee <kuifeng@meta.com>
On 3/24/23 11:42, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> This patch fixes a mistake in checking NULL instead of
> checking IS_ERR for the bpf_map_get() return value.
>
> It also fixes the return value in link_update_map() from -EINVAL
> to PTR_ERR(*_map).
>
> Reported-by: syzbot+71ccc0fe37abb458406b@syzkaller.appspotmail.com
> Fixes: 68b04864ca42 ("bpf: Create links for BPF struct_ops maps.")
> Fixes: aef56f2e918b ("bpf: Update the struct_ops of a bpf_link.")
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
> ---
> kernel/bpf/bpf_struct_ops.c | 4 ++--
> kernel/bpf/syscall.c | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
> index 6401deca3b56..d3f0a4825fa6 100644
> --- a/kernel/bpf/bpf_struct_ops.c
> +++ b/kernel/bpf/bpf_struct_ops.c
> @@ -871,8 +871,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
> int err;
>
> map = bpf_map_get(attr->link_create.map_fd);
> - if (!map)
> - return -EINVAL;
> + if (IS_ERR(map))
> + return PTR_ERR(map);
>
> st_map = (struct bpf_struct_ops_map *)map;
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index b4d758fa5981..a09597c95029 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -4689,12 +4689,12 @@ static int link_update_map(struct bpf_link *link, union bpf_attr *attr)
>
> new_map = bpf_map_get(attr->link_update.new_map_fd);
> if (IS_ERR(new_map))
> - return -EINVAL;
> + return PTR_ERR(new_map);
>
> if (attr->link_update.flags & BPF_F_REPLACE) {
> old_map = bpf_map_get(attr->link_update.old_map_fd);
> if (IS_ERR(old_map)) {
> - ret = -EINVAL;
> + ret = PTR_ERR(old_map);
> goto out_put;
> }
> } else if (attr->link_update.old_map_fd) {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value
2023-03-24 18:42 [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value Martin KaFai Lau
2023-03-24 19:20 ` Kui-Feng Lee
@ 2023-03-24 19:37 ` Stanislav Fomichev
2023-03-24 19:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2023-03-24 19:37 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: bpf, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, syzbot+71ccc0fe37abb458406b
On 03/24, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
> This patch fixes a mistake in checking NULL instead of
> checking IS_ERR for the bpf_map_get() return value.
> It also fixes the return value in link_update_map() from -EINVAL
> to PTR_ERR(*_map).
> Reported-by: syzbot+71ccc0fe37abb458406b@syzkaller.appspotmail.com
> Fixes: 68b04864ca42 ("bpf: Create links for BPF struct_ops maps.")
> Fixes: aef56f2e918b ("bpf: Update the struct_ops of a bpf_link.")
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
> ---
> kernel/bpf/bpf_struct_ops.c | 4 ++--
> kernel/bpf/syscall.c | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
> diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
> index 6401deca3b56..d3f0a4825fa6 100644
> --- a/kernel/bpf/bpf_struct_ops.c
> +++ b/kernel/bpf/bpf_struct_ops.c
> @@ -871,8 +871,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
> int err;
> map = bpf_map_get(attr->link_create.map_fd);
> - if (!map)
> - return -EINVAL;
> + if (IS_ERR(map))
> + return PTR_ERR(map);
> st_map = (struct bpf_struct_ops_map *)map;
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index b4d758fa5981..a09597c95029 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -4689,12 +4689,12 @@ static int link_update_map(struct bpf_link *link,
> union bpf_attr *attr)
> new_map = bpf_map_get(attr->link_update.new_map_fd);
> if (IS_ERR(new_map))
> - return -EINVAL;
> + return PTR_ERR(new_map);
> if (attr->link_update.flags & BPF_F_REPLACE) {
> old_map = bpf_map_get(attr->link_update.old_map_fd);
> if (IS_ERR(old_map)) {
> - ret = -EINVAL;
> + ret = PTR_ERR(old_map);
> goto out_put;
> }
> } else if (attr->link_update.old_map_fd) {
> --
> 2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value
2023-03-24 18:42 [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value Martin KaFai Lau
2023-03-24 19:20 ` Kui-Feng Lee
2023-03-24 19:37 ` Stanislav Fomichev
@ 2023-03-24 19:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-24 19:50 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: bpf, ast, andrii, daniel, kernel-team, syzbot+71ccc0fe37abb458406b
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Fri, 24 Mar 2023 11:42:41 -0700 you wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> This patch fixes a mistake in checking NULL instead of
> checking IS_ERR for the bpf_map_get() return value.
>
> It also fixes the return value in link_update_map() from -EINVAL
> to PTR_ERR(*_map).
>
> [...]
Here is the summary with links:
- [bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value
https://git.kernel.org/bpf/bpf-next/c/55fbae05476d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-24 19:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 18:42 [PATCH bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value Martin KaFai Lau
2023-03-24 19:20 ` Kui-Feng Lee
2023-03-24 19:37 ` Stanislav Fomichev
2023-03-24 19:50 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.