02 Jul, 2018

1 commit

  • gcc 8.1.0 complains:

    fs/configfs/symlink.c:67:3: warning:
    'strncpy' output truncated before terminating nul copying as many
    bytes from a string as its length
    fs/configfs/symlink.c: In function 'configfs_get_link':
    fs/configfs/symlink.c:63:13: note: length computed here

    Using strncpy() is indeed less than perfect since the length of data to
    be copied has already been determined with strlen(). Replace strncpy()
    with memcpy() to address the warning and optimize the code a little.

    Signed-off-by: Guenter Roeck
    Signed-off-by: Christoph Hellwig

    Guenter Roeck
     

19 Oct, 2017

1 commit

  • 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: Bhumika Goyal
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: Christoph Hellwig

    Bhumika Goyal
     

12 Jun, 2017

1 commit

  • This patch closes a long standing race in configfs between
    the creation of a new symlink in create_link(), while the
    symlink target's config_item is being concurrently removed
    via configfs_rmdir().

    This can happen because the symlink target's reference
    is obtained by config_item_get() in create_link() before
    the CONFIGFS_USET_DROPPING bit set by configfs_detach_prep()
    during configfs_rmdir() shutdown is actually checked..

    This originally manifested itself on ppc64 on v4.8.y under
    heavy load using ibmvscsi target ports with Novalink API:

    [ 7877.289863] rpadlpar_io: slot U8247.22L.212A91A-V1-C8 added
    [ 7879.893760] ------------[ cut here ]------------
    [ 7879.893768] WARNING: CPU: 15 PID: 17585 at ./include/linux/kref.h:46 config_item_get+0x7c/0x90 [configfs]
    [ 7879.893811] CPU: 15 PID: 17585 Comm: targetcli Tainted: G O 4.8.17-customv2.22 #12
    [ 7879.893812] task: c00000018a0d3400 task.stack: c0000001f3b40000
    [ 7879.893813] NIP: d000000002c664ec LR: d000000002c60980 CTR: c000000000b70870
    [ 7879.893814] REGS: c0000001f3b43810 TRAP: 0700 Tainted: G O (4.8.17-customv2.22)
    [ 7879.893815] MSR: 8000000000029033 CR: 28222242 XER: 00000000
    [ 7879.893820] CFAR: d000000002c664bc SOFTE: 1
    GPR00: d000000002c60980 c0000001f3b43a90 d000000002c70908 c0000000fbc06820
    GPR04: c0000001ef1bd900 0000000000000004 0000000000000001 0000000000000000
    GPR08: 0000000000000000 0000000000000001 d000000002c69560 d000000002c66d80
    GPR12: c000000000b70870 c00000000e798700 c0000001f3b43ca0 c0000001d4949d40
    GPR16: c00000014637e1c0 0000000000000000 0000000000000000 c0000000f2392940
    GPR20: c0000001f3b43b98 0000000000000041 0000000000600000 0000000000000000
    GPR24: fffffffffffff000 0000000000000000 d000000002c60be0 c0000001f1dac490
    GPR28: 0000000000000004 0000000000000000 c0000001ef1bd900 c0000000f2392940
    [ 7879.893839] NIP [d000000002c664ec] config_item_get+0x7c/0x90 [configfs]
    [ 7879.893841] LR [d000000002c60980] check_perm+0x80/0x2e0 [configfs]
    [ 7879.893842] Call Trace:
    [ 7879.893844] [c0000001f3b43ac0] [d000000002c60980] check_perm+0x80/0x2e0 [configfs]
    [ 7879.893847] [c0000001f3b43b10] [c000000000329770] do_dentry_open+0x2c0/0x460
    [ 7879.893849] [c0000001f3b43b70] [c000000000344480] path_openat+0x210/0x1490
    [ 7879.893851] [c0000001f3b43c80] [c00000000034708c] do_filp_open+0xfc/0x170
    [ 7879.893853] [c0000001f3b43db0] [c00000000032b5bc] do_sys_open+0x1cc/0x390
    [ 7879.893856] [c0000001f3b43e30] [c000000000009584] system_call+0x38/0xec
    [ 7879.893856] Instruction dump:
    [ 7879.893858] 409d0014 38210030 e8010010 7c0803a6 4e800020 3d220000 e94981e0 892a0000
    [ 7879.893861] 2f890000 409effe0 39200001 992a0000 4bffffd0 60000000 60000000
    [ 7879.893866] ---[ end trace 14078f0b3b5ad0aa ]---

    To close this race, go ahead and obtain the symlink's target
    config_item reference only after the existing CONFIGFS_USET_DROPPING
    check succeeds.

    This way, if configfs_rmdir() wins create_link() will return -ENONET,
    and if create_link() wins configfs_rmdir() will return -EBUSY.

    Reported-by: Bryant G. Ly
    Tested-by: Bryant G. Ly
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Christoph Hellwig
    Cc: stable@vger.kernel.org

    Nicholas Bellinger
     

