Re: What protection does sysfs_readdir have with SMP/Preemption?

From: Steven Rostedt (rostedt_at_goodmis.org)
Date: 11/23/05

  • Next message: Michal Piotrowski: "Re: 2.6.15-rc2-mm1"
    To: maneesh@in.ibm.com
    Date:	Wed, 23 Nov 2005 09:15:44 -0500
    
    

    On Wed, 2005-11-23 at 19:28 +0530, Maneesh Soni wrote:

    >
    > hmm looks like we got some situation which is not desirable and could lead
    > to bogus sysfs_dirent in the parent list. It may not be the exact problem
    > in this case though, but needs fixing IMO.
    >
    > After sysfs_make_dirent(), the ref count for sysfs dirent will be 2.
    > (one from allocation, and after linking the new dentry to it). On
    > error from sysfs_create(), we do sysfs_put() once, decrementing the
    > ref count to 1. And again when the new dentry for which we couldn't
    > allocate the d_inode, is d_drop()'ed. In sysfs_d_iput() we again
    > sysfs_put(), and decrement the sysfs dirent's ref count to 0, which will
    > be the final sysfs_put(), and it will free the sysfs_dirent but never
    > unlinks it from the parent list. So, parent list could still will having
    > links to the freed sysfs_dirent in its s_children list.
    >
    > so basically list_del_init(&sd->s_sibling) should be done in error path
    > in create_dir().
    >
    > Could you also put the appended patch in your trial runs..
    >

    I'm already playing around with this. You might want this patch instead.
    I noticed that if sysfs_make_dirent fails to allocate the sd, then a
    null will be passed to sysfs_put.

    But this is not the end of the problems. I'll follow up on that comment
    right after this.

    -- Steve

    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

    Index: linux-2.6.15-rc2-git2/fs/sysfs/dir.c
    ===================================================================
    --- linux-2.6.15-rc2-git2.orig/fs/sysfs/dir.c 2005-11-23 08:40:33.000000000 -0500
    +++ linux-2.6.15-rc2-git2/fs/sysfs/dir.c 2005-11-23 08:52:57.000000000 -0500
    @@ -112,7 +112,11 @@
                             }
                     }
                     if (error && (error != -EEXIST)) {
    - sysfs_put((*d)->d_fsdata);
    + struct sysfs_dirent *sd = (*d)->d_fsdata;
    + if (sd) {
    + list_del_init(&sd->s_sibling);
    + sysfs_put(sd);
    + }
                             d_drop(*d);
                     }
                     dput(*d);

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Michal Piotrowski: "Re: 2.6.15-rc2-mm1"

    Relevant Pages

    • Re: [PATCH] Re: Major XFS problems...
      ... > patch is included in mainline - it is the old patch from Neil Brown ... -struct dentry * d_find_alias(struct inode *inode) ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ - ...
      (Linux-Kernel)
    • Re: [PATCH] per-user signal pending and message queue limits
      ... my head is gently rotating wrt this patch. ... * Locate the user_struct for the passed UID. ... take a ref on it. ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • Re: [PATCH] sysfs & dput.
      ... > solution is to remove the assignment of the error to dentry. ... However, your patch drops the error value, and his adds another variable. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH] Problems with NFS while running SpecSFS with JFS filesystem and 2.6 kernel.
      ... After Jose debugged the problem down to the routine jfs_get_parent, ... Does this patch ... struct dentry *jfs_get_parent ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] prom_find_machine_type typo breaks pSeries lpar boot
      ... ref" before sending the patch (as I did notice this typo and fixed it ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)