CC: [email protected]
CC: [email protected]
TO: "Andrii, Nakryiko," <[email protected]>
CC: Alexei Starovoitov <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   f359287765c04711ff54fbd11645271d8e5ff763
commit: af6eea57437a830293eab56246b6025cc7d46ee7 bpf: Implement bpf_link-based 
cgroup BPF program attachment
date:   9 weeks ago
:::::: branch date: 4 hours ago
:::::: commit date: 9 weeks ago
config: i386-randconfig-m021-20200602 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
kernel/bpf/cgroup.c:455 __cgroup_bpf_attach() error: we previously assumed 
'link' could be null (see line 430)

# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=af6eea57437a830293eab56246b6025cc7d46ee7
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git remote update linus
git checkout af6eea57437a830293eab56246b6025cc7d46ee7
vim +/link +455 kernel/bpf/cgroup.c

af6eea57437a83 Andrii Nakryiko    2020-03-29  399  
3007098494bec6 Daniel Mack        2016-11-23  400  /**
af6eea57437a83 Andrii Nakryiko    2020-03-29  401   * __cgroup_bpf_attach() - 
Attach the program or the link to a cgroup, and
3007098494bec6 Daniel Mack        2016-11-23  402   *                         
propagate the change to descendants
3007098494bec6 Daniel Mack        2016-11-23  403   * @cgrp: The cgroup which 
descendants to traverse
324bda9e6c5add Alexei Starovoitov 2017-10-02  404   * @prog: A program to attach
af6eea57437a83 Andrii Nakryiko    2020-03-29  405   * @link: A link to attach
7dd68b3279f179 Andrey Ignatov     2019-12-18  406   * @replace_prog: Previously 
attached program to replace if BPF_F_REPLACE is set
324bda9e6c5add Alexei Starovoitov 2017-10-02  407   * @type: Type of attach 
operation
1832f4ef5867fd Valdis Kletnieks   2019-01-29  408   * @flags: Option flags
3007098494bec6 Daniel Mack        2016-11-23  409   *
af6eea57437a83 Andrii Nakryiko    2020-03-29  410   * Exactly one of @prog or 
@link can be non-null.
3007098494bec6 Daniel Mack        2016-11-23  411   * Must be called with 
cgroup_mutex held.
3007098494bec6 Daniel Mack        2016-11-23  412   */
af6eea57437a83 Andrii Nakryiko    2020-03-29  413  int 
__cgroup_bpf_attach(struct cgroup *cgrp,
af6eea57437a83 Andrii Nakryiko    2020-03-29  414                       struct 
bpf_prog *prog, struct bpf_prog *replace_prog,
af6eea57437a83 Andrii Nakryiko    2020-03-29  415                       struct 
bpf_cgroup_link *link,
324bda9e6c5add Alexei Starovoitov 2017-10-02  416                       enum 
bpf_attach_type type, u32 flags)
3007098494bec6 Daniel Mack        2016-11-23  417  {
7dd68b3279f179 Andrey Ignatov     2019-12-18  418       u32 saved_flags = 
(flags & (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI));
324bda9e6c5add Alexei Starovoitov 2017-10-02  419       struct list_head *progs 
= &cgrp->bpf.progs[type];
324bda9e6c5add Alexei Starovoitov 2017-10-02  420       struct bpf_prog 
*old_prog = NULL;
8bad74f9840f87 Roman Gushchin     2018-09-28  421       struct 
bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE],
8bad74f9840f87 Roman Gushchin     2018-09-28  422               
*old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {NULL};
af6eea57437a83 Andrii Nakryiko    2020-03-29  423       struct bpf_prog_list 
*pl;
324bda9e6c5add Alexei Starovoitov 2017-10-02  424       int err;
324bda9e6c5add Alexei Starovoitov 2017-10-02  425  
7dd68b3279f179 Andrey Ignatov     2019-12-18  426       if (((flags & 
BPF_F_ALLOW_OVERRIDE) && (flags & BPF_F_ALLOW_MULTI)) ||
7dd68b3279f179 Andrey Ignatov     2019-12-18  427           ((flags & 
BPF_F_REPLACE) && !(flags & BPF_F_ALLOW_MULTI)))
324bda9e6c5add Alexei Starovoitov 2017-10-02  428               /* invalid 
combination */
324bda9e6c5add Alexei Starovoitov 2017-10-02  429               return -EINVAL;
af6eea57437a83 Andrii Nakryiko    2020-03-29 @430       if (link && (prog || 
replace_prog))
af6eea57437a83 Andrii Nakryiko    2020-03-29  431               /* only either 
link or prog/replace_prog can be specified */
af6eea57437a83 Andrii Nakryiko    2020-03-29  432               return -EINVAL;
af6eea57437a83 Andrii Nakryiko    2020-03-29  433       if (!!replace_prog != 
!!(flags & BPF_F_REPLACE))
af6eea57437a83 Andrii Nakryiko    2020-03-29  434               /* replace_prog 
implies BPF_F_REPLACE, and vice versa */
af6eea57437a83 Andrii Nakryiko    2020-03-29  435               return -EINVAL;
324bda9e6c5add Alexei Starovoitov 2017-10-02  436  
9fab329d6a04c0 Andrey Ignatov     2019-12-18  437       if 
(!hierarchy_allows_attach(cgrp, type))
7f677633379b4a Alexei Starovoitov 2017-02-10  438               return -EPERM;
7f677633379b4a Alexei Starovoitov 2017-02-10  439  
7dd68b3279f179 Andrey Ignatov     2019-12-18  440       if (!list_empty(progs) 
&& cgrp->bpf.flags[type] != saved_flags)
324bda9e6c5add Alexei Starovoitov 2017-10-02  441               /* Disallow 
attaching non-overridable on top
324bda9e6c5add Alexei Starovoitov 2017-10-02  442                * of existing 
overridable in this cgroup.
324bda9e6c5add Alexei Starovoitov 2017-10-02  443                * Disallow 
attaching multi-prog if overridable or none
7f677633379b4a Alexei Starovoitov 2017-02-10  444                */
7f677633379b4a Alexei Starovoitov 2017-02-10  445               return -EPERM;
7f677633379b4a Alexei Starovoitov 2017-02-10  446  
324bda9e6c5add Alexei Starovoitov 2017-10-02  447       if 
(prog_list_length(progs) >= BPF_CGROUP_MAX_PROGS)
324bda9e6c5add Alexei Starovoitov 2017-10-02  448               return -E2BIG;
324bda9e6c5add Alexei Starovoitov 2017-10-02  449  
af6eea57437a83 Andrii Nakryiko    2020-03-29  450       pl = 
find_attach_entry(progs, prog, link, replace_prog,
af6eea57437a83 Andrii Nakryiko    2020-03-29  451                              
flags & BPF_F_ALLOW_MULTI);
af6eea57437a83 Andrii Nakryiko    2020-03-29  452       if (IS_ERR(pl))
af6eea57437a83 Andrii Nakryiko    2020-03-29  453               return 
PTR_ERR(pl);
324bda9e6c5add Alexei Starovoitov 2017-10-02  454  
af6eea57437a83 Andrii Nakryiko    2020-03-29 @455       if 
(bpf_cgroup_storages_alloc(storage, prog ? : link->link.prog))
324bda9e6c5add Alexei Starovoitov 2017-10-02  456               return -ENOMEM;
d7bf2c10af0531 Roman Gushchin     2018-08-02  457  
af6eea57437a83 Andrii Nakryiko    2020-03-29  458       if (pl) {
1020c1f24a946e Andrey Ignatov     2019-12-18  459               old_prog = 
pl->prog;
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  460               
bpf_cgroup_storages_unlink(pl->storage);
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  461               
bpf_cgroup_storages_assign(old_storage, pl->storage);
324bda9e6c5add Alexei Starovoitov 2017-10-02  462       } else {
324bda9e6c5add Alexei Starovoitov 2017-10-02  463               pl = 
kmalloc(sizeof(*pl), GFP_KERNEL);
d7bf2c10af0531 Roman Gushchin     2018-08-02  464               if (!pl) {
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  465                       
bpf_cgroup_storages_free(storage);
324bda9e6c5add Alexei Starovoitov 2017-10-02  466                       return 
-ENOMEM;
d7bf2c10af0531 Roman Gushchin     2018-08-02  467               }
324bda9e6c5add Alexei Starovoitov 2017-10-02  468               
list_add_tail(&pl->node, progs);
324bda9e6c5add Alexei Starovoitov 2017-10-02  469       }
1020c1f24a946e Andrey Ignatov     2019-12-18  470  
324bda9e6c5add Alexei Starovoitov 2017-10-02  471       pl->prog = prog;
af6eea57437a83 Andrii Nakryiko    2020-03-29  472       pl->link = link;
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  473       
bpf_cgroup_storages_assign(pl->storage, storage);
7dd68b3279f179 Andrey Ignatov     2019-12-18  474       cgrp->bpf.flags[type] = 
saved_flags;
324bda9e6c5add Alexei Starovoitov 2017-10-02  475  
85fc4b16aaf05f Roman Gushchin     2018-08-06  476       err = 
update_effective_progs(cgrp, type);
324bda9e6c5add Alexei Starovoitov 2017-10-02  477       if (err)
324bda9e6c5add Alexei Starovoitov 2017-10-02  478               goto cleanup;
324bda9e6c5add Alexei Starovoitov 2017-10-02  479  
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  480       
bpf_cgroup_storages_free(old_storage);
af6eea57437a83 Andrii Nakryiko    2020-03-29  481       if (old_prog)
324bda9e6c5add Alexei Starovoitov 2017-10-02  482               
bpf_prog_put(old_prog);
af6eea57437a83 Andrii Nakryiko    2020-03-29  483       else
af6eea57437a83 Andrii Nakryiko    2020-03-29  484               
static_branch_inc(&cgroup_bpf_enabled_key);
af6eea57437a83 Andrii Nakryiko    2020-03-29  485       
bpf_cgroup_storages_link(pl->storage, cgrp, type);
324bda9e6c5add Alexei Starovoitov 2017-10-02  486       return 0;
324bda9e6c5add Alexei Starovoitov 2017-10-02  487  
324bda9e6c5add Alexei Starovoitov 2017-10-02  488  cleanup:
af6eea57437a83 Andrii Nakryiko    2020-03-29  489       if (old_prog) {
324bda9e6c5add Alexei Starovoitov 2017-10-02  490               pl->prog = 
old_prog;
af6eea57437a83 Andrii Nakryiko    2020-03-29  491               pl->link = NULL;
af6eea57437a83 Andrii Nakryiko    2020-03-29  492       }
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  493       
bpf_cgroup_storages_free(pl->storage);
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  494       
bpf_cgroup_storages_assign(pl->storage, old_storage);
00c4eddf7ee5cb Andrii Nakryiko    2020-03-24  495       
bpf_cgroup_storages_link(pl->storage, cgrp, type);
af6eea57437a83 Andrii Nakryiko    2020-03-29  496       if (!old_prog) {
324bda9e6c5add Alexei Starovoitov 2017-10-02  497               
list_del(&pl->node);
324bda9e6c5add Alexei Starovoitov 2017-10-02  498               kfree(pl);
324bda9e6c5add Alexei Starovoitov 2017-10-02  499       }
324bda9e6c5add Alexei Starovoitov 2017-10-02  500       return err;
324bda9e6c5add Alexei Starovoitov 2017-10-02  501  }
324bda9e6c5add Alexei Starovoitov 2017-10-02  502  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to