Skip to contentSkip to conversation

bpf: fix static checker warning

PATCH Applied Alexei Starovoitov 2 participants 2 messages Nov 26, 2019 – Nov 27, 2019

Subsystems (3)
lore
Share & tools
lore

Alexei Starovoitov

author maintainer
#0 lore raw

PATCH 1/1 bpf: fix static checker warning

kernel/bpf/btf.c:4023 btf_distill_func_proto()
error: potentially dereferencing uninitialized 't'.

kernel/bpf/btf.c
4012 nargs = btf_type_vlen(func);
4013 if (nargs >= MAX_BPF_FUNC_ARGS) {
4014 bpf_log(log,
4015 "The function %s has %d arguments. Too many.\n",
4016 tname, nargs);
4017 return -EINVAL;
4018 }

  4019          ret = __get_type_size(btf, func->type, &t);
                                                       ^^

t isn't initialized for the first -EINVAL return

This is unlikely path, since BTF should have been validated at this point. Fix it by returning 'void' BTF.

---
 kernel/bpf/btf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/btf.c +3 -1
index 40efde5eedcb..bd5e11881ba3 100644
@@ -3976,8 +3976,10 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
 	t = btf_type_by_id(btf, btf_id);
 	while (t && btf_type_is_modifier(t))
 		t = btf_type_by_id(btf, t->type);
-	if (!t)
+	if (!t) {
+		*bad_type = btf->types[0];
 		return -EINVAL;
+	}
 	if (btf_type_is_ptr(t))
 		/* kernel size of pointer. Not BPF's size of pointer*/
 		return sizeof(void *);
Signature · 1 line
2.23.0
maintainer Applied
#1 lore raw
Quoted 13 lines · Alexei Starovoitov

kernel/bpf/btf.c:4023 btf_distill_func_proto()
error: potentially dereferencing uninitialized 't'.

kernel/bpf/btf.c

   4012          nargs = btf_type_vlen(func);
   4013          if (nargs >= MAX_BPF_FUNC_ARGS) {
   4014                  bpf_log(log,
   4015                          "The function %s has %d arguments. Too many.\n",
   4016                          tname, nargs);
   4017                  return -EINVAL;
   4018          }
   4019          ret = __get_type_size(btf, func->type, &t);
                                                        ^^
Quoted 7 lines

t isn't initialized for the first -EINVAL return

This is unlikely path, since BTF should have been validated at this point. Fix it by returning 'void' BTF.

Applied, thanks!