kernel/bpf/bpf_iter.c:148:15-20: ERROR: invalid reference to the index variable of the iterator on line 133 (fwd)
PATCH 801/821 kernel/bpf/bpf_iter.c:148:15-20: ERROR: invalid reference to the index variable of the iterator on line 133 (fwd)
Hello,
If the list_for_each_entry loop can exit normally (ie not by the break), then tinfo can be an invalid pointer after the loop.
julia
---------- Forwarded message ----------
Date: Sun, 10 May 2020 12:01:28 +0800
From: kbuild test robot <[email protected]>
To: kbuild(a)lists.01.org
Cc: lkp(a)intel.com, Julia Lawall <[email protected]>
Subject: [bpf-next:master 801/821] kernel/bpf/bpf_iter.c:148:15-20: ERROR:
invalid reference to the index variable of the iterator on line 133
CC: kbuild-all(a)lists.01.org
TO: Yonghong Song <[email protected]>
CC: Alexei Starovoitov <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master head: b4563facdcae55c83039d5efcc3b45a63da14d2f commit: de4e05cac46d206f9090051ef09930514bff73e4 [801/821] bpf: Support bpf tracing/iter programs for BPF_LINK_CREATE
:::::: branch date: 3 hours ago
:::::: commit date: 4 hours ago
If you fix the issue, kindly add following tag as appropriate
coccinelle warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
kernel/bpf/bpf_iter.c:148:15-20: ERROR: invalid reference to the index variable of the iterator on line 133
# https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=de4e05cac46d206f9090051ef09930514bff73e4
git remote add bpf-next https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
git remote update bpf-next
git checkout de4e05cac46d206f9090051ef09930514bff73e4
vim +148 kernel/bpf/bpf_iter.c
de4e05cac46d20 Yonghong Song 2020-05-09 118
de4e05cac46d20 Yonghong Song 2020-05-09 119 int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
de4e05cac46d20 Yonghong Song 2020-05-09 120 {
de4e05cac46d20 Yonghong Song 2020-05-09 121 struct bpf_link_primer link_primer;
de4e05cac46d20 Yonghong Song 2020-05-09 122 struct bpf_iter_target_info *tinfo;
de4e05cac46d20 Yonghong Song 2020-05-09 123 struct bpf_iter_link *link;
de4e05cac46d20 Yonghong Song 2020-05-09 124 bool existed = false;
de4e05cac46d20 Yonghong Song 2020-05-09 125 u32 prog_btf_id;
de4e05cac46d20 Yonghong Song 2020-05-09 126 int err;
de4e05cac46d20 Yonghong Song 2020-05-09 127
de4e05cac46d20 Yonghong Song 2020-05-09 128 if (attr->link_create.target_fd || attr->link_create.flags)
de4e05cac46d20 Yonghong Song 2020-05-09 129 return -EINVAL;
de4e05cac46d20 Yonghong Song 2020-05-09 130
de4e05cac46d20 Yonghong Song 2020-05-09 131 prog_btf_id = prog->aux->attach_btf_id;
de4e05cac46d20 Yonghong Song 2020-05-09 132 mutex_lock(&targets_mutex);
de4e05cac46d20 Yonghong Song 2020-05-09 @133 list_for_each_entry(tinfo, &targets, list) {
de4e05cac46d20 Yonghong Song 2020-05-09 134 if (tinfo->btf_id == prog_btf_id) {
de4e05cac46d20 Yonghong Song 2020-05-09 135 existed = true;
de4e05cac46d20 Yonghong Song 2020-05-09 136 break;
de4e05cac46d20 Yonghong Song 2020-05-09 137 }
de4e05cac46d20 Yonghong Song 2020-05-09 138 }
de4e05cac46d20 Yonghong Song 2020-05-09 139 mutex_unlock(&targets_mutex);
de4e05cac46d20 Yonghong Song 2020-05-09 140 if (!existed)
de4e05cac46d20 Yonghong Song 2020-05-09 141 return -ENOENT;
de4e05cac46d20 Yonghong Song 2020-05-09 142
de4e05cac46d20 Yonghong Song 2020-05-09 143 link = kzalloc(sizeof(*link), GFP_USER | __GFP_NOWARN);
de4e05cac46d20 Yonghong Song 2020-05-09 144 if (!link)
de4e05cac46d20 Yonghong Song 2020-05-09 145 return -ENOMEM;
de4e05cac46d20 Yonghong Song 2020-05-09 146
de4e05cac46d20 Yonghong Song 2020-05-09 147 bpf_link_init(&link->link, BPF_LINK_TYPE_ITER, &bpf_iter_link_lops, prog);de4e05cac46d20 Yonghong Song 2020-05-09 @148 link->tinfo = tinfo;
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 4 lines · Julia Lawall
Hello,
If the
list_for_each_entryloop can exit normally (ie not by the break), then tinfo can be an invalid pointer after the loop.
This should not happen since tinfo only accessed later when existed is true. I guess initializing tinfo = NULL will be able to silence this warning?
Quoted 73 lines
julia
---------- Forwarded message ----------
Date: Sun, 10 May 2020 12:01:28 +0800
From: kbuild test robot <[email protected]>
To: kbuild(a)lists.01.org
Cc: lkp(a)intel.com, Julia Lawall <[email protected]>
Subject: [bpf-next:master 801/821] kernel/bpf/bpf_iter.c:148:15-20: ERROR:
invalid reference to the index variable of the iterator on line 133CC: kbuild-all(a)lists.01.org
TO: Yonghong Song <[email protected]>
CC: Alexei Starovoitov <[email protected]>tree: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master head: b4563facdcae55c83039d5efcc3b45a63da14d2f commit: de4e05cac46d206f9090051ef09930514bff73e4 [801/821] bpf: Support bpf tracing/iter programs for BPF_LINK_CREATE:::::: branch date: 3 hours ago
:::::: commit date: 4 hours agoIf you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>Reported-by Julia Lawall <[email protected]>coccinelle warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
kernel/bpf/bpf_iter.c:148:15-20: ERROR: invalid reference to the index variable of the iterator on line 133
# https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=de4e05cac46d206f9090051ef09930514bff73e4
git remote add bpf-next https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
git remote update bpf-next
git checkoutde4e05cac46d206f9090051ef09930514bff73e4
vim +148kernel/bpf/bpf_iter.cde4e05cac46d20 Yonghong Song 2020-05-09 118 de4e05cac46d20 Yonghong Song 2020-05-09 119 int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) de4e05cac46d20 Yonghong Song 2020-05-09 120 { de4e05cac46d20 Yonghong Song 2020-05-09 121 struct bpf_link_primer link_primer; de4e05cac46d20 Yonghong Song 2020-05-09 122 struct bpf_iter_target_info *tinfo; de4e05cac46d20 Yonghong Song 2020-05-09 123 struct bpf_iter_link *link; de4e05cac46d20 Yonghong Song 2020-05-09 124 bool existed = false; de4e05cac46d20 Yonghong Song 2020-05-09 125 u32 prog_btf_id; de4e05cac46d20 Yonghong Song 2020-05-09 126 int err; de4e05cac46d20 Yonghong Song 2020-05-09 127 de4e05cac46d20 Yonghong Song 2020-05-09 128 if (attr->link_create.target_fd || attr->link_create.flags) de4e05cac46d20 Yonghong Song 2020-05-09 129 return -EINVAL; de4e05cac46d20 Yonghong Song 2020-05-09 130 de4e05cac46d20 Yonghong Song 2020-05-09 131 prog_btf_id = prog->aux->attach_btf_id; de4e05cac46d20 Yonghong Song 2020-05-09 132 mutex_lock(&targets_mutex); de4e05cac46d20 Yonghong Song 2020-05-09 @133 list_for_each_entry(tinfo, &targets, list) { de4e05cac46d20 Yonghong Song 2020-05-09 134 if (tinfo->btf_id == prog_btf_id) { de4e05cac46d20 Yonghong Song 2020-05-09 135 existed = true; de4e05cac46d20 Yonghong Song 2020-05-09 136 break; de4e05cac46d20 Yonghong Song 2020-05-09 137 } de4e05cac46d20 Yonghong Song 2020-05-09 138 } de4e05cac46d20 Yonghong Song 2020-05-09 139 mutex_unlock(&targets_mutex); de4e05cac46d20 Yonghong Song 2020-05-09 140 if (!existed) de4e05cac46d20 Yonghong Song 2020-05-09 141 return -ENOENT; de4e05cac46d20 Yonghong Song 2020-05-09 142 de4e05cac46d20 Yonghong Song 2020-05-09 143 link = kzalloc(sizeof(*link), GFP_USER | __GFP_NOWARN); de4e05cac46d20 Yonghong Song 2020-05-09 144 if (!link) de4e05cac46d20 Yonghong Song 2020-05-09 145 return -ENOMEM; de4e05cac46d20 Yonghong Song 2020-05-09 146 de4e05cac46d20 Yonghong Song 2020-05-09 147 bpf_link_init(&link->link, BPF_LINK_TYPE_ITER, &bpf_iter_link_lops, prog);
de4e05cac46d20Yonghong Song 2020-05-09 @148link->tinfo= tinfo;---
0-DAY CI Kernel Test Service, Intel Corporation
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.01.org_hyperkitty_list_kbuild-2Dall-40lists.01.org&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=PkP59UHFyGOAoJKPUFdFJnDyFmkguITHCnAlNvAC8Ps&s=wyaOKjgZYqmGKbpSGySELSko78H58Q5MgcpNoGHUW5k&e=
Quoted 11 lines · Yonghong Song
Quoted 4 lines · Julia Lawall
Hello,
If the
list_for_each_entryloop can exit normally (ie not by the break), then tinfo can be an invalid pointer after the loop.This should not happen since tinfo only accessed later when existed is true. I guess initializing tinfo = NULL will be able to silence this warning?
Sorry, I didn't notice the use of existed. It's fine as is.
julia
Quoted 96 lines
Quoted 95 lines
julia
---------- Forwarded message ----------
Date: Sun, 10 May 2020 12:01:28 +0800
From: kbuild test robot <[email protected]>
To: kbuild(a)lists.01.org
Cc: lkp(a)intel.com, Julia Lawall <[email protected]>
Subject: [bpf-next:master 801/821] kernel/bpf/bpf_iter.c:148:15-20: ERROR:
invalid reference to the index variable of the iterator on line 133CC: kbuild-all(a)lists.01.org
TO: Yonghong Song <[email protected]>
CC: Alexei Starovoitov <[email protected]>tree: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
masterhead: b4563facdcae55c83039d5efcc3b45a63da14d2f commit: de4e05cac46d206f9090051ef09930514bff73e4 [801/821] bpf: Support bpftracing/iter programs for
BPF_LINK_CREATE
:::::: branch date: 3 hours ago
:::::: commit date: 4 hours agoIf you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>Reported-by Julia Lawall <[email protected]>coccinelle warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
kernel/bpf/bpf_iter.c:148:15-20: ERROR: invalid reference to the index variable of the iterator on line 133
#
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=de4e05cac46d206f9090051ef09930514bff73e4
git remote add bpf-next
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
git remote update bpf-next
git checkoutde4e05cac46d206f9090051ef09930514bff73e4vim +148kernel/bpf/bpf_iter.c
de4e05cac46d20Yonghong Song 2020-05-09 118de4e05cac46d20Yonghong Song 2020-05-09 119 intbpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)de4e05cac46d20 Yonghong Song 2020-05-09 120 { de4e05cac46d20 Yonghong Song 2020-05-09 121 struct bpf_link_primer
link_primer;de4e05cac46d20Yonghong Song 2020-05-09 122 structbpf_iter_target_info*tinfo;de4e05cac46d20Yonghong Song 2020-05-09 123 structbpf_iter_link
*link;de4e05cac46d20 Yonghong Song 2020-05-09 124 bool existed = false; de4e05cac46d20 Yonghong Song 2020-05-09 125 u32 prog_btf_id; de4e05cac46d20 Yonghong Song 2020-05-09 126 int err; de4e05cac46d20 Yonghong Song 2020-05-09 127 de4e05cac46d20 Yonghong Song 2020-05-09 128 if(
attr->link_create.target_fd||attr->link_create.flags)de4e05cac46d20Yonghong Song 2020-05-09 129 return-EINVAL;de4e05cac46d20Yonghong Song 2020-05-09 130de4e05cac46d20Yonghong Song 2020-05-09 131prog_btf_id=prog->aux->attach_btf_id;de4e05cac46d20Yonghong Song 2020-05-09 132mutex_lock(&targets_mutex);de4e05cac46d20Yonghong Song 2020-05-09 @133list_for_each_entry(tinfo, &targets, list){de4e05cac46d20Yonghong Song 2020-05-09 134 if
(tinfo->btf_id==prog_btf_id) {de4e05cac46d20Yonghong Song 2020-05-09 135 existed = true;de4e05cac46d20 Yonghong Song 2020-05-09 136 break; de4e05cac46d20 Yonghong Song 2020-05-09 137 } de4e05cac46d20 Yonghong Song 2020-05-09 138 } de4e05cac46d20 Yonghong Song 2020-05-09 139 mutex_unlock(&targets_mutex); de4e05cac46d20 Yonghong Song 2020-05-09 140 if (!existed) de4e05cac46d20 Yonghong Song 2020-05-09 141 return
-ENOENT;de4e05cac46d20Yonghong Song 2020-05-09 142de4e05cac46d20Yonghong Song 2020-05-09 143 link =kzalloc(sizeof(*link), GFP_USER | __GFP_NOWARN);de4e05cac46d20 Yonghong Song 2020-05-09 144 if (!link) de4e05cac46d20 Yonghong Song 2020-05-09 145 return
-ENOMEM;de4e05cac46d20Yonghong Song 2020-05-09 146de4e05cac46d20Yonghong Song 2020-05-09 147bpf_link_init(&link->link, BPF_LINK_TYPE_ITER, &bpf_iter_link_lops, prog);de4e05cac46d20Yonghong Song 2020-05-09 @148link->tinfo= tinfo;---
0-DAY CI Kernel Test Service, Intel Corporation
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.01.org_hyperkitty_list_kbuild-2Dall-40lists.01.org&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=PkP59UHFyGOAoJKPUFdFJnDyFmkguITHCnAlNvAC8Ps&s=wyaOKjgZYqmGKbpSGySELSko78H58Q5MgcpNoGHUW5k&e=