<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/drivers/md/bcache/sysfs.c, branch linux-5.1.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-5.1.y</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-5.1.y'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2019-07-26T07:12:55Z</updated>
<entry>
<title>bcache: fix mistaken sysfs entry for io_error counter</title>
<updated>2019-07-26T07:12:55Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-06-28T11:59:43Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=f85c665b20a5a9a700c9b0707f7a960a1ea2ae14'/>
<id>urn:sha1:f85c665b20a5a9a700c9b0707f7a960a1ea2ae14</id>
<content type='text'>
commit 5461999848e0462c14f306a62923d22de820a59c upstream.

In bch_cached_dev_files[] from driver/md/bcache/sysfs.c, sysfs_errors is
incorrectly inserted in. The correct entry should be sysfs_io_errors.

This patch fixes the problem and now I/O errors of cached device can be
read from /sys/block/bcache&lt;N&gt;/bcache/io_errors.

Fixes: c7b7bd07404c5 ("bcache: add io_disable to struct cached_dev")
Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>bcache: only set BCACHE_DEV_WB_RUNNING when cached device attached</title>
<updated>2019-06-19T06:00:04Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-06-09T22:13:35Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=13101dcfa290eb36af432dc878f655c6ec04b539'/>
<id>urn:sha1:13101dcfa290eb36af432dc878f655c6ec04b539</id>
<content type='text'>
commit 1f0ffa67349c56ea54c03ccfd1e073c990e7411e upstream.

When people set a writeback percent via sysfs file,
  /sys/block/bcache&lt;N&gt;/bcache/writeback_percent
current code directly sets BCACHE_DEV_WB_RUNNING to dc-&gt;disk.flags
and schedules kworker dc-&gt;writeback_rate_update.

If there is no cache set attached to, the writeback kernel thread is
not running indeed, running dc-&gt;writeback_rate_update does not make
sense and may cause NULL pointer deference when reference cache set
pointer inside update_writeback_rate().

This patch checks whether the cache set point (dc-&gt;disk.c) is NULL in
sysfs interface handler, and only set BCACHE_DEV_WB_RUNNING and
schedule dc-&gt;writeback_rate_update when dc-&gt;disk.c is not NULL (it
means the cache device is attached to a cache set).

This problem might be introduced from initial bcache commit, but
commit 3fd47bfe55b0 ("bcache: stop dc-&gt;writeback_rate_update properly")
changes part of the original code piece, so I add 'Fixes: 3fd47bfe55b0'
to indicate from which commit this patch can be applied.

Fixes: 3fd47bfe55b0 ("bcache: stop dc-&gt;writeback_rate_update properly")
Reported-by: Bjørn Forsman &lt;bjorn.forsman@gmail.com&gt;
Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Reviewed-by: Bjørn Forsman &lt;bjorn.forsman@gmail.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>bcache: fix input overflow to cache set sysfs file io_error_halflife</title>
<updated>2019-02-09T14:18:33Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:10Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=a91fbda49f746119828f7e8ad0f0aa2ab0578f65'/>
<id>urn:sha1:a91fbda49f746119828f7e8ad0f0aa2ab0578f65</id>
<content type='text'>
Cache set sysfs entry io_error_halflife is used to set c-&gt;error_decay.
c-&gt;error_decay is in type unsigned int, and it is converted by
strtoul_or_return(), therefore overflow to c-&gt;error_decay is possible
for a large input value.

This patch fixes the overflow by using strtoul_safe_clamp() to convert
input string to an unsigned long value in range [0, UINT_MAX], then
divides by 88 and set it to c-&gt;error_decay.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix input overflow to cache set io_error_limit</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:09Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=b15008403b59955c9fa0c8b55cadd6dae991a4e9'/>
<id>urn:sha1:b15008403b59955c9fa0c8b55cadd6dae991a4e9</id>
<content type='text'>
c-&gt;error_limit is in type unsigned int, it is set via cache set sysfs
file io_error_limit. Inside the bcache code, input string is converted
by strtoul_or_return() and set the converted value to c-&gt;error_limit.

Because the converted value is unsigned long, and c-&gt;error_limit is
unsigned int, if the input is large enought, overflow will happen to
c-&gt;error_limit.

This patch uses sysfs_strtoul_clamp() to convert input string, and set
the range in [0, UINT_MAX] to avoid the potential overflow.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix input overflow to journal_delay_ms</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:08Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=453745fbbebecf7e459785db7e29e11563908525'/>
<id>urn:sha1:453745fbbebecf7e459785db7e29e11563908525</id>
<content type='text'>
c-&gt;journal_delay_ms is in type unsigned short, it is set via sysfs
interface and converted by sysfs_strtoul() from input string to
unsigned short value. Therefore overflow to unsigned short might be
happen when the converted value exceed USHRT_MAX. e.g. writing
65536 into sysfs file journal_delay_ms, c-&gt;journal_delay_ms is set to
0.

