1. 06 4月, 2013 1 次提交
    • M
      sysfs: check if one entry has been removed before freeing · bb2b0051
      Ming Lei 提交于
      It might be a kernel disaster if one sysfs entry is freed but
      still referenced by sysfs tree.
      
      Recently Dave and Sasha reported one use-after-free problem on
      sysfs entry, and the problem has been troubleshooted with help
      of debug message added in this patch.
      
      Given sysfs_get_dirent/sysfs_put are exported APIs, even inside
      sysfs they are called in many contexts(kobject/attribe add/delete,
      inode init/drop, dentry lookup/release, readdir, ...), it is healthful
      to check the removed flag before freeing one entry and dump message
      if it is freeing without being removed first.
      
      Cc: Dave Jones <davej@redhat.com>
      Cc: Sasha Levin <levinsasha928@gmail.com>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bb2b0051
  2. 04 4月, 2013 1 次提交
  3. 26 3月, 2013 1 次提交
  4. 21 3月, 2013 2 次提交
  5. 25 10月, 2012 1 次提交
  6. 18 7月, 2012 2 次提交
  7. 14 7月, 2012 4 次提交
  8. 15 5月, 2012 1 次提交
    • A
      sysfs: get rid of some lockdep false positives · 356c05d5
      Alan Stern 提交于
      This patch (as1554) fixes a lockdep false-positive report.  The
      problem arises because lockdep is unable to deal with the
      tree-structured locks created by the device core and sysfs.
      
      This particular problem involves a sysfs attribute method that
      unregisters itself, not from the device it was called for, but from a
      descendant device.  Lockdep doesn't understand the distinction and
      reports a possible deadlock, even though the operation is safe.
      
      This is the sort of thing that would normally be handled by using a
      nested lock annotation; unfortunately it's not feasible to do that
      here.  There's no sensible way to tell sysfs when attribute removal
      occurs in the context of a parent attribute method.
      
      As a workaround, the patch adds a new flag to struct attribute
      telling sysfs not to inform lockdep when it acquires a readlock on a
      sysfs_dirent instance for the attribute.  The readlock is still
      acquired, but lockdep doesn't know about it and hence does not
      complain about impossible deadlock scenarios.
      
      Also added are macros for static initialization of attribute
      structures with the ignore_lockdep flag set.  The three offending
      attributes in the USB subsystem are converted to use the new macros.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Acked-by: NTejun Heo <tj@kernel.org>
      CC: Eric W. Biederman <ebiederm@xmission.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      356c05d5
  9. 03 5月, 2012 1 次提交
  10. 11 4月, 2012 1 次提交
    • D
      sysfs: handle 'parent deleted before child added' · 3a198886
      Dan Williams 提交于
      In scsi at least two cases of the parent device being deleted before the
      child is added have been observed.
      
      1/ scsi is performing async scans and the device is removed prior to the
         async can thread running (can happen with an in-opportune / unlikely
         unplug during initial scan).
      
      2/ libsas discovery event running after the parent port has been torn
         down (this is a bug in libsas).
      
      Result in crash signatures like:
       BUG: unable to handle kernel NULL pointer dereference at 0000000000000098
       IP: [<ffffffff8115e100>] sysfs_create_dir+0x32/0xb6
       ...
       Process scsi_scan_8 (pid: 5417, threadinfo ffff88080bd16000, task ffff880801b8a0b0)
       Stack:
        00000000fffffffe ffff880813470628 ffff88080bd17cd0 ffff88080614b7e8
        ffff88080b45c108 00000000fffffffe ffff88080bd17d20 ffffffff8125e4a8
        ffff88080bd17cf0 ffffffff81075149 ffff88080bd17d30 ffff88080614b7e8
       Call Trace:
        [<ffffffff8125e4a8>] kobject_add_internal+0x120/0x1e3
        [<ffffffff81075149>] ? trace_hardirqs_on+0xd/0xf
        [<ffffffff8125e641>] kobject_add_varg+0x41/0x50
        [<ffffffff8125e70b>] kobject_add+0x64/0x66
        [<ffffffff8131122b>] device_add+0x12d/0x63a
      
      In this scenario the parent is still valid (because we have a
      reference), but it has been device_del()'d which means its kobj->sd
      pointer is NULL'd via:
      
       device_del()->kobject_del()->sysfs_remove_dir()
      
      ...and then sysfs_create_dir() (without this fix) goes ahead and
      de-references parent_sd via sysfs_ns_type():
      
       return (sd->s_flags & SYSFS_NS_TYPE_MASK) >> SYSFS_NS_TYPE_SHIFT;
      
      This scenario is being fixed in scsi/libsas, but if other subsystems
      present the same ordering the system need not immediately crash.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: James Bottomley <JBottomley@parallels.com>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3a198886
  11. 10 4月, 2012 1 次提交
  12. 09 3月, 2012 1 次提交
  13. 01 2月, 2012 1 次提交
  14. 25 1月, 2012 3 次提交
  15. 02 11月, 2011 1 次提交
    • E
      sysfs: Make sysfs_rename safe with sysfs_dirents in rbtrees. · f6d90b4f
      Eric W. Biederman 提交于
      In sysfs_rename we need to remove the optimization of not calling
      sysfs_unlink_sibling and sysfs_link_sibling if the renamed parent
      directory is not changing.  This optimization is no longer valid now
      that sysfs dirents are stored in an rbtree sorted by name.
      
      Move the assignment of s_ns before the call of sysfs_link_sibling.  With
      no sysfs_dirent fields changing after the call of sysfs_link_sibling
      this allows sysfs_link_sibling to take any of the directory entries into
      account when it builds the rbtrees, and s_ns looks like a prime canidate
      to be used in the rbtree in the future.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Cc: Jiri Slaby <jirislaby@gmail.com>
      Cc: Greg KH <gregkh@suse.de>
      Cc: David Miller <davem@davemloft.net>
      Cc: Mikulas Patocka <mpatocka@redhat.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      f6d90b4f
  16. 25 10月, 2011 1 次提交
  17. 20 10月, 2011 2 次提交
  18. 27 9月, 2011 1 次提交
  19. 23 8月, 2011 4 次提交
  20. 07 1月, 2011 3 次提交
    • N
      fs: rcu-walk aware d_revalidate method · 34286d66
      Nick Piggin 提交于
      Require filesystems be aware of .d_revalidate being called in rcu-walk
      mode (nd->flags & LOOKUP_RCU). For now do a simple push down, returning
      -ECHILD from all implementations.
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      34286d66
    • N
      fs: dcache reduce branches in lookup path · fb045adb
      Nick Piggin 提交于
      Reduce some branches and memory accesses in dcache lookup by adding dentry
      flags to indicate common d_ops are set, rather than having to check them.
      This saves a pointer memory access (dentry->d_op) in common path lookup
      situations, and saves another pointer load and branch in cases where we
      have d_op but not the particular operation.
      
      Patched with:
      
      git grep -E '[.>]([[:space:]])*d_op([[:space:]])*=' | xargs sed -e 's/\([^\t ]*\)->d_op = \(.*\);/d_set_d_op(\1, \2);/' -e 's/\([^\t ]*\)\.d_op = \(.*\);/d_set_d_op(\&\1, \2);/' -i
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      fb045adb
    • N
      fs: change d_delete semantics · fe15ce44
      Nick Piggin 提交于
      Change d_delete from a dentry deletion notification to a dentry caching
      advise, more like ->drop_inode. Require it to be constant and idempotent,
      and not take d_lock. This is how all existing filesystems use the callback
      anyway.
      
      This makes fine grained dentry locking of dput and dentry lru scanning
      much simpler.
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      fe15ce44
  21. 22 5月, 2010 3 次提交
    • E
      sysfs: Implement sysfs tagged directory support. · 3ff195b0
      Eric W. Biederman 提交于
      The problem.  When implementing a network namespace I need to be able
      to have multiple network devices with the same name.  Currently this
      is a problem for /sys/class/net/*, /sys/devices/virtual/net/*, and
      potentially a few other directories of the form /sys/ ... /net/*.
      
      What this patch does is to add an additional tag field to the
      sysfs dirent structure.  For directories that should show different
      contents depending on the context such as /sys/class/net/, and
      /sys/devices/virtual/net/ this tag field is used to specify the
      context in which those directories should be visible.  Effectively
      this is the same as creating multiple distinct directories with
      the same name but internally to sysfs the result is nicer.
      
      I am calling the concept of a single directory that looks like multiple
      directories all at the same path in the filesystem tagged directories.
      
      For the networking namespace the set of directories whose contents I need
      to filter with tags can depend on the presence or absence of hotplug
      hardware or which modules are currently loaded.  Which means I need
      a simple race free way to setup those directories as tagged.
      
      To achieve a reace free design all tagged directories are created
      and managed by sysfs itself.
      
      Users of this interface:
      - define a type in the sysfs_tag_type enumeration.
      - call sysfs_register_ns_types with the type and it's operations
      - sysfs_exit_ns when an individual tag is no longer valid
      
      - Implement mount_ns() which returns the ns of the calling process
        so we can attach it to a sysfs superblock.
      - Implement ktype.namespace() which returns the ns of a syfs kobject.
      
      Everything else is left up to sysfs and the driver layer.
      
      For the network namespace mount_ns and namespace() are essentially
      one line functions, and look to remain that.
      
      Tags are currently represented a const void * pointers as that is
      both generic, prevides enough information for equality comparisons,
      and is trivial to create for current users, as it is just the
      existing namespace pointer.
      
      The work needed in sysfs is more extensive.  At each directory
      or symlink creating I need to check if the directory it is being
      created in is a tagged directory and if so generate the appropriate
      tag to place on the sysfs_dirent.  Likewise at each symlink or
      directory removal I need to check if the sysfs directory it is
      being removed from is a tagged directory and if so figure out
      which tag goes along with the name I am deleting.
      
      Currently only directories which hold kobjects, and
      symlinks are supported.  There is not enough information
      in the current file attribute interfaces to give us anything
      to discriminate on which makes it useless, and there are
      no potential users which makes it an uninteresting problem
      to solve.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: NBenjamin Thery <benjamin.thery@bull.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      3ff195b0
    • S
      sysfs: Comment sysfs directory tagging logic · be867b19
      Serge E. Hallyn 提交于
      Add some in-line comments to explain the new infrastructure, which
      was introduced to support sysfs directory tagging with namespaces.
      I think an overall description someplace might be good too, but it
      didn't really seem to fit into Documentation/filesystems/sysfs.txt,
      which appears more geared toward users, rather than maintainers, of
      sysfs.
      
      (Tejun, please let me know if I can make anything clearer or failed
      altogether to comment something that should be commented.)
      Signed-off-by: NSerge E. Hallyn <serue@us.ibm.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      be867b19
    • E
      sysfs: Add support for tagged directories with untagged members. · af10ec77
      Eric W. Biederman 提交于
      I had hopped to avoid this but the bonding driver adds a file
      to /sys/class/net/  and the easiest way to handle that file is
      to make it untagged and to register it only once.
      
      So relax the rules on tagged directories, and make bonding work.
      Signed-off-by: NEric W. Biederman <ebiederm@aristanetworks.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      af10ec77
  22. 08 3月, 2010 4 次提交