08 Dec, 2018

1 commit

  • commit 77d2a24b6107bd9b3bf2403a65c1428a9da83dd0 upstream.

    gcc 8.1.0 complains:

    lib/kobject.c:128:3: warning:
    'strncpy' output truncated before terminating nul copying as many
    bytes from a string as its length [-Wstringop-truncation]
    lib/kobject.c: In function 'kobject_get_path':
    lib/kobject.c:125: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: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Guenter Roeck
     

02 May, 2018

1 commit

  • commit 3e14c6abbfb5c94506edda9d8e2c145d79375798 upstream.

    This WARNING proved to be noisy. The function still returns an error
    and callers should handle it. That's how most of kernel code works.
    Downgrade the WARNING to pr_err() and leave WARNINGs for kernel bugs.

    Signed-off-by: Dmitry Vyukov
    Reported-by: syzbot+209c0f67f99fec8eb14b@syzkaller.appspotmail.com
    Reported-by: syzbot+7fb6d9525a4528104e05@syzkaller.appspotmail.com
    Reported-by: syzbot+2e63711063e2d8f9ea27@syzkaller.appspotmail.com
    Reported-by: syzbot+de73361ee4971b6e6f75@syzkaller.appspotmail.com
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Dmitry Vyukov
     

23 Mar, 2017

1 commit


10 Feb, 2016

1 commit


07 Nov, 2015

1 commit

  • Sometimes kobject_set_name_vargs is called with a format string conaining
    no %, or a format string of precisely "%s", where the single vararg
    happens to point to .rodata. kvasprintf_const detects these cases for us
    and returns a copy of that pointer instead of duplicating the string, thus
    saving some run-time memory. Otherwise, it falls back to kvasprintf. We
    just need to always deallocate ->name using kfree_const.

    Unfortunately, the dance we need to do to perform the '/' -> '!'
    sanitization makes the resulting code rather ugly.

    I instrumented kstrdup_const to provide some statistics on the memory
    saved, and for me this gave an additional ~14KB after boot (306KB was
    already saved; this patch bumped that to 320KB). I have
    KMALLOC_SHIFT_LOW==3, and since 80% of the kvasprintf_const hits were
    satisfied by an 8-byte allocation, the 14K would roughly be quadrupled
    when KMALLOC_SHIFT_LOW==5. Whether these numbers are sufficient to
    justify the ugliness I'll leave to others to decide.

    Signed-off-by: Rasmus Villemoes
    Cc: Greg KH
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

04 Oct, 2015

1 commit


18 Jul, 2015

