1. 08 5月, 2019 1 次提交
    • Y
      configfs: fix possible use-after-free in configfs_register_group · 35399f87
      YueHaibing 提交于
      In configfs_register_group(), if create_default_group() failed, we
      forget to unlink the group. It will left a invalid item in the parent list,
      which may trigger the use-after-free issue seen below:
      
      BUG: KASAN: use-after-free in __list_add_valid+0xd4/0xe0 lib/list_debug.c:26
      Read of size 8 at addr ffff8881ef61ae20 by task syz-executor.0/5996
      
      CPU: 1 PID: 5996 Comm: syz-executor.0 Tainted: G         C        5.0.0+ #5
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0xa9/0x10e lib/dump_stack.c:113
       print_address_description+0x65/0x270 mm/kasan/report.c:187
       kasan_report+0x149/0x18d mm/kasan/report.c:317
       __list_add_valid+0xd4/0xe0 lib/list_debug.c:26
       __list_add include/linux/list.h:60 [inline]
       list_add_tail include/linux/list.h:93 [inline]
       link_obj+0xb0/0x190 fs/configfs/dir.c:759
       link_group+0x1c/0x130 fs/configfs/dir.c:784
       configfs_register_group+0x56/0x1e0 fs/configfs/dir.c:1751
       configfs_register_default_group+0x72/0xc0 fs/configfs/dir.c:1834
       ? 0xffffffffc1be0000
       iio_sw_trigger_init+0x23/0x1000 [industrialio_sw_trigger]
       do_one_initcall+0xbc/0x47d init/main.c:887
       do_init_module+0x1b5/0x547 kernel/module.c:3456
       load_module+0x6405/0x8c10 kernel/module.c:3804
       __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
       do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x462e99
      Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007f494ecbcc58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
      RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
      RDX: 0000000000000000 RSI: 0000000020000180 RDI: 0000000000000003
      RBP: 00007f494ecbcc70 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 00007f494ecbd6bc
      R13: 00000000004bcefa R14: 00000000006f6fb0 R15: 0000000000000004
      
      Allocated by task 5987:
       set_track mm/kasan/common.c:87 [inline]
       __kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:497
       kmalloc include/linux/slab.h:545 [inline]
       kzalloc include/linux/slab.h:740 [inline]
       configfs_register_default_group+0x4c/0xc0 fs/configfs/dir.c:1829
       0xffffffffc1bd0023
       do_one_initcall+0xbc/0x47d init/main.c:887
       do_init_module+0x1b5/0x547 kernel/module.c:3456
       load_module+0x6405/0x8c10 kernel/module.c:3804
       __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
       do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Freed by task 5987:
       set_track mm/kasan/common.c:87 [inline]
       __kasan_slab_free+0x130/0x180 mm/kasan/common.c:459
       slab_free_hook mm/slub.c:1429 [inline]
       slab_free_freelist_hook mm/slub.c:1456 [inline]
       slab_free mm/slub.c:3003 [inline]
       kfree+0xe1/0x270 mm/slub.c:3955
       configfs_register_default_group+0x9a/0xc0 fs/configfs/dir.c:1836
       0xffffffffc1bd0023
       do_one_initcall+0xbc/0x47d init/main.c:887
       do_init_module+0x1b5/0x547 kernel/module.c:3456
       load_module+0x6405/0x8c10 kernel/module.c:3804
       __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
       do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      The buggy address belongs to the object at ffff8881ef61ae00
       which belongs to the cache kmalloc-192 of size 192
      The buggy address is located 32 bytes inside of
       192-byte region [ffff8881ef61ae00, ffff8881ef61aec0)
      The buggy address belongs to the page:
      page:ffffea0007bd8680 count:1 mapcount:0 mapping:ffff8881f6c03000 index:0xffff8881ef61a700
      flags: 0x2fffc0000000200(slab)
      raw: 02fffc0000000200 ffffea0007ca4740 0000000500000005 ffff8881f6c03000
      raw: ffff8881ef61a700 000000008010000c 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff8881ef61ad00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
       ffff8881ef61ad80: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
      >ffff8881ef61ae00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                     ^
       ffff8881ef61ae80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
       ffff8881ef61af00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      Fixes: 5cf6a51e ("configfs: allow dynamic group creation")
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      35399f87
  2. 09 4月, 2019 1 次提交
    • G
      fs: mark expected switch fall-throughs · 0a4c9265
      Gustavo A. R. Silva 提交于
      In preparation to enabling -Wimplicit-fallthrough, mark switch cases
      where we are expecting to fall through.
      
      This patch fixes the following warnings:
      
      fs/affs/affs.h:124:38: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/configfs/dir.c:1692:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/configfs/dir.c:1694:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ceph/file.c:249:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/hash.c:233:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/hash.c:246:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext2/inode.c:1237:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext2/inode.c:1244:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1182:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1188:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1432:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1440:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/f2fs/node.c:618:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/f2fs/node.c:620:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/btrfs/ref-verify.c:522:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/gfs2/bmap.c:711:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/gfs2/bmap.c:722:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/jffs2/fs.c:339:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/nfsd/nfs4proc.c:429:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ufs/util.h:62:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ufs/util.h:43:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/fcntl.c:770:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/seq_file.c:319:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/libfs.c:148:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/libfs.c:150:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/signalfd.c:178:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/locks.c:1473:16: warning: this statement may fall through [-Wimplicit-fallthrough=]
      
      Warning level 3 was used: -Wimplicit-fallthrough=3
      
      This patch is part of the ongoing efforts to enabling
      -Wimplicit-fallthrough.
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      0a4c9265
  3. 17 7月, 2018 1 次提交
    • M
      configfs: fix registered group removal · cc57c073
      Mike Christie 提交于
      This patch fixes a bug where configfs_register_group had added
      a group in a tree, and userspace has done a rmdir on a dir somewhere
      above that group and we hit a kernel crash. The problem is configfs_rmdir
      will detach everything under it and unlink groups on the default_groups
      list. It will not unlink groups added with configfs_register_group so when
      configfs_unregister_group is called to drop its references to the group/items
      we crash when we try to access the freed dentrys.
      
      The patch just adds a check for if a rmdir has been done above
      us and if so just does the unlink part of unregistration.
      
      Sorry if you are getting this multiple times. I thouhgt I sent
      this to some of you and lkml, but I do not see it.
      Signed-off-by: NMike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Joel Becker <jlbec@evilplan.org>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      cc57c073
  4. 19 10月, 2017 1 次提交
    • B
      configfs: make ci_type field, some pointers and function arguments const · aa293583
      Bhumika Goyal 提交于
      The ci_type field of the config_item structure do not modify the fields
      of the config_item_type structure it points to. And the other pointers
      initialized with ci_type do not modify the fields as well.
      So, make the ci_type field and the pointers initialized with ci_type
      as const.
      
      Make the struct config_item_type *type function argument of functions
      config_{item/group}_init_type_name const as the argument in both the
      functions is only stored in the ci_type field of a config_item structure
      which is now made const.
      Make the argument of configfs_register_default_group const as it is
      only passed to the argument of the function config_group_init_type_name
      which is now const.
      Signed-off-by: NBhumika Goyal <bhumirks@gmail.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      aa293583
  5. 09 5月, 2016 1 次提交
  6. 03 5月, 2016 1 次提交
  7. 14 3月, 2016 1 次提交
  8. 06 3月, 2016 1 次提交
  9. 23 1月, 2016 1 次提交
    • A
      wrappers for ->i_mutex access · 5955102c
      Al Viro 提交于
      parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
      inode_foo(inode) being mutex_foo(&inode->i_mutex).
      
      Please, use those for access to ->i_mutex; over the coming cycle
      ->i_mutex will become rwsem, with ->lookup() done with it held
      only shared.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      5955102c
  10. 04 1月, 2016 1 次提交
    • P
      configfs: implement binary attributes · 03607ace
      Pantelis Antoniou 提交于
      ConfigFS lacked binary attributes up until now. This patch
      introduces support for binary attributes in a somewhat similar
      manner of sysfs binary attributes albeit with changes that
      fit the configfs usage model.
      
      Problems that configfs binary attributes fix are everything that
      requires a binary blob as part of the configuration of a resource,
      such as bitstream loading for FPGAs, DTBs for dynamically created
      devices etc.
      
      Look at Documentation/filesystems/configfs/configfs.txt for internals
      and howto use them.
      
      This patch is against linux-next as of today that contains
      Christoph's configfs rework.
      Signed-off-by: NPantelis Antoniou <pantelis.antoniou@konsulko.com>
      [hch: folded a fix from Geert Uytterhoeven <geert+renesas@glider.be>]
      [hch: a few tiny updates based on review feedback]
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      03607ace
  11. 21 12月, 2015 4 次提交
    • K
      fs: configfs: Add unlocked version of configfs_depend_item() · d79d75b5
      Krzysztof Opasiak 提交于
      This change is necessary for the SCSI target usb gadget composed with
      configfs. In this case configfs will be used for two different purposes:
      to compose a usb gadget and to configure the target part. If an instance
      of tcm function is created in $CONFIGFS_ROOT/usb_gadget/<gadget>/functions
      a tpg can be created in $CONFIGFS_ROOT/target/usb_gadget/<wwn>/, but after
      a tpg is created the tcm function must not be removed until its
      corresponding tpg is gone. While the configfs_depend/undepend_item() are
      meant exactly for creating this kind of dependencies, they are not suitable
      if the other kernel subsystem happens to be another subsystem in configfs,
      so this patch adds unlocked versions meant for configfs callbacks.
      
      Above description has been provided by:
      Andrzej Pietrasiewicz <andrzej.p@samsung.com>
      
      In configfs_depend_item() we have to consider two possible cases:
      
      1) When we are called to depend another item in the same subsystem
         as caller
      	In this case we should skip locking configfs root as we know
      	that configfs is in valid state and our subsystem will not
      	be unregistered during this call.
      
      2) When we are called to depend item in different subsystem than
         our caller
      	In this case we are also sure that configfs is in valid state
      	but we have to lock root of configfs to avoid unregistration
      	of target's subsystem. As it is other than caller's subsystem,
      	there may be nothing what protects us against unregistration
      	of that subsystem.
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      d79d75b5
    • K
      fs: configfs: Factor out configfs_find_subsys_dentry() · 9a70adff
      Krzysztof Opasiak 提交于
      configfs_depend_item() is quite complicated and should
      be split up into smaller functions. This also allow to
      share this code with other functions.
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      9a70adff
    • K
      fs: configfs: Factor out configfs_do_depend_item() · 9fb434e7
      Krzysztof Opasiak 提交于
      configfs_depend_item() is quite complicated and should
      be split up into smaller functions. This also allow to
      share this code with other functions.
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      9fb434e7
    • K
      fs: configfs: Drop unused parameter from configfs_undepend_item() · 9a9e3415
      Krzysztof Opasiak 提交于
      subsys parameter is never used by configfs_undepend_item()
      so there is no point in passing it to this function.
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      9a9e3415
  12. 21 11月, 2015 1 次提交
    • D
      configfs: allow dynamic group creation · 5cf6a51e
      Daniel Baluta 提交于
      This patchset introduces IIO software triggers, offers a way of configuring
      them via configfs and adds the IIO hrtimer based interrupt source to be used
      with software triggers.
      
      The architecture is now split in 3 parts, to remove all IIO trigger specific
      parts from IIO configfs core:
      
      (1) IIO configfs - creates the root of the IIO configfs subsys.
      (2) IIO software triggers - software trigger implementation, dynamically
          creating /config/iio/triggers group.
      (3) IIO hrtimer trigger - is the first interrupt source for software triggers
          (with syfs to follow). Each trigger type can implement its own set of
          attributes.
      
      Lockdep seems to be happy with the locking in configfs patch.
      
      This patch (of 5):
      
      We don't want to hardcode default groups at subsystem
      creation time. We export:
      	* configfs_register_group
      	* configfs_unregister_group
      to allow drivers to programatically create/destroy groups
      later, after module init time.
      
      This is needed for IIO configfs support.
      
      (akpm: the other 4 patches to be merged via the IIO tree)
      Signed-off-by: NDaniel Baluta <daniel.baluta@intel.com>
      Suggested-by: NLars-Peter Clausen <lars@metafoo.de>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Acked-by: NJoel Becker <jlbec@evilplan.org>
      Cc: Hartmut Knaack <knaack.h@gmx.de>
      Cc: Octavian Purdila <octavian.purdila@intel.com>
      Cc: Paul Bolle <pebolle@tiscali.nl>
      Cc: Adriana Reus <adriana.reus@intel.com>
      Cc: Cristina Opriceana <cristina.opriceana@gmail.com>
      Cc: Peter Meerwald <pmeerw@pmeerw.net>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5cf6a51e
  13. 16 4月, 2015 2 次提交
  14. 18 2月, 2015 2 次提交
  15. 20 11月, 2014 1 次提交
  16. 05 6月, 2014 2 次提交
  17. 22 11月, 2013 1 次提交
    • J
      configfs: fix race between dentry put and lookup · 76ae281f
      Junxiao Bi 提交于
      A race window in configfs, it starts from one dentry is UNHASHED and end
      before configfs_d_iput is called.  In this window, if a lookup happen,
      since the original dentry was UNHASHED, so a new dentry will be
      allocated, and then in configfs_attach_attr(), sd->s_dentry will be
      updated to the new dentry.  Then in configfs_d_iput(),
      BUG_ON(sd->s_dentry != dentry) will be triggered and system panic.
      
      sys_open:                     sys_close:
       ...                           fput
                                      dput
                                       dentry_kill
                                        __d_drop <--- dentry unhashed here,
                                                 but sd->dentry still point
                                                 to this dentry.
      
       lookup_real
        configfs_lookup
         configfs_attach_attr---> update sd->s_dentry
                                  to new allocated dentry here.
      
                                         d_kill
                                           configfs_d_iput <--- BUG_ON(sd->s_dentry != dentry)
                                                           triggered here.
      
      To fix it, change configfs_d_iput to not update sd->s_dentry if
      sd->s_count > 2, that means there are another dentry is using the sd
      beside the one that is going to be put.  Use configfs_dirent_lock in
      configfs_attach_attr to sync with configfs_d_iput.
      
      With the following steps, you can reproduce the bug.
      
      1. enable ocfs2, this will mount configfs at /sys/kernel/config and
         fill configure in it.
      
      2. run the following script.
      	while [ 1 ]; do cat /sys/kernel/config/cluster/$your_cluster_name/idle_timeout_ms > /dev/null; done &
      	while [ 1 ]; do cat /sys/kernel/config/cluster/$your_cluster_name/idle_timeout_ms > /dev/null; done &
      Signed-off-by: NJunxiao Bi <junxiao.bi@oracle.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      76ae281f
  18. 16 11月, 2013 1 次提交
  19. 14 7月, 2013 1 次提交
  20. 29 6月, 2013 1 次提交
  21. 23 2月, 2013 1 次提交
  22. 22 2月, 2013 1 次提交
  23. 18 12月, 2012 1 次提交
  24. 14 7月, 2012 1 次提交
    • A
      stop passing nameidata to ->lookup() · 00cd8dd3
      Al Viro 提交于
      Just the flags; only NFS cares even about that, but there are
      legitimate uses for such argument.  And getting rid of that
      completely would require splitting ->lookup() into a couple
      of methods (at least), so let's leave that alone for now...
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      00cd8dd3
  25. 21 3月, 2012 4 次提交
  26. 04 1月, 2012 3 次提交
  27. 28 5月, 2011 1 次提交
  28. 26 5月, 2011 1 次提交
  29. 18 5月, 2011 1 次提交
    • J
      configfs: Fix race between configfs_readdir() and configfs_d_iput() · 24307aa1
      Joel Becker 提交于
      configfs_readdir() will use the existing inode numbers of inodes in the
      dcache, but it makes them up for attribute files that aren't currently
      instantiated.  There is a race where a closing attribute file can be
      tearing down at the same time as configfs_readdir() is trying to get its
      inode number.
      
      We want to get the inode number of open attribute files, because they
      should match while instantiated.  We can't lock down the transition
      where dentry->d_inode is set to NULL, so we just check for NULL there.
      We can, however, ensure that an inode we find isn't iput() in
      configfs_d_iput() until after we've accessed it.
      Signed-off-by: NJoel Becker <jlbec@evilplan.org>
      24307aa1