09 Dec, 2016

1 commit


31 Dec, 2015

1 commit


30 Dec, 2015

1 commit


09 Dec, 2015

1 commit

  • new method: ->get_link(); replacement of ->follow_link(). The differences
    are:
    * inode and dentry are passed separately
    * might be called both in RCU and non-RCU mode;
    the former is indicated by passing it a NULL dentry.
    * when called that way it isn't allowed to block
    and should return ERR_PTR(-ECHILD) if it needs to be called
    in non-RCU mode.

    It's a flagday change - the old method is gone, all in-tree instances
    converted. Conversion isn't hard; said that, so far very few instances
    do not immediately bail out when called in RCU mode. That'll change
    in the next commits.

    Signed-off-by: Al Viro

    Al Viro
     

11 May, 2015

4 commits

  • similar to kfree_put_link()

    Signed-off-by: Al Viro

    Al Viro
     
  • only one instance looks at that argument at all; that sole
    exception wants inode rather than dentry.

    Signed-off-by: Al Viro

    Al Viro
     
  • its only use is getting passed to nd_jump_link(), which can obtain
    it from current->nameidata

    Signed-off-by: Al Viro

    Al Viro
     
  • a) instead of storing the symlink body (via nd_set_link()) and returning
    an opaque pointer later passed to ->put_link(), ->follow_link() _stores_
    that opaque pointer (into void * passed by address by caller) and returns
    the symlink body. Returning ERR_PTR() on error, NULL on jump (procfs magic
    symlinks) and pointer to symlink body for normal symlinks. Stored pointer
    is ignored in all cases except the last one.

    Storing NULL for opaque pointer (or not storing it at all) means no call
    of ->put_link().

    b) the body used to be passed to ->put_link() implicitly (via nameidata).
    Now only the opaque pointer is. In the cases when we used the symlink body
    to free stuff, ->follow_link() now should store it as opaque pointer in addition
    to returning it.

    Signed-off-by: Al Viro

    Al Viro
     

21 Mar, 2012

2 commits


30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

14 Jan, 2010

1 commit


22 Apr, 2009

1 commit

  • I observed the following build warning with fs/configfs/symlink.c:

    fs/configfs/symlink.c: In function 'configfs_symlink':
    fs/configfs/symlink.c:138: warning: 'target_item' may be used uninitialized in this function

    Here is a small fix for this.

    Cc: Patrick Mochel
    Cc: Balbir Singh
    Cc: Sachin P Sant
    Signed-Off-By: Subrata Modak
    Signed-off-by: Joel Becker

    Subrata Modak
     

23 Oct, 2008

1 commit


01 Aug, 2008