1 commit

  • Using __printf attributes helps to detect several format string issues
    at compile time (even though -Wformat-security is currently disabled in
    Makefile). For example it can detect when formatting a pointer as a
    number, like the issue fixed in commit a3fa71c40f18 ("wl18xx: show
    rx_frames_per_rates as an array as it really is"), or when the arguments
    do not match the format string, c.f. for example commit 5ce1aca81435
    ("reiserfs: fix __RASSERT format string").

    To prevent similar bugs in the future, add a __printf attribute to every
    function prototype which needs one in include/linux/ and lib/. These
    functions were mostly found by using gcc's -Wsuggest-attribute=format
    flag.

    Signed-off-by: Nicolas Iooss
    Cc: Greg Kroah-Hartman
    Cc: Felipe Balbi
    Cc: Joel Becker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nicolas Iooss
     

01 Jul, 2015

1 commit

  • Pull btrfs updates from Chris Mason:
    "Outside of our usual batch of fixes, this integrates the subvolume
    quota updates that Qu Wenruo from Fujitsu has been working on for a
    few releases now. He gets an extra gold star for making btrfs smaller
    this time, and fixing a number of quota corners in the process.

    Dave Sterba tested and integrated Anand Jain's sysfs improvements.
    Outside of exporting a symbol (ack'd by Greg) these are all internal
    to btrfs and it's mostly cleanups and fixes. Anand also attached some
    of our sysfs objects to our internal device management structs instead
    of an object off the super block. It will make device management
    easier overall and it's a better fit for how the sysfs files are used.
    None of the existing sysfs files are moved around.

    Thanks for all the fixes everyone"

    * 'for-linus-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (87 commits)
    btrfs: delayed-ref: double free in btrfs_add_delayed_tree_ref()
    Btrfs: Check if kobject is initialized before put
    lib: export symbol kobject_move()
    Btrfs: sysfs: add support to show replacing target in the sysfs
    Btrfs: free the stale device
    Btrfs: use received_uuid of parent during send
    Btrfs: fix use-after-free in btrfs_replay_log
    btrfs: wait for delayed iputs on no space
    btrfs: qgroup: Make snapshot accounting work with new extent-oriented qgroup.
    btrfs: qgroup: Add the ability to skip given qgroup for old/new_roots.
    btrfs: ulist: Add ulist_del() function.
    btrfs: qgroup: Cleanup the old ref_node-oriented mechanism.
    btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism.
    btrfs: qgroup: Switch to new extent-oriented qgroup mechanism.
    btrfs: qgroup: Switch rescan to new mechanism.
    btrfs: qgroup: Add new qgroup calculation function btrfs_qgroup_account_extents().
    btrfs: backref: Add special time_seq == (u64)-1 case for btrfs_find_all_roots().
    btrfs: qgroup: Add new function to record old_roots.
    btrfs: qgroup: Record possible quota-related extent for qgroup.
    btrfs: qgroup: Add function qgroup_update_counters().
    ...

    Linus Torvalds
     

26 Jun, 2015

1 commit


19 Jun, 2015

1 commit


25 Mar, 2015

1 commit

  • call kobject_get() to kojbect that is not initalized or released will only
    leave following like call trace to us:

    -----------[ cut here ]------------
    [ 54.545816] WARNING: CPU: 0 PID: 213 at include/linux/kref.h:47
    kobject_get+0x41/0x50()
    [ 54.642595] Modules linked in: i2c_i801(+) mfd_core shpchp(+)
    acpi_cpufreq(+) edac_core ioatdma(+) xfs libcrc32c ast syscopyarea ixgbe
    sysfillrect sysimgblt sr_mod sd_mod drm_kms_helper igb mdio cdrom e1000e ahci
    dca ttm libahci uas drm i2c_algo_bit ptp megaraid_sas libata usb_storage
    i2c_core pps_core dm_mirror dm_region_hash dm_log dm_mod
    [ 55.007264] CPU: 0 PID: 213 Comm: kworker/0:2 Not tainted
    3.18.5
    [ 55.099970] Hardware name: Oracle Corporation SUN FIRE X4170 M2 SERVER
    /ASSY,MOTHERBOARD,X4170, BIOS 08120104 05/08/2012
    [ 55.239736] Workqueue: kacpi_notify acpi_os_execute_deferred
    [ 55.308598] 0000000000000000 00000000bd730b61 ffff88046742baf8
    ffffffff816b7edb
    [ 55.398305] 0000000000000000 0000000000000000 ffff88046742bb38
    ffffffff81078ae1
    [ 55.488040] ffff88046742bbd8 ffff8806706b3000 0000000000000292
    0000000000000000
    [ 55.577776] Call Trace:
    [ 55.608228] [] dump_stack+0x46/0x58
    [ 55.670895] [] warn_slowpath_common+0x81/0xa0
    [ 55.743952] [] warn_slowpath_null+0x1a/0x20
    [ 55.814929] [] kobject_get+0x41/0x50
    [ 55.878654] [] cpufreq_cpu_get+0x75/0xc0
    [ 55.946528] [] cpufreq_update_policy+0x2e/0x1f0

    The above issue was casued by a race condition, if there is a WARN in
    kobject_get() of the kobject is not initialized, that would save us much
    time to debug it.

    Signed-off-by: Ethan Zhao
    Signed-off-by: Greg Kroah-Hartman

    Ethan Zhao
     

08 Nov, 2014

1 commit

  • We will hit NULL pointer dereference if we call
    platform_device_register_simple or platform_device_add at very early
    stage. I have observed following crash when called platform_device_add
    from "init_irq" hook of machine_desc. This patch fixes this issue and
    let system handle this case gracefully instead of kernel panic.

    [0.000000] Unable to handle kernel NULL pointer dereference at
    virtual address 0000000c
    [0.000000] pgd = c0004000
    [0.000000] [0000000c] *pgd=00000000
    [0.000000] Internal error: Oops: 5 [#1] PREEMPT ARM
    [0.000000] Modules linked in:
    [0.000000] CPU: 0 PID: 0 Comm: swapper Tainted: G W 3.17.0-rc6-00198-ga1603f1-dirty #319
    [0.000000] task: c05b23f0 ti: c05a8000 task.ti: c05a8000
    [0.000000] PC is at kobject_namespace+0x18/0x58
    [0.000000] LR is at kobject_add_internal+0x90/0x2ec
    [snip]
    [0.000000] [] (kobject_namespace) from [] (kobject_add_internal+0x90/0x2ec)
    [0.000000] [] (kobject_add_internal) from [] (kobject_add+0x4c/0x98)
    [0.000000] [] (kobject_add) from [] (device_add+0xe8/0x51c)
    [0.000000] [] (device_add) from [] (platform_device_add+0xb4/0x214)
    [0.000000] [] (platform_device_add) from [] (platform_device_register_full+0xb8/0xdc)
    [0.000000] [] (platform_device_register_full) from [] (exynos_init_irq+0x90/0x9c)
    [0.000000] [] (exynos_init_irq) from [] (init_IRQ+0x2c/0x78)
    [0.000000] [] (init_IRQ) from [] (start_kernel+0x22c/0x378)
    [0.000000] [] (start_kernel) from [] (0x40008070)
    [0.000000] Code: e590000c e3500000 0a00000e e5903014 (e593300c)

    Signed-off-by: Pankaj Dubey
    Signed-off-by: Greg Kroah-Hartman

    Pankaj Dubey
     

08 Feb, 2014

1 commit

  • Currently, kobject is invoking kernfs_enable_ns() directly. This is
    fine now as sysfs and kernfs are enabled and disabled together. If
    sysfs is disabled, kernfs_enable_ns() is switched to dummy
    implementation too and everything is fine; however, kernfs will soon
    have its own config option CONFIG_KERNFS and !SYSFS && KERNFS will be
    possible, which can make kobject call into non-dummy
    kernfs_enable_ns() with NULL kernfs_node pointers leading to an oops.

    Introduce sysfs_enable_ns() which is a wrapper around
    kernfs_enable_ns() so that it can be made a noop depending only on
    CONFIG_SYSFS regardless of the planned CONFIG_KERNFS.

    Signed-off-by: Tejun Heo
    Reported-by: Fengguang Wu
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

31 Jan, 2014

1 commit

  • Pull btrfs updates from Chris Mason:
    "This is a pretty big pull, and most of these changes have been
    floating in btrfs-next for a long time. Filipe's properties work is a
    cool building block for inheriting attributes like compression down on
    a per inode basis.

    Jeff Mahoney kicked in code to export filesystem info into sysfs.

    Otherwise, lots of performance improvements, cleanups and bug fixes.

    Looks like there are still a few other small pending incrementals, but
    I wanted to get the bulk of this in first"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (149 commits)
    Btrfs: fix spin_unlock in check_ref_cleanup
    Btrfs: setup inode location during btrfs_init_inode_locked
    Btrfs: don't use ram_bytes for uncompressed inline items
    Btrfs: fix btrfs_search_slot_for_read backwards iteration
    Btrfs: do not export ulist functions
    Btrfs: rework ulist with list+rb_tree
    Btrfs: fix memory leaks on walking backrefs failure
    Btrfs: fix send file hole detection leading to data corruption
    Btrfs: add a reschedule point in btrfs_find_all_roots()
    Btrfs: make send's file extent item search more efficient
    Btrfs: fix to catch all errors when resolving indirect ref
    Btrfs: fix protection between walking backrefs and root deletion
    btrfs: fix warning while merging two adjacent extents
    Btrfs: fix infinite path build loops in incremental send
    btrfs: undo sysfs when open_ctree() fails
    Btrfs: fix snprintf usage by send's gen_unique_name
    btrfs: fix defrag 32-bit integer overflow
    btrfs: sysfs: list the NO_HOLES feature
    btrfs: sysfs: don't show reserved incompat feature
    btrfs: call permission checks earlier in ioctls and return EPERM
    ...

    Linus Torvalds
     

29 Jan, 2014

1 commit

  • struct kobj_attribute implements the baseline attribute functionality
    that can be used all over the place. We should export the ops associated
    with it.

    Signed-off-by: Jeff Mahoney
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Josef Bacik
    Signed-off-by: Chris Mason

    Jeff Mahoney
     

09 Jan, 2014

1 commit


05 Jan, 2014

1 commit

  • This reverts commit eee031649707db3c9920d9498f8d03819b74fc23.

    Jeff writes:
    I have no objections to reverting it. There were concerns from
    Al Viro that it'd be tough to get right by callers and I had
    assumed it got dropped after that. I had planned on using it in
    my btrfs sysfs exports patchset but came up with a better way.

    Cc: Jeff Mahoney
    Cc: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

12 Dec, 2013

1 commit

  • kernfs has just been separated out from sysfs and we're already in
    full conflict mode. Nothing can make the situation any worse. Let's
    take the chance to name things properly.

    This patch performs the following renames.

    * s/sysfs_elem_dir/kernfs_elem_dir/
    * s/sysfs_elem_symlink/kernfs_elem_symlink/
    * s/sysfs_elem_attr/kernfs_elem_file/
    * s/sysfs_dirent/kernfs_node/
    * s/sd/kn/ in kernfs proper
    * s/parent_sd/parent/
    * s/target_sd/target/
    * s/dir_sd/parent/
    * s/to_sysfs_dirent()/rb_to_kn()/
    * misc renames of local vars when they conflict with the above

    Because md, mic and gpio dig into sysfs details, this patch ends up
    modifying them. All are sysfs_dirent renames and trivial. While we
    can avoid these by introducing a dummy wrapping struct sysfs_dirent
    around kernfs_node, given the limited usage outside kernfs and sysfs
    proper, I don't think such workaround is called for.

    This patch is strictly rename only and doesn't introduce any
    functional difference.

    - mic / gpio renames were missing. Spotted by kbuild test robot.

    Signed-off-by: Tejun Heo
    Cc: Neil Brown
    Cc: Linus Walleij
    Cc: Ashutosh Dixit
    Cc: kbuild test robot
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

09 Dec, 2013

1 commit


08 Dec, 2013

2 commits

  • There's no "unlink from sysfs" interface for ksets, so I think callers of
    kset_unregister() expect the kset to be removed from sysfs immediately,
    without waiting for the last reference to be released.

    This patch makes the sysfs removal happen immediately, so the caller may
    create a new kset with the same name as soon as kset_unregister() returns.
    Without this, every caller has to call "kobject_del(&kset->kobj)" first
    unless it knows it will never create a new kset with the same name.

    This sometimes shows up on module unload and reload, where the reload fails
    because it tries to create a kobject with the same name as one from the
    original load that still exists. CONFIG_DEBUG_KOBJECT_RELEASE=y makes this
    problem easier to hit.

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Greg Kroah-Hartman

    Bjorn Helgaas
     
  • When CONFIG_DEBUG_KOBJECT_RELEASE=y, delay kobject release functions for a
    random time between 1 and 8 seconds, which effectively changes the order in
    which they're called.

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Greg Kroah-Hartman

    Bjorn Helgaas
     

30 Nov, 2013

1 commit

  • Introduce kernfs interface to manipulate a directory which takes and
    returns sysfs_dirents.

    create_dir() is renamed to kernfs_create_dir_ns() and its argumantes
    and return value are updated. create_dir() usages are replaced with
    kernfs_create_dir_ns() and sysfs_create_subdir() usages are replaced
    with kernfs_create_dir(). Dup warnings are handled explicitly by
    sysfs users of the kernfs interface.

    sysfs_enable_ns() is renamed to kernfs_enable_ns().

    This patch doesn't introduce any behavior changes.

    v2: Dummy implementation for !CONFIG_SYSFS updated to return -ENOSYS.

    v3: kernfs_enable_ns() added.

    v4: Refreshed on top of "sysfs: drop kobj_ns_type handling, take #2"
    so that this patch removes sysfs_enable_ns().

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

28 Nov, 2013

1 commit

  • The way namespace tags are implemented in sysfs is more complicated
    than necessary. As each tag is a pointer value and required to be
    non-NULL under a namespace enabled parent, there's no need to record
    separately what type each tag is. If multiple namespace types are
    needed, which currently aren't, we can simply compare the tag to a set
    of allowed tags in the superblock assuming that the tags, being
    pointers, won't have the same value across multiple types.

    This patch rips out kobj_ns_type handling from sysfs. sysfs now has
    an enable switch to turn on namespace under a node. If enabled, all
    children are required to have non-NULL namespace tags and filtered
    against the super_block's tag.

    kobject namespace determination is now performed in
    lib/kobject.c::create_dir() making sysfs_read_ns_type() unnecessary.
    The sanity checks are also moved. create_dir() is restructured to
    ease such addition. This removes most kobject namespace knowledge
    from sysfs proper which will enable proper separation and layering of
    sysfs.

    This is the second try. The first one was cb26a311578e ("sysfs: drop
    kobj_ns_type handling") which tried to automatically enable namespace
    if there are children with non-NULL namespace tags; however, it was
    broken for symlinks as they should inherit the target's tag iff
    namespace is enabled in the parent. This led to namespace filtering
    enabled incorrectly for wireless net class devices through phy80211
    symlinks and thus network configuration failure. a1212d278c05
    ("Revert "sysfs: drop kobj_ns_type handling"") reverted the commit.

    This shouldn't introduce any behavior changes, for real.

    v2: Dummy implementation of sysfs_enable_ns() for !CONFIG_SYSFS was
    missing and caused build failure. Reported by kbuild test robot.

    Signed-off-by: Tejun Heo
    Reported-by: Linus Torvalds
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Cc: Greg Kroah-Hartman
    Cc: kbuild test robot
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

07 Nov, 2013

1 commit

  • This reverts commit cb26a311578e67769e92a39a0a63476533cb7e12.

    It mysteriously causes NetworkManager to not find the wireless device
    for me. As far as I can tell, Tejun *meant* for this commit to not make
    any semantic changes, but there clearly are some. So revert it, taking
    into account some of the calling convention changes that happened in
    this area in subsequent commits.

    Cc: Tejun Heo
    Cc: Greg Kroah-Hartman
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

12 Oct, 2013

1 commit

  • Useful for locating buggy drivers on kernel oops.

    It may add dozens of new lines to boot dmesg. DEBUG_KOBJECT_RELEASE is
    hopefully only enabled in debug kernels (like maybe the Fedora rawhide
    one, or at developers), so being a bit more verbose is likely ok.

    Signed-off-by: Fengguang Wu
    Acked-by: Russell King
    Signed-off-by: Greg Kroah-Hartman

    Fengguang Wu
     

04 Oct, 2013

1 commit

  • sysfs currently has a rather weird behavior regarding removals. A
    directory removal would delete all files directly under it but
    wouldn't recurse into subdirectories, which, while a bit inconsistent,
    seems to make sense at the first glance as each directory is
    supposedly associated with a kobject and each kobject can take care of
    the directory deletion; however, this doesn't really hold as we have
    groups which can be directories without a kobject associated with it
    and require explicit deletions.

    We're in the process of separating out sysfs from kboject / driver
    core and want a consistent behavior. A removal should delete either
    only the specified node or everything under it. I think it is helpful
    to support recursive atomic removal and later patches will implement
    it.

    Such change means that a sysfs_dirent associated with kobject may be
    deleted before the kobject itself is removed if one of its ancestor
    gets removed before it. As sysfs_remove_dir() puts the base ref, we
    may end up with dangling pointer on descendants. This can be solved
    by holding an extra reference on the sd from kobject.

    Acquire an extra reference on the associated sysfs_dirent on directory
    creation and put it after removal.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

30 Sep, 2013

1 commit


28 Sep, 2013

1 commit

  • In kobj_ns_current_may_mount the default should be to allow the mount.
    The test is only for a single kobj_ns_type at a time, and unless there
    is a reason to prevent it the mounting sysfs should be allowed.
    Subsystems that are not registered can't have are not involved so can't
    have a reason to prevent mounting sysfs.

    This is a bug-fix to commit 7dc5dbc879bd ("sysfs: Restrict mounting
    sysfs") that came in via the userns tree during the 3.12 merge window.

    Reported-and-tested-by: James Hogan
    Signed-off-by: "Eric W. Biederman"
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

27 Sep, 2013

3 commits

  • A common way to handle kobject lifetimes in embedded in objects with
    different lifetime rules is to pair the kobject with a struct completion.

    This introduces a kobj_completion structure that can be used in place
    of the pairing, along with several convenience functions for
    initialization, release, and put-and-wait.

    Signed-off-by: Jeff Mahoney
    Signed-off-by: Greg Kroah-Hartman

    Jeff Mahoney
     
  • The way namespace tags are implemented in sysfs is more complicated
    than necessary. As each tag is a pointer value and required to be
    non-NULL under a namespace enabled parent, there's no need to record
    separately what type each tag is or where namespace is enabled.

    If multiple namespace types are needed, which currently aren't, we can
    simply compare the tag to a set of allowed tags in the superblock
    assuming that the tags, being pointers, won't have the same value
    across multiple types. Also, whether to filter by namespace tag or
    not can be trivially determined by whether the node has any tagged
    children or not.

    This patch rips out kobj_ns_type handling from sysfs. sysfs no longer
    cares whether specific type of namespace is enabled or not. If a
    sysfs_dirent has a non-NULL tag, the parent is marked as needing
    namespace filtering and the value is tested against the allowed set of
    tags for the superblock (currently only one but increasing this number
    isn't difficult) and the sysfs_dirent is ignored if it doesn't match.

    This removes most kobject namespace knowledge from sysfs proper which
    will enable proper separation and layering of sysfs. The namespace
    sanity checks in fs/sysfs/dir.c are replaced by the new sanity check
    in kobject_namespace(). As this is the only place ktype->namespace()
    is called for sysfs, this doesn't weaken the sanity check
    significantly. I omitted converting the sanity check in
    sysfs_do_create_link_sd(). While the check can be shifted to upper
    layer, mistakes there are well contained and should be easily visible
    anyway.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • For some unrecognizable reason, namespace information is communicated
    to sysfs through ktype->namespace() callback when there's *nothing*
    which needs the use of a callback. The whole sequence of operations
    is completely synchronous and sysfs operations simply end up calling
    back into the layer which just invoked it in order to find out the
    namespace information, which is completely backwards, obfuscates
    what's going on and unnecessarily tangles two separate layers.

    This patch doesn't remove ktype->namespace() but shifts its handling
    to kobject layer. We probably want to get rid of the callback in the
    long term.

    This patch adds an explicit param to sysfs_{create|rename|move}_dir()
    and renames them to sysfs_{create|rename|move}_dir_ns(), respectively.
    ktype->namespace() invocations are moved to the calling sites of the
    above functions. A new helper kboject_namespace() is introduced which
    directly tests kobj_ns_type_operations->type which should give the
    same result as testing sysfs_fs_type(parent_sd) and returns @kobj's
    namespace tag as necessary. kobject_namespace() is extern as it will
    be used from another file in the following patches.

    This patch should be an equivalent conversion without any functional
    difference.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

08 Sep, 2013

1 commit

  • Pull namespace changes from Eric Biederman:
    "This is an assorted mishmash of small cleanups, enhancements and bug
    fixes.

    The major theme is user namespace mount restrictions. nsown_capable
    is killed as it encourages not thinking about details that need to be
    considered. A very hard to hit pid namespace exiting bug was finally
    tracked and fixed. A couple of cleanups to the basic namespace
    infrastructure.

    Finally there is an enhancement that makes per user namespace
    capabilities usable as capabilities, and an enhancement that allows
    the per userns root to nice other processes in the user namespace"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
    userns: Kill nsown_capable it makes the wrong thing easy
    capabilities: allow nice if we are privileged
    pidns: Don't have unshare(CLONE_NEWPID) imply CLONE_THREAD
    userns: Allow PR_CAPBSET_DROP in a user namespace.
    namespaces: Simplify copy_namespaces so it is clear what is going on.
    pidns: Fix hang in zap_pid_ns_processes by sending a potentially extra wakeup
    sysfs: Restrict mounting sysfs
    userns: Better restrictions on when proc and sysfs can be mounted
    vfs: Don't copy mount bind mounts of /proc//ns/mnt between namespaces
    kernel/nsproxy.c: Improving a snippet of code.
    proc: Restrict mounting the proc filesystem
    vfs: Lock in place mounts from more privileged users

    Linus Torvalds
     

29 Aug, 2013

1 commit

  • Don't allow mounting sysfs unless the caller has CAP_SYS_ADMIN rights
    over the net namespace. The principle here is if you create or have
    capabilities over it you can mount it, otherwise you get to live with
    what other people have mounted.

    Instead of testing this with a straight forward ns_capable call,
    perform this check the long and torturous way with kobject helpers,
    this keeps direct knowledge of namespaces out of sysfs, and preserves
    the existing sysfs abstractions.

    Acked-by: Greg Kroah-Hartman
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

26 Jul, 2013

1 commit

  • Implement debugging for kobject release functions. kobjects are
    reference counted, so the drop of the last reference to them is not
    predictable. However, the common case is for the last reference to be
    the kobject's removal from a subsystem, which results in the release
    function being immediately called.

    This can hide subtle bugs, which can occur when another thread holds a
    reference to the kobject at the same time that a kobject is removed.
    This results in the release method being delayed.

    In order to make these kinds of problems more visible, the following
    patch implements a delayed release; this has the effect that the
    release function will be out of order with respect to the removal of
    the kobject in the same manner that it would be if a reference was
    being held.

    This provides us with an easy way to allow driver writers to debug
    their drivers and fix otherwise hidden problems.

    Signed-off-by: Russell King
    Signed-off-by: Greg Kroah-Hartman

    Russell King
     

08 Jun, 2013

1 commit

  • Unlike kobject_set_name(), the kset_create_and_add() interface does not
    provide a way to use format strings, so make sure that the interface
    cannot be abused accidentally. It looks like all current callers use
    static strings, so there's no existing flaw.

    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

08 May, 2013

1 commit

  • - make warning smp-safe
    - result of atomic _unless_zero functions should be checked by caller
    to avoid use-after-free error
    - trivial whitespace fix.

    Link: https://lkml.org/lkml/2013/4/12/391

    Tested: compile x86, boot machine and run xfstests
    Signed-off-by: Anatol Pomozov
    [ Removed line-break, changed to use WARN_ON_ONCE() - Linus ]
    Signed-off-by: Linus Torvalds

    Anatol Pomozov
     

14 Apr, 2013

1 commit

  • Anatol Pomozov identified a race condition that hits module unloading
    and re-loading. To quote Anatol:

    "This is a race codition that exists between kset_find_obj() and
    kobject_put(). kset_find_obj() might return kobject that has refcount
    equal to 0 if this kobject is freeing by kobject_put() in other
    thread.

    Here is timeline for the crash in case if kset_find_obj() searches for
    an object tht nobody holds and other thread is doing kobject_put() on
    the same kobject:

    THREAD A (calls kset_find_obj()) THREAD B (calls kobject_put())
    splin_lock()
    atomic_dec_return(kobj->kref), counter gets zero here
    ... starts kobject cleanup ....
    spin_lock() // WAIT thread A in kobj_kset_leave()
    iterate over kset->list
    atomic_inc(kobj->kref) (counter becomes 1)
    spin_unlock()
    spin_lock() // taken
    // it does not know that thread A increased counter so it
    remove obj from list
    spin_unlock()
    vfree(module) // frees module object with containing kobj

    // kobj points to freed memory area!!
    kobject_put(kobj) // OOPS!!!!

    The race above happens because module.c tries to use kset_find_obj()
    when somebody unloads module. The module.c code was introduced in
    commit 6494a93d55fa"

    Anatol supplied a patch specific for module.c that worked around the
    problem by simply not using kset_find_obj() at all, but rather than make
    a local band-aid, this just fixes kset_find_obj() to be thread-safe
    using the proper model of refusing the get a new reference if the
    refcount has already dropped to zero.

    See examples of this proper refcount handling not only in the kref
    documentation, but in various other equivalent uses of this pattern by
    grepping for atomic_inc_not_zero().

    [ Side note: the module race does indicate that module loading and
    unloading is not properly serialized wrt sysfs information using the
    module mutex. That may require further thought, but this is the
    correct fix at the kobject layer regardless. ]

    Reported-analyzed-and-tested-by: Anatol Pomozov
    Cc: Greg Kroah-Hartman
    Cc: Al Viro
    Cc: stable@vger.kernel.org
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

08 May, 2012

1 commit


03 May, 2012

1 commit


24 Apr, 2012

1 commit