Commit f8d4f618fed5a4978afada52166bc2efaf7656d1

Authored by Eric W. Biederman
Committed by Greg Kroah-Hartman
1 parent b35c74dab6

sysfs: Serialize updates to the vfs inode

The vfs depends upon filesystem methods to update the
vfs inode.   Sysfs adds to the normal number of places
where the vfs inode is updated by also updatng the
vfs inode in sysfs_refresh_inode.

Typically the inode mutex is used to serialize updates
to the vfs inode, but grabbing the inode mutex in
sysfs_permission and sysfs_getattr causes deadlocks,
because sometimes the vfs calls those operations with
the inode mutex held.  Therefore sysfs  can not use the
inode mutex to serial updates to the vfs inode.

The sysfs_mutex is acquired in all of the routines
where sysfs updates the vfs inode, and with a small
change we can consistently protext sysfs vfs inode
updates with the sysfs_mutex. To protect the sysfs
vfs inode updates with the sysfs_mutex simply requires
extending the scope of sysfs_mutex in sysfs_setattr
over inode_setattr, and over inode_change_ok (so we
have an unchanging inode when we perform the check).

Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 4 additions and 4 deletions Side-by-side Diff

... ... @@ -111,20 +111,20 @@
111 111 if (!sd)
112 112 return -EINVAL;
113 113  
  114 + mutex_lock(&sysfs_mutex);
114 115 error = inode_change_ok(inode, iattr);
115 116 if (error)
116   - return error;
  117 + goto out;
117 118  
118 119 iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */
119 120  
120 121 error = inode_setattr(inode, iattr);
121 122 if (error)
122   - return error;
  123 + goto out;
123 124  
124   - mutex_lock(&sysfs_mutex);
125 125 error = sysfs_sd_setattr(sd, iattr);
  126 +out:
126 127 mutex_unlock(&sysfs_mutex);
127   -
128 128 return error;
129 129 }
130 130