Skip to contentSkip to conversation

bpf: Fix an error code in check_btf_func()

PATCH Superseded Dan Carpenter 4 participants 5 messages Jun 3, 2020 – Jun 4, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Fix an error code in check_btf_func()

This code returns success if kcalloc() but it should return -ENOMEM.

Fixes 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")
---
 kernel/bpf/verifier.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +3 -1
index 5c7bbaac81ef9..25363f134bf0c 100644
@@ -7581,8 +7581,10 @@ static int check_btf_func(struct bpf_verifier_env *env,
 	if (!krecord)
 		return -ENOMEM;
 	info_aux = kcalloc(nfuncs, sizeof(*info_aux), GFP_KERNEL | __GFP_NOWARN);
-	if (!info_aux)
+	if (!info_aux) {
+		ret = -ENOMEM;
 		goto err_free;
+	}
 
 	for (i = 0; i < nfuncs; i++) {
 		ret = bpf_check_uarg_tail_zero(urecord, krec_size, urec_size);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 14 lines · Dan Carpenter

This code returns success if kcalloc() but it should return -ENOMEM.

Fixes 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")
---
 kernel/bpf/verifier.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +0 -0
index 5c7bbaac81ef9..25363f134bf0c 100644

kernel/bpf/verifier.c static int check_btf_func(struct bpf_verifier_env *env, · line 7587

Quoted 8 lines
kernel/bpf/verifier.c +3 -1
@@ -7581,8 +7581,10 @@ static int check_btf_func(struct bpf_verifier_env *env,
        if (!krecord)
                return -ENOMEM;
        info_aux = kcalloc(nfuncs, sizeof(*info_aux), GFP_KERNEL | __GFP_NOWARN);
-       if (!info_aux)
+       if (!info_aux) {
+               ret = -ENOMEM;
                goto err_free;
+       }

Thanks for the fix.
I think it's better to do 'int ret = -ENOMEM;' instead.

#2 lore raw

PATCH v2 1/1 bpf: Fix an error code in check_btf_func()

This code returns success if the "info_aux" allocation fails but it should return -ENOMEM.

Fixes 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")

---
v2: style change

 kernel/bpf/verifier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
index 5c7bbaac81ef9..34cde841ab681 100644
@@ -7552,7 +7552,7 @@ static int check_btf_func(struct bpf_verifier_env *env,
 	const struct btf *btf;
 	void __user *urecord;
 	u32 prev_offset = 0;
-	int ret = 0;
+	int ret = -ENOMEM;
 
 	nfuncs = attr->func_info_cnt;
 	if (!nfuncs)
Signature · 1 line
2.26.2
reviewer Acked-by on v2 1/1
#3 lore raw
Quoted 6 lines · Dan Carpenter

This code returns success if the "info_aux" allocation fails but it should return -ENOMEM.

Fixes 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")
Quoted 3 lines

---
v2: style change

maintainer Applied
#4 lore raw
Quoted 9 lines · Song Liu
Quoted 6 lines · Dan Carpenter

This code returns success if the "info_aux" allocation fails but it should return -ENOMEM.

Fixes 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")

Applied, thanks (my personal style preference would have been v1, but fair enough).