1. 08 11月, 2017 6 次提交
    • G
      debugfs: Remove redundant license text · 2b2d8788
      Greg Kroah-Hartman 提交于
      Now that the SPDX tag is in all debugfs files, that identifies the
      license in a specific and legally-defined manner.  So the extra GPL text
      wording can be removed as it is no longer needed at all.
      
      This is done on a quest to remove the 700+ different ways that files in
      the kernel describe the GPL license text.  And there's unneeded stuff
      like the address (sometimes incorrect) for the FSF which is never
      needed.
      
      No copyright headers or other non-license-description text was removed.
      
      Cc: Nicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b2d8788
    • G
      debugfs: add SPDX identifiers to all debugfs files · 3bce94fd
      Greg Kroah-Hartman 提交于
      It's good to have SPDX identifiers in all files to make it easier to
      audit the kernel tree for correct licenses.
      
      Update the debugfs files files with the correct SPDX license identifier
      based on the license text in the file itself.  The SPDX identifier is a
      legally binding shorthand, which can be used instead of the full boiler
      plate text.
      
      This work is based on a script and data from Thomas Gleixner, Philippe
      Ombredanne, and Kate Stewart.
      
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Nicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3bce94fd
    • N
      debugfs: purge obsolete SRCU based removal protection · c9afbec2
      Nicolai Stange 提交于
      Purge the SRCU based file removal race protection in favour of the new,
      refcount based debugfs_file_get()/debugfs_file_put() API.
      
      Fixes: 49d200de ("debugfs: prevent access to removed files' private data")
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c9afbec2
    • N
      debugfs: debugfs_real_fops(): drop __must_hold sparse annotation · 055ab8e3
      Nicolai Stange 提交于
      Currently, debugfs_real_fops() is annotated with a
      __must_hold(&debugfs_srcu) sparse annotation.
      
      With the conversion of the SRCU based protection of users against
      concurrent file removals to a per-file refcount based scheme, this becomes
      wrong.
      
      Drop this annotation.
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      055ab8e3
    • N
      debugfs: implement per-file removal protection · e9117a5a
      Nicolai Stange 提交于
      Since commit 49d200de ("debugfs: prevent access to removed files'
      private data"), accesses to a file's private data are protected from
      concurrent removal by covering all file_operations with a SRCU read section
      and sychronizing with those before returning from debugfs_remove() by means
      of synchronize_srcu().
      
      As pointed out by Johannes Berg, there are debugfs files with forever
      blocking file_operations. Their corresponding SRCU read side sections would
      block any debugfs_remove() forever as well, even unrelated ones. This
      results in a livelock. Because a remover can't cancel any indefinite
      blocking within foreign files, this is a problem.
      
      Resolve this by introducing support for more granular protection on a
      per-file basis.
      
      This is implemented by introducing an  'active_users' refcount_t to the
      per-file struct debugfs_fsdata state. At file creation time, it is set to
      one and a debugfs_remove() will drop that initial reference. The new
      debugfs_file_get() and debugfs_file_put(), intended to be used in place of
      former debugfs_use_file_start() and debugfs_use_file_finish(), increment
      and decrement it respectively. Once the count drops to zero,
      debugfs_file_put() will signal a completion which is possibly being waited
      for from debugfs_remove().
      Thus, as long as there is a debugfs_file_get() not yet matched by a
      corresponding debugfs_file_put() around, debugfs_remove() will block.
      
      Actual users of debugfs_use_file_start() and -finish() will get converted
      to the new debugfs_file_get() and debugfs_file_put() by followup patches.
      
      Fixes: 49d200de ("debugfs: prevent access to removed files' private data")
      Reported-by: NJohannes Berg <johannes@sipsolutions.net>
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e9117a5a
    • N
      debugfs: add support for more elaborate ->d_fsdata · 7c8d4698
      Nicolai Stange 提交于
      Currently, the user provided fops, "real_fops", are stored directly into
      ->d_fsdata.
      
      In order to be able to store more per-file state and thus prepare for more
      granular file removal protection, wrap the real_fops into a dynamically
      allocated container struct, debugfs_fsdata.
      
      A struct debugfs_fsdata gets allocated at file creation and freed from the
      newly intoduced ->d_release().
      
      Finally, move the implementation of debugfs_real_fops() out of the public
      debugfs header such that struct debugfs_fsdata's declaration can be kept
      private.
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c8d4698
  2. 17 7月, 2017 1 次提交
  3. 16 5月, 2017 1 次提交
  4. 08 4月, 2017 1 次提交
  5. 03 2月, 2017 1 次提交
    • O
      debugfs: add debugfs_lookup() · a7c5437b
      Omar Sandoval 提交于
      We don't always have easy access to the dentry of a file or directory we
      created in debugfs. Add a helper which allows us to get a dentry we
      previously created.
      
      The motivation for this change is a problem with blktrace and the blk-mq
      debugfs entries introduced in 07e4fead ("blk-mq: create debugfs
      directory tree"). Namely, in some cases, the directory that blktrace
      needs to create may already exist, but in other cases, it may not. We
      _could_ rely on a bunch of implied knowledge to decide whether to create
      the directory or not, but it's much cleaner on our end to just look it
      up.
      Signed-off-by: NOmar Sandoval <osandov@fb.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      a7c5437b
  6. 01 2月, 2017 1 次提交
    • E
      fs: Better permission checking for submounts · 93faccbb
      Eric W. Biederman 提交于
      To support unprivileged users mounting filesystems two permission
      checks have to be performed: a test to see if the user allowed to
      create a mount in the mount namespace, and a test to see if
      the user is allowed to access the specified filesystem.
      
      The automount case is special in that mounting the original filesystem
      grants permission to mount the sub-filesystems, to any user who
      happens to stumble across the their mountpoint and satisfies the
      ordinary filesystem permission checks.
      
      Attempting to handle the automount case by using override_creds
      almost works.  It preserves the idea that permission to mount
      the original filesystem is permission to mount the sub-filesystem.
      Unfortunately using override_creds messes up the filesystems
      ordinary permission checks.
      
      Solve this by being explicit that a mount is a submount by introducing
      vfs_submount, and using it where appropriate.
      
      vfs_submount uses a new mount internal mount flags MS_SUBMOUNT, to let
      sget and friends know that a mount is a submount so they can take appropriate
      action.
      
      sget and sget_userns are modified to not perform any permission checks
      on submounts.
      
      follow_automount is modified to stop using override_creds as that
      has proven problemantic.
      
      do_mount is modified to always remove the new MS_SUBMOUNT flag so
      that we know userspace will never by able to specify it.
      
      autofs4 is modified to stop using current_real_cred that was put in
      there to handle the previous version of submount permission checking.
      
      cifs is modified to pass the mountpoint all of the way down to vfs_submount.
      
      debugfs is modified to pass the mountpoint all of the way down to
      trace_automount by adding a new parameter.  To make this change easier
      a new typedef debugfs_automount_t is introduced to capture the type of
      the debugfs automount function.
      
      Cc: stable@vger.kernel.org
      Fixes: 069d5ac9 ("autofs:  Fix automounts by using current_real_cred()->uid")
      Fixes: aeaa4a79 ("fs: Call d_automount with the filesystems creds")
      Reviewed-by: NTrond Myklebust <trond.myklebust@primarydata.com>
      Reviewed-by: NSeth Forshee <seth.forshee@canonical.com>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      93faccbb
  7. 11 1月, 2017 1 次提交
  8. 05 11月, 2016 1 次提交
  9. 28 10月, 2016 1 次提交
    • A
      debugfs: improve DEFINE_DEBUGFS_ATTRIBUTE for !CONFIG_DEBUG_FS · 7f847dd3
      Arnd Bergmann 提交于
      The slp_s0_residency_usec debugfs file currently uses
      DEFINE_DEBUGFS_ATTRIBUTE(), but that macro cannot really be used to
      define files outside of the debugfs code, as it has no reference to
      the get/set functions if CONFIG_DEBUG_FS is not defined:
      
      drivers/platform/x86/intel_pmc_core.c:80:12: error: ‘pmc_core_dev_state_get’ defined but not used [-Werror=unused-function]
      
      This fixes the macro to always contain the reference, and instead rely
      on the stubbed-out debugfs_create_file to not actually refer to
      its arguments so the compiler can still drop the reference.
      This works because the attribute definition is always 'static',
      and the dead-code removal silently drops all static symbols
      that are not used.
      
      Fixes: c6468808 ("debugfs: add support for self-protecting attribute file fops")
      Fixes: df2294fb ("intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      [nicstange@gmail.com: Add dummy implementations of debugfs_attr_read() and
        debugfs_attr_write() in order to protect against possibly broken dead
        code elimination and to improve readability.
        Correct CONFIG_DEBUGFS_FS -> CONFIG_DEBUG_FS typo in changelog.]
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f847dd3
  10. 21 9月, 2016 1 次提交
  11. 13 4月, 2016 3 次提交
    • N
      debugfs: add support for self-protecting attribute file fops · c6468808
      Nicolai Stange 提交于
      In order to protect them against file removal issues, debugfs_create_file()
      creates a lifetime managing proxy around each struct file_operations
      handed in.
      
      In cases where this struct file_operations is able to manage file lifetime
      by itself already, the proxy created by debugfs is a waste of resources.
      
      The most common class of struct file_operations given to debugfs are those
      defined by means of the DEFINE_SIMPLE_ATTRIBUTE() macro.
      
      Introduce a DEFINE_DEBUGFS_ATTRIBUTE() macro to allow any
      struct file_operations of this class to be easily made file lifetime aware
      and thus, to be operated unproxied.
      
      Specifically, introduce debugfs_attr_read() and debugfs_attr_write()
      which wrap simple_attr_read() and simple_attr_write() under the protection
      of a debugfs_use_file_start()/debugfs_use_file_finish() pair.
      
      Make DEFINE_DEBUGFS_ATTRIBUTE() set the defined struct file_operations'
      ->read() and ->write() members to these wrappers.
      
      Export debugfs_create_file_unsafe() in order to allow debugfs users to
      create their files in non-proxying operation mode.
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6468808
    • N
      debugfs: prevent access to removed files' private data · 49d200de
      Nicolai Stange 提交于
      Upon return of debugfs_remove()/debugfs_remove_recursive(), it might
      still be attempted to access associated private file data through
      previously opened struct file objects. If that data has been freed by
      the caller of debugfs_remove*() in the meanwhile, the reading/writing
      process would either encounter a fault or, if the memory address in
      question has been reassigned again, unrelated data structures could get
      overwritten.
      
      However, since debugfs files are seldomly removed, usually from module
      exit handlers only, the impact is very low.
      
      Currently, there are ~1000 call sites of debugfs_create_file() spread
      throughout the whole tree and touching all of those struct file_operations
      in order to make them file removal aware by means of checking the result of
      debugfs_use_file_start() from within their methods is unfeasible.
      
      Instead, wrap the struct file_operations by a lifetime managing proxy at
      file open:
      - In debugfs_create_file(), the original fops handed in has got stashed
        away in ->d_fsdata already.
      - In debugfs_create_file(), install a proxy file_operations factory,
        debugfs_full_proxy_file_operations, at ->i_fop.
      
      This proxy factory has got an ->open() method only. It carries out some
      lifetime checks and if successful, dynamically allocates and sets up a new
      struct file_operations proxy at ->f_op. Afterwards, it forwards to the
      ->open() of the original struct file_operations in ->d_fsdata, if any.
      
      The dynamically set up proxy at ->f_op has got a lifetime managing wrapper
      set for each of the methods defined in the original struct file_operations
      in ->d_fsdata.
      
      Its ->release()er frees the proxy again and forwards to the original
      ->release(), if any.
      
      In order not to mislead the VFS layer, it is strictly necessary to leave
      those fields blank in the proxy that have been NULL in the original
      struct file_operations also, i.e. aren't supported. This is why there is a
      need for dynamically allocated proxies. The choice made not to allocate a
      proxy instance for every dentry at file creation, but for every
      struct file object instantiated thereof is justified by the expected usage
      pattern of debugfs, namely that in general very few files get opened more
      than once at a time.
      
      The wrapper methods set in the struct file_operations implement lifetime
      managing by means of the SRCU protection facilities already in place for
      debugfs:
      They set up a SRCU read side critical section and check whether the dentry
      is still alive by means of debugfs_use_file_start(). If so, they forward
      the call to the original struct file_operation stored in ->d_fsdata, still
      under the protection of the SRCU read side critical section.
      This SRCU read side critical section prevents any pending debugfs_remove()
      and friends to return to their callers. Since a file's private data must
      only be freed after the return of debugfs_remove(), the ongoing proxied
      call is guarded against any file removal race.
      
      If, on the other hand, the initial call to debugfs_use_file_start() detects
      that the dentry is dead, the wrapper simply returns -EIO and does not
      forward the call. Note that the ->poll() wrapper is special in that its
      signature does not allow for the return of arbitrary -EXXX values and thus,
      POLLHUP is returned here.
      
      In order not to pollute debugfs with wrapper definitions that aren't ever
      needed, I chose not to define a wrapper for every struct file_operations
      method possible. Instead, a wrapper is defined only for the subset of
      methods which are actually set by any debugfs users.
      Currently, these are:
      
        ->llseek()
        ->read()
        ->write()
        ->unlocked_ioctl()
        ->poll()
      
      The ->release() wrapper is special in that it does not protect the original
      ->release() in any way from dead files in order not to leak resources.
      Thus, any ->release() handed to debugfs must implement file lifetime
      management manually, if needed.
      For only 33 out of a total of 434 releasers handed in to debugfs, it could
      not be verified immediately whether they access data structures that might
      have been freed upon a debugfs_remove() return in the meanwhile.
      
      Export debugfs_use_file_start() and debugfs_use_file_finish() in order to
      allow any ->release() to manually implement file lifetime management.
      
      For a set of common cases of struct file_operations implemented by the
      debugfs_core itself, future patches will incorporate file lifetime
      management directly within those in order to allow for their unproxied
      operation. Rename the original, non-proxying "debugfs_create_file()" to
      "debugfs_create_file_unsafe()" and keep it for future internal use by
      debugfs itself. Factor out code common to both into the new
      __debugfs_create_file().
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      49d200de
    • N
      debugfs: prevent access to possibly dead file_operations at file open · 9fd4dcec
      Nicolai Stange 提交于
      Nothing prevents a dentry found by path lookup before a return of
      __debugfs_remove() to actually get opened after that return. Now, after
      the return of __debugfs_remove(), there are no guarantees whatsoever
      regarding the memory the corresponding inode's file_operations object
      had been kept in.
      
      Since __debugfs_remove() is seldomly invoked, usually from module exit
      handlers only, the race is hard to trigger and the impact is very low.
      
      A discussion of the problem outlined above as well as a suggested
      solution can be found in the (sub-)thread rooted at
      
        http://lkml.kernel.org/g/20130401203445.GA20862@ZenIV.linux.org.uk
        ("Yet another pipe related oops.")
      
      Basically, Greg KH suggests to introduce an intermediate fops and
      Al Viro points out that a pointer to the original ones may be stored in
      ->d_fsdata.
      
      Follow this line of reasoning:
      - Add SRCU as a reverse dependency of DEBUG_FS.
      - Introduce a srcu_struct object for the debugfs subsystem.
      - In debugfs_create_file(), store a pointer to the original
        file_operations object in ->d_fsdata.
      - Make debugfs_remove() and debugfs_remove_recursive() wait for a
        SRCU grace period after the dentry has been delete()'d and before they
        return to their callers.
      - Introduce an intermediate file_operations object named
        "debugfs_open_proxy_file_operations". It's ->open() functions checks,
        under the protection of a SRCU read lock, whether the dentry is still
        alive, i.e. has not been d_delete()'d and if so, tries to acquire a
        reference on the owning module.
        On success, it sets the file object's ->f_op to the original
        file_operations and forwards the ongoing open() call to the original
        ->open().
      - For clarity, rename the former debugfs_file_operations to
        debugfs_noop_file_operations -- they are in no way canonical.
      
      The choice of SRCU over "normal" RCU is justified by the fact, that the
      former may also be used to protect ->i_private data from going away
      during the execution of a file's readers and writers which may (and do)
      sleep.
      
      Finally, introduce the fs/debugfs/internal.h header containing some
      declarations internal to the debugfs implementation.
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9fd4dcec
  12. 08 2月, 2016 1 次提交
  13. 19 10月, 2015 1 次提交
  14. 04 10月, 2015 1 次提交
  15. 21 7月, 2015 1 次提交
  16. 11 5月, 2015 1 次提交
  17. 18 2月, 2015 1 次提交
  18. 26 1月, 2015 2 次提交
  19. 01 12月, 2014 1 次提交
  20. 27 11月, 2014 1 次提交
  21. 06 11月, 2014 1 次提交
  22. 04 10月, 2013 1 次提交
  23. 28 8月, 2013 1 次提交
  24. 04 6月, 2013 1 次提交
  25. 19 1月, 2013 1 次提交
  26. 17 4月, 2012 1 次提交
  27. 21 3月, 2012 1 次提交
  28. 04 1月, 2012 1 次提交
  29. 19 11月, 2011 2 次提交
  30. 20 5月, 2010 1 次提交
  31. 24 9月, 2009 1 次提交