diff mbox series

[bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value

Message ID 20230324184241.1387437-1-martin.lau@linux.dev (mailing list archive)
State Accepted
Commit 55fbae05476df65e5eee8be54f61d0257af0240b
Delegated to: BPF
Headers show
Series [bpf-next] bpf: Check IS_ERR for the bpf_map_get() return value | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 pending Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on s390x with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 21 this patch: 21
netdev/cc_maintainers fail 1 blamed authors not CCed: kuifeng@meta.com; 9 maintainers not CCed: song@kernel.org sdf@google.com haoluo@google.com yhs@fb.com john.fastabend@gmail.com kuifeng@meta.com kpsingh@kernel.org jolsa@kernel.org netdev@vger.kernel.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 21 this patch: 21
netdev/checkpatch warning WARNING: Reported-by: should be immediately followed by Link: with a URL to the report
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-15 fail Logs for test_progs on s390x with gcc

Commit Message

Martin KaFai Lau March 24, 2023, 6:42 p.m. UTC
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(-)

Comments

Kui-Feng Lee March 24, 2023, 7:20 p.m. UTC | #1
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) {
Stanislav Fomichev March 24, 2023, 7:37 p.m. UTC | #2
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
patchwork-bot+netdevbpf@kernel.org March 24, 2023, 7:50 p.m. UTC | #3
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!
diff mbox series

Patch

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) {