2018-01-22 16:18:13 +01:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-09-20 17:31:38 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-13 22:41:52 -04:00
|
|
|
|
2006-12-20 10:52:44 +01:00
|
|
|
|
2007-07-26 11:03:54 +00:00
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:34 -05:00
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
2013-10-01 17:41:57 -04:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-10-01 17:41:57 -04:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-10-01 17:41:57 -04:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2013-10-01 17:41:57 -04:00
|
|
|
|
2013-12-11 14:11:56 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-10-01 17:41:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-12-11 14:11:55 -05:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2014-05-19 15:52:10 -04:00
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-19 15:52:10 -04:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-14 03:45:16 +09:00
|
|
|
|
2007-11-21 14:55:19 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-04 15:09:07 -08:00
|
|
|
|
2017-12-11 21:50:22 +09:00
|
|
|
|
|
|
|
|
|
2008-03-04 15:09:07 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:02 -04:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:55 -05:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2013-10-01 17:42:06 -04:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2013-10-01 17:42:06 -04:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
2013-10-01 17:42:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-22 00:21:16 +03:00
|
|
|
|
2013-10-01 17:42:06 -04:00
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:06 -04:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysfs: be careful of error returns from ops->show()
ops->show() can return a negative error code.
Commit 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
(in v4.4) caused this to be stored in an unsigned 'size_t' variable, so errors
would look like large numbers.
As a result, if an error is returned, sysfs_kf_read() will return the
value of 'count', typically 4096.
Commit 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
(in v4.8) extended this error to use the unsigned large 'len' as a size for
memmove().
Consequently, if ->show returns an error, then the first read() on the
sysfs file will return 4096 and could return uninitialized memory to
user-space.
If the application performs a subsequent read, this will trigger a memmove()
with extremely large count, and is likely to crash the machine is bizarre ways.
This bug can currently only be triggered by reading from an md
sysfs attribute declared with __ATTR_PREALLOC() during the
brief period between when mddev_put() deletes an mddev from
the ->all_mddevs list, and when mddev_delayed_delete() - which is
scheduled on a workqueue - completes.
Before this, an error won't be returned by the ->show()
After this, the ->show() won't be called.
I can reproduce it reliably only by putting delay like
usleep_range(500000,700000);
early in mddev_delayed_delete(). Then after creating an
md device md0 run
echo clear > /sys/block/md0/md/array_state; cat /sys/block/md0/md/array_state
The bug can be triggered without the usleep.
Fixes: 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
Fixes: 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
Cc: stable@vger.kernel.org
Signed-off-by: NeilBrown <neilb@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reported-and-tested-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-04-03 11:30:34 +10:00
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-22 21:42:16 +03:00
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
2015-08-06 08:27:55 +10:00
|
|
|
|
sysfs: be careful of error returns from ops->show()
ops->show() can return a negative error code.
Commit 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
(in v4.4) caused this to be stored in an unsigned 'size_t' variable, so errors
would look like large numbers.
As a result, if an error is returned, sysfs_kf_read() will return the
value of 'count', typically 4096.
Commit 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
(in v4.8) extended this error to use the unsigned large 'len' as a size for
memmove().
Consequently, if ->show returns an error, then the first read() on the
sysfs file will return 4096 and could return uninitialized memory to
user-space.
If the application performs a subsequent read, this will trigger a memmove()
with extremely large count, and is likely to crash the machine is bizarre ways.
This bug can currently only be triggered by reading from an md
sysfs attribute declared with __ATTR_PREALLOC() during the
brief period between when mddev_put() deletes an mddev from
the ->all_mddevs list, and when mddev_delayed_delete() - which is
scheduled on a workqueue - completes.
Before this, an error won't be returned by the ->show()
After this, the ->show() won't be called.
I can reproduce it reliably only by putting delay like
usleep_range(500000,700000);
early in mddev_delayed_delete(). Then after creating an
md device md0 run
echo clear > /sys/block/md0/md/array_state; cat /sys/block/md0/md/array_state
The bug can be triggered without the usleep.
Fixes: 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
Fixes: 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
Cc: stable@vger.kernel.org
Signed-off-by: NeilBrown <neilb@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reported-and-tested-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-04-03 11:30:34 +10:00
|
|
|
|
|
|
|
|
|
2016-06-22 21:42:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysfs: be careful of error returns from ops->show()
ops->show() can return a negative error code.
Commit 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
(in v4.4) caused this to be stored in an unsigned 'size_t' variable, so errors
would look like large numbers.
As a result, if an error is returned, sysfs_kf_read() will return the
value of 'count', typically 4096.
Commit 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
(in v4.8) extended this error to use the unsigned large 'len' as a size for
memmove().
Consequently, if ->show returns an error, then the first read() on the
sysfs file will return 4096 and could return uninitialized memory to
user-space.
If the application performs a subsequent read, this will trigger a memmove()
with extremely large count, and is likely to crash the machine is bizarre ways.
This bug can currently only be triggered by reading from an md
sysfs attribute declared with __ATTR_PREALLOC() during the
brief period between when mddev_put() deletes an mddev from
the ->all_mddevs list, and when mddev_delayed_delete() - which is
scheduled on a workqueue - completes.
Before this, an error won't be returned by the ->show()
After this, the ->show() won't be called.
I can reproduce it reliably only by putting delay like
usleep_range(500000,700000);
early in mddev_delayed_delete(). Then after creating an
md device md0 run
echo clear > /sys/block/md0/md/array_state; cat /sys/block/md0/md/array_state
The bug can be triggered without the usleep.
Fixes: 65da3484d9be ("sysfs: correctly handle short reads on PREALLOC attrs.")
Fixes: 17d0774f8068 ("sysfs: correctly handle read offset on PREALLOC attrs")
Cc: stable@vger.kernel.org
Signed-off-by: NeilBrown <neilb@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reported-and-tested-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-04-03 11:30:34 +10:00
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2013-12-11 14:11:55 -05:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2007-06-14 03:45:16 +09:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
|
|
|
|
|
2007-06-14 03:45:16 +09:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2013-10-01 17:42:05 -04:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2013-12-11 14:11:55 -05:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2013-10-01 17:42:05 -04:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
|
|
|
|
|
2014-09-24 18:21:04 +03:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2013-10-01 17:42:05 -04:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
|
|
|
|
|
2007-06-14 03:45:16 +09:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-11-28 14:54:17 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:55 -05:00
|
|
|
|
2013-11-28 14:54:18 -05:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2013-11-28 14:54:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2006-03-20 17:53:53 +11:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2007-06-14 04:27:25 +09:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:27 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:27 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:27 -05:00
|
|
|
|
2007-06-14 04:27:25 +09:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:27 -05:00
|
|
|
|
2006-03-20 17:53:53 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-13 16:41:28 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
2014-10-13 16:41:28 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-10 09:29:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:23 -05:00
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-11-28 14:54:29 -05:00
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:22 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-11-28 14:54:23 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-13 16:41:28 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-14 16:57:26 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-13 16:41:28 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
2013-11-28 14:54:22 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-10 09:29:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:22 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:21 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
2018-07-20 21:56:47 +00:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-14 04:27:22 +09:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2010-01-05 12:48:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-21 16:17:47 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
2008-01-02 18:44:05 -06:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2007-06-14 04:27:22 +09:00
|
|
|
|
|
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
2018-07-27 21:33:27 +00:00
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2007-06-14 04:27:22 +09:00
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-18 21:57:32 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-02 16:54:05 +02:00
|
|
|
|
2011-07-24 03:40:40 -04:00
|
|
|
|
2005-04-18 21:57:32 -07:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2005-07-29 12:13:35 -07:00
|
|
|
|
2007-06-14 04:27:25 +09:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
2013-11-23 17:21:52 -05:00
|
|
|
|
2007-09-20 16:05:10 +09:00
|
|
|
|
2013-12-11 14:11:54 -05:00
|
|
|
|
2009-11-07 23:27:02 -08:00
|
|
|
|
2007-09-20 16:05:10 +09:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-23 17:21:52 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2007-06-14 04:27:25 +09:00
|
|
|
|
2005-04-18 21:57:32 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-02 10:51:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2011-10-12 21:53:38 +00:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-09-11 22:29:04 -04:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
kernfs, sysfs, driver-core: implement kernfs_remove_self() and its wrappers
Sometimes it's necessary to implement a node which wants to delete
nodes including itself. This isn't straightforward because of kernfs
active reference. While a file operation is in progress, an active
reference is held and kernfs_remove() waits for all such references to
drain before completing. For a self-deleting node, this is a deadlock
as kernfs_remove() ends up waiting for an active reference that itself
is sitting on top of.
This currently is worked around in the sysfs layer using
sysfs_schedule_callback() which makes such removals asynchronous.
While it works, it's rather cumbersome and inherently breaks
synchronicity of the operation - the file operation which triggered
the operation may complete before the removal is finished (or even
started) and the removal may fail asynchronously. If a removal
operation is immmediately followed by another operation which expects
the specific name to be available (e.g. removal followed by rename
onto the same name), there's no way to make the latter operation
reliable.
The thing is there's no inherent reason for this to be asynchrnous.
All that's necessary to do this synchronous is a dedicated operation
which drops its own active ref and deactivates self. This patch
implements kernfs_remove_self() and its wrappers in sysfs and driver
core. kernfs_remove_self() is to be called from one of the file
operations, drops the active ref the task is holding, removes the self
node, and restores active ref to the dead node so that the ref is
balanced afterwards. __kernfs_remove() is updated so that it takes an
early exit if the target node is already fully removed so that the
active ref restored by kernfs_remove_self() after removal doesn't
confuse the deactivation path.
This makes implementing self-deleting nodes very easy. The normal
removal path doesn't even need to be changed to use
kernfs_remove_self() for the self-deleting node. The method can
invoke kernfs_remove_self() on itself before proceeding the normal
removal path. kernfs_remove() invoked on the node by the normal
deletion path will simply be ignored.
This will replace sysfs_schedule_callback(). A subtle feature of
sysfs_schedule_callback() is that it collapses multiple invocations -
even if multiple removals are triggered, the removal callback is run
only once. An equivalent effect can be achieved by testing the return
value of kernfs_remove_self() - only the one which gets %true return
value should proceed with actual deletion. All other instances of
kernfs_remove_self() will wait till the enclosing kernfs operation
which invoked the winning instance of kernfs_remove_self() finishes
and then return %false. This trivially makes all users of
kernfs_remove_self() automatically show correct synchronous behavior
even when there are multiple concurrent operations - all "echo 1 >
delete" instances will finish only after the whole operation is
completed by one of the instances.
Note that manipulation of active ref is implemented in separate public
functions - kernfs_[un]break_active_protection().
kernfs_remove_self() is the only user at the moment but this will be
used to cater to more complex cases.
v2: For !CONFIG_SYSFS, dummy version kernfs_remove_self() was missing
and sysfs_remove_file_self() had incorrect return type. Fix it.
Reported by kbuild test bot.
v3: kernfs_[un]break_active_protection() separated out from
kernfs_remove_self() and exposed as public API.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-03 14:03:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-21 16:28:26 -07:00
|
|
|
|
2010-01-05 12:48:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-21 16:17:47 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
2013-11-28 14:54:30 -05:00
|
|
|
|
|
|
|
|
|
2013-12-11 14:11:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-20 15:02:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:09 -04:00
|
|
|
|
|
|
|
|
|
2018-07-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-01 17:42:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-23 17:21:49 -05:00
|
|
|
|
2013-10-01 17:42:09 -04:00
|
|
|
|
|
|
|
|
|