3 commits

  • process 1: process 2:
    configfs_mkdir("A")
    attach_group("A")
    attach_item("A")
    d_instantiate("A")
    populate_groups("A")
    mutex_lock("A")
    attach_group("A/B")
    attach_item("A")
    d_instantiate("A/B")
    mkdir("A/B/C")
    do_path_lookup("A/B/C", LOOKUP_PARENT)
    ok
    lookup_create("A/B/C")
    mutex_lock("A/B")
    ok
    configfs_mkdir("A/B/C")
    ok
    attach_group("A/C")
    attach_item("A/C")
    d_instantiate("A/C")
    populate_groups("A/C")
    mutex_lock("A/C")
    attach_group("A/C/D")
    attach_item("A/C/D")
    failure
    mutex_unlock("A/C")
    detach_groups("A/C")
    nothing to do
    mkdir("A/C/E")
    do_path_lookup("A/C/E", LOOKUP_PARENT)
    ok
    lookup_create("A/C/E")
    mutex_lock("A/C")
    ok
    configfs_mkdir("A/C/E")
    ok
    detach_item("A/C")
    d_delete("A/C")
    mutex_unlock("A")
    detach_groups("A")
    mutex_lock("A/B")
    detach_group("A/B")
    detach_groups("A/B")
    nothing since no _default_ group
    detach_item("A/B")
    mutex_unlock("A/B")
    d_delete("A/B")
    detach_item("A")
    d_delete("A")

    Two bugs:

    1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
    removed in the end. The same could happen with symlink() instead of mkdir().

    2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
    which may probably confuse VFS.

    This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
    building the inode and instantiating the dentry, and validating the whole
    group+default groups hierarchy in a second pass by clearing
    CONFIGFS_USET_CREATING.
    mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
    called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
    does not prevent userspace from calling stat() successfuly on such directories,
    but this prevents userspace from adding (children to | symlinking from/to |
    read/write attributes of | listing the contents of) not validated items. In
    other words, userspace will not interact with the subsystem on a new item until
    the new item creation completes correctly.
    It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
    flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
    target of a new symlink: a valid target directory in the middle of attaching
    a new user-created child item could be wrongly detected as being attached.

    2/ is fixed by next commit.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker
    Signed-off-by: Mark Fasheh

    Louis Rilling
     
  • On a similar pattern as mkdir() vs rmdir(), a failing symlink() may make rmdir()
    fail for the symlink's parent and the symlink's target as well.

    failing symlink() making target's rmdir() fail:

    process 1: process 2:
    symlink("A/S" -> "B")
    allow_link()
    create_link()
    attach to "B" links list
    rmdir("B")
    detach_prep("B")
    error because of new link
    configfs_create_link("A", "S")
    error (eg -ENOMEM)

    failing symlink() making parent's rmdir() fail:

    process 1: process 2:
    symlink("A/D/S" -> "B")
    allow_link()
    create_link()
    attach to "B" links list
    configfs_create_link("A/D", "S")
    make_dirent("A/D", "S")
    rmdir("A")
    detach_prep("A")
    detach_prep("A/D")
    error because of "S"
    create("S")
    error (eg -ENOMEM)

    We cannot use the same solution as for mkdir() vs rmdir(), since rmdir() on the
    target cannot wait on the i_mutex of the new symlink's parent without risking a
    deadlock (with other symlink() or sys_rename()). Instead we define a global
    mutex protecting all configfs symlinks attachment, so that rmdir() can avoid the
    races above.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker
    Signed-off-by: Mark Fasheh

    Louis Rilling
     
  • The rule for configfs symlinks is that symlinks always point to valid
    config_items, and prevent the target from being removed. However,
    configfs_symlink() only checks that it can grab a reference on the target item,
    without ensuring that it remains alive until the symlink is correctly attached.

    This patch makes configfs_symlink() fail whenever the target is being removed,
    using the CONFIGFS_USET_DROPPING flag set by configfs_detach_prep() and
    protected by configfs_dirent_lock.

    This patch introduces a similar (weird?) behavior as with mkdir failures making
    rmdir fail: if symlink() races with rmdir() of the parent directory (or its
    youngest user-created ancestor if parent is a default group) or rmdir() of the
    target directory, and then fails in configfs_create(), this can make the racing
    rmdir() fail despite the concerned directory having no user-created entry (resp.
    no symlink pointing to it or one of its default groups) in the end.
    This behavior is fixed in later patches.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker
    Signed-off-by: Mark Fasheh

    Louis Rilling
     

