All of lore.kernel.org
 help / color / mirror / Atom feed
* [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 (fwd)
@ 2020-05-10 13:35 Julia Lawall
  2020-05-10 17:23 ` Yonghong Song
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2020-05-10 13:35 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3908 bytes --]

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 <lkp@intel.com>
To: kbuild(a)lists.01.org
Cc: lkp(a)intel.com, Julia Lawall <julia.lawall@lip6.fr>
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 <yhs@fb.com>
CC: Alexei Starovoitov <ast@kernel.org>

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
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>


coccinelle warnings: (new ones prefixed by >>)

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [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 (fwd)
  2020-05-10 13:35 [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 (fwd) Julia Lawall
@ 2020-05-10 17:23 ` Yonghong Song
  2020-05-10 17:26   ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2020-05-10 17:23 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4467 bytes --]



On 5/10/20 6:35 AM, Julia Lawall wrote:
> 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.

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?

> 
> julia
> 
> 
> ---------- Forwarded message ----------
> Date: Sun, 10 May 2020 12:01:28 +0800
> From: kbuild test robot <lkp@intel.com>
> To: kbuild(a)lists.01.org
> Cc: lkp(a)intel.com, Julia Lawall <julia.lawall@lip6.fr>
> 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 <yhs@fb.com>
> CC: Alexei Starovoitov <ast@kernel.org>
> 
> 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
> Reported-by: kbuild test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@lip6.fr>
> 
> 
> coccinelle warnings: (new ones prefixed by >>)
> 
>>> 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://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=
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [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 (fwd)
  2020-05-10 17:23 ` Yonghong Song
@ 2020-05-10 17:26   ` Julia Lawall
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2020-05-10 17:26 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4846 bytes --]



On Sun, 10 May 2020, Yonghong Song wrote:

>
>
> On 5/10/20 6:35 AM, Julia Lawall wrote:
> > 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.
>
> 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


>
> >
> > julia
> >
> >
> > ---------- Forwarded message ----------
> > Date: Sun, 10 May 2020 12:01:28 +0800
> > From: kbuild test robot <lkp@intel.com>
> > To: kbuild(a)lists.01.org
> > Cc: lkp(a)intel.com, Julia Lawall <julia.lawall@lip6.fr>
> > 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 <yhs@fb.com>
> > CC: Alexei Starovoitov <ast@kernel.org>
> >
> > 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
> > Reported-by: kbuild test robot <lkp@intel.com>
> > Reported-by: Julia Lawall <julia.lawall@lip6.fr>
> >
> >
> > coccinelle warnings: (new ones prefixed by >>)
> >
> > > > 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://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=
> >
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-10 17:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-10 13:35 [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 (fwd) Julia Lawall
2020-05-10 17:23 ` Yonghong Song
2020-05-10 17:26   ` Julia Lawall

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.