linux_dsm_epyc7002/drivers/md/bcache
Darrick J. Wong 9471744767 bcache: fix BUG_ON due to integer overflow with GC_SECTORS_USED
The BUG_ON at the end of __bch_btree_mark_key can be triggered due to
an integer overflow error:

BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, 13);
...
SET_GC_SECTORS_USED(g, min_t(unsigned,
	     GC_SECTORS_USED(g) + KEY_SIZE(k),
	     (1 << 14) - 1));
BUG_ON(!GC_SECTORS_USED(g));

In bcache.h, the SECTORS_USED bitfield is defined to be 13 bits wide.
While the SET_ code tries to ensure that the field doesn't overflow by
clamping it to (1<<14)-1 == 16383, this is incorrect because 16383
requires 14 bits.  Therefore, if GC_SECTORS_USED() + KEY_SIZE() =
8192, the SET_ statement tries to store 8192 into a 13-bit field.  In
a 13-bit field, 8192 becomes zero, thus triggering the BUG_ON.

Therefore, create a field width constant and a max value constant, and
use those to create the bitfield and check the inputs to
SET_GC_SECTORS_USED.  Arguably the BITMASK() template ought to have
BUG_ON checks for too-large values, but that's a separate patch.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2014-01-29 13:06:15 -08:00
..
alloc.c bcache: Improve bucket_prio() calculation 2014-01-08 13:05:14 -08:00
bcache.h bcache: fix BUG_ON due to integer overflow with GC_SECTORS_USED 2014-01-29 13:06:15 -08:00
bset.c bcache: Fix auxiliary search trees for key size > cacheline size 2014-01-08 13:05:15 -08:00
bset.h bcache: Add bch_bkey_equal_header() 2014-01-08 13:05:14 -08:00
btree.c bcache: fix BUG_ON due to integer overflow with GC_SECTORS_USED 2014-01-29 13:06:15 -08:00
btree.h bcache: Convert btree_iter to struct btree_keys 2014-01-08 13:05:13 -08:00
closure.c bcache: kill closure locking code 2014-01-08 13:05:08 -08:00
closure.h bcache: kill closure locking code 2014-01-08 13:05:08 -08:00
debug.c bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
debug.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
extents.c bcache: Add bch_bkey_equal_header() 2014-01-08 13:05:14 -08:00
extents.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
io.c block: Introduce new bio_split() 2013-11-23 22:33:57 -08:00
journal.c bcache: Rename/shuffle various code around 2014-01-08 13:05:12 -08:00
journal.h bcache: kill closure locking usage 2014-01-08 13:05:08 -08:00
Kconfig bcache: Debug code improvements 2013-11-10 21:56:34 -08:00
Makefile bcache: Abstract out stuff needed for sorting 2014-01-08 13:05:12 -08:00
movinggc.c bcache: Rework allocator reserves 2014-01-08 13:05:09 -08:00
request.c bcache: Make bch_keylist_realloc() take u64s, not nptrs 2014-01-08 13:05:11 -08:00
request.h bcache: Zero less memory 2014-01-08 13:05:08 -08:00
stats.c bcache: Break up struct search 2013-11-10 21:56:32 -08:00
stats.h bcache: Break up struct search 2013-11-10 21:56:32 -08:00
super.c bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
sysfs.c bcache: Convert btree_iter to struct btree_keys 2014-01-08 13:05:13 -08:00
sysfs.h bcache: Don't export utility code, prefix with bch_ 2013-03-28 12:50:55 -06:00
trace.c bcache: Break up struct search 2013-11-10 21:56:32 -08:00
util.c Linux 3.13-rc6 2013-12-31 09:51:02 -07:00
util.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
writeback.c Linux 3.13-rc6 2013-12-31 09:51:02 -07:00
writeback.h block: Abstract out bvec iterator 2013-11-23 22:33:47 -08:00