15 Jul, 2008

3 commits

  • When allow_link() succeeds but create_link() fails, the subsystem is not
    informed of the failure.

    This patch fixes this by calling drop_link() on create_link() failures.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker

    Louis Rilling
     
  • Symlinks to a config_item are listed under its configfs_dirent s_links, but the
    list mutations are not protected by any common lock.

    This patch uses the configfs_dirent_lock spinlock to add the necessary
    protection.

    Note: we should also protect the list_empty() test in configfs_detach_prep() but
    1/ the lock should not be released immediately because nothing would prevent the
    list from being filled after a successful list_empty() test, making the problem
    tricky,
    2/ this will be solved by the rmdir() vs rename() deadlock bugfix.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker

    Louis Rilling
     
  • This patch introduces configfs_dirent_lock spinlock to protect configfs_dirent
    traversals against linkage mutations (add/del/move). This will allow
    configfs_detach_prep() to avoid locking i_mutexes.

    Locking rules for configfs_dirent linkage mutations are the same plus the
    requirement of taking configfs_dirent_lock. For configfs_dirent walking, one can
    either take appropriate i_mutex as before, or take configfs_dirent_lock.

    The spinlock could actually be a mutex, but the critical sections are either
    O(1) or should not be too long (default groups walking in last patch).

    ChangeLog:
    - Clarify the comment on configfs_dirent_lock usage
    - Move sd->s_element init before linking the new dirent
    - In lseek(), do not release configfs_dirent_lock before the dirent is
    relinked.

    Signed-off-by: Louis Rilling
    Signed-off-by: Joel Becker

    Louis Rilling
     

30 Apr, 2008

1 commit


15 Feb, 2008

2 commits

  • * Add path_put() functions for releasing a reference to the dentry and
    vfsmount of a struct path in the right order

    * Switch from path_release(nd) to path_put(&nd->path)

    * Rename dput_path() to path_put_conditional()

    [akpm@linux-foundation.org: fix cifs]
    Signed-off-by: Jan Blunck
    Signed-off-by: Andreas Gruenbacher
    Acked-by: Christoph Hellwig
    Cc:
    Cc: Al Viro
    Cc: Steven French
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Blunck
     
  • This is the central patch of a cleanup series. In most cases there is no good
    reason why someone would want to use a dentry for itself. This series reflects
    that fact and embeds a struct path into nameidata.

    Together with the other patches of this series
    - it enforced the correct order of getting/releasing the reference count on
    pairs
    - it prepares the VFS for stacking support since it is essential to have a
    struct path in every place where the stack can be traversed
    - it reduces the overall code size:

    without patch series:
    text data bss dec hex filename
    5321639 858418 715768 6895825 6938d1 vmlinux

    with patch series:
    text data bss dec hex filename
    5320026 858418 715768 6894212 693284 vmlinux

    This patch:

    Switch from nd->{dentry,mnt} to nd->path.{dentry,mnt} everywhere.

    [akpm@linux-foundation.org: coding-style fixes]
    [akpm@linux-foundation.org: fix cifs]
    [akpm@linux-foundation.org: fix smack]
    Signed-off-by: Jan Blunck
    Signed-off-by: Andreas Gruenbacher
    Acked-by: Christoph Hellwig
    Cc: Al Viro
    Cc: Casey Schaufler
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Blunck
     

13 Feb, 2007

1 commit

  • Many struct inode_operations in the kernel can be "const". Marking them const
    moves these to the .rodata section, which avoids false sharing with potential
    dirty data. In addition it'll catch accidental writes at compile time to
    these shared resources.

    Signed-off-by: Arjan van de Ven
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arjan van de Ven
     

30 Jun, 2006

1 commit


04 Feb, 2006

2 commits


04 Jan, 2006

1 commit