This patch uses sysfs_strtoul_clamp() to convert the input string and
limit value range in [0, USHRT_MAX], to avoid the input overflow.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix input overflow to writeback_rate_minimum</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:07Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=dab71b2db98dcdd4657d151b01a7be88ce10f9d1'/>
<id>urn:sha1:dab71b2db98dcdd4657d151b01a7be88ce10f9d1</id>
<content type='text'>
dc-&gt;writeback_rate_minimum is type unsigned integer variable, it is set
via sysfs interface, and converte from input string to unsigned integer
by d_strtoul_nonzero(). When the converted input value is larger than
UINT_MAX, overflow to unsigned integer happens.

This patch fixes the overflow by using sysfs_strotoul_clamp() to
convert input string and limit the value in range [1, UINT_MAX], then
the overflow can be avoided.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix potential div-zero error of writeback_rate_p_term_inverse</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:06Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=5b5fd3c94eef69dcfaa8648198e54c92e5687d6d'/>
<id>urn:sha1:5b5fd3c94eef69dcfaa8648198e54c92e5687d6d</id>
<content type='text'>
Current code already uses d_strtoul_nonzero() to convert input string
to an unsigned integer, to make sure writeback_rate_p_term_inverse
won't be zero value. But overflow may happen when converting input
string to an unsigned integer value by d_strtoul_nonzero(), then
dc-&gt;writeback_rate_p_term_inverse can still be set to 0 even if the
sysfs file input value is not zero, e.g. 4294967296 (a.k.a UINT_MAX+1).

If dc-&gt;writeback_rate_p_term_inverse is set to 0, it might cause a
dev-zero error in following code from __update_writeback_rate(),
	int64_t proportional_scaled =
		div_s64(error, dc-&gt;writeback_rate_p_term_inverse);

This patch replaces d_strtoul_nonzero() by sysfs_strtoul_clamp() and
limit the value range in [1, UINT_MAX]. Then the unsigned integer
overflow and dev-zero error can be avoided.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix potential div-zero error of writeback_rate_i_term_inverse</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:05Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=c3b75a2199cdbfc1c335155fe143d842604b1baa'/>
<id>urn:sha1:c3b75a2199cdbfc1c335155fe143d842604b1baa</id>
<content type='text'>
dc-&gt;writeback_rate_i_term_inverse can be set via sysfs interface. It is
in type unsigned int, and convert from input string by d_strtoul(). The
problem is d_strtoul() does not check valid range of the input, if
4294967296 is written into sysfs file writeback_rate_i_term_inverse,
an overflow of unsigned integer will happen and value 0 is set to
dc-&gt;writeback_rate_i_term_inverse.

In writeback.c:__update_writeback_rate(), there are following lines of
code,
      integral_scaled = div_s64(dc-&gt;writeback_rate_integral,
                      dc-&gt;writeback_rate_i_term_inverse);
If dc-&gt;writeback_rate_i_term_inverse is set to 0 via sysfs interface,
a div-zero error might be triggered in the above code.

Therefore we need to add a range limitation in the sysfs interface,
this is what this patch does, use sysfs_stroul_clamp() to replace
d_strtoul() and restrict the input range in [1, UINT_MAX].

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix input overflow to writeback_delay</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:04Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=369d21a73a241682de019ac5c5209ce3ec627743'/>
<id>urn:sha1:369d21a73a241682de019ac5c5209ce3ec627743</id>
<content type='text'>
Sysfs file writeback_delay is used to configure dc-&gt;writeback_delay
which is type unsigned int. But bcache code uses sysfs_strtoul() to
convert the input string, therefore it might be overflowed if the input
value is too large. E.g. input value is 4294967296 but indeed 0 is
set to dc-&gt;writeback_delay.

This patch uses sysfs_strtoul_clamp() to convert the input string and
set the result value range in [0, UINT_MAX] to avoid such unsigned
integer overflow.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: use sysfs_strtoul_bool() to set bit-field variables</title>
<updated>2019-02-09T14:18:32Z</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2019-02-09T04:53:03Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=f5c0b95d2eeb17cf8a81fde0461938d2a79303ab'/>
<id>urn:sha1:f5c0b95d2eeb17cf8a81fde0461938d2a79303ab</id>
<content type='text'>
When setting bcache parameters via sysfs, there are some variables are
defined as bit-field value. Current bcache code in sysfs.c uses either
d_strtoul() or sysfs_strtoul() to convert the input string to unsigned
integer value and set it to the corresponded bit-field value.

The problem is, the bit-field value only takes the lowest bit of the
converted value. If input is 2, the expected value (like bool value)
of the bit-field value should be 1, but indeed it is 0.

The following sysfs files for bit-field variables have such problem,
	bypass_torture_test,	for dc-&gt;bypass_torture_test
	writeback_metadata,	for dc-&gt;writeback_metadata
	writeback_running,	for dc-&gt;writeback_running
	verify,			for c-&gt;verify
	key_merging_disabled,	for c-&gt;key_merging_disabled
	gc_always_rewrite,	for c-&gt;gc_always_rewrite
	btree_shrinker_disabled,for c-&gt;shrinker_disabled
	copy_gc_enabled,	for c-&gt;copy_gc_enabled

This patch uses sysfs_strtoul_bool() to set such bit-field variables,
then if the converted value is non-zero, the bit-field variables will
be set to 1, like setting a bool value like expensive_debug_checks.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
</feed>
