Files
linux/drivers/md/bcache
Darrick J. Wong b8bb5472da bcache: fix BUG_ON due to integer overflow with GC_SECTORS_USED
commit 9471744767 upstream.

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>
Cc: Kent Overstreet <kmo@daterainc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-20 11:10:11 -08:00
..
2014-02-06 11:34:06 -08:00
2013-11-10 21:56:39 -08:00
2013-11-10 21:56:10 -08:00
2013-11-10 21:56:10 -08:00
2013-11-10 21:56:43 -08:00
2013-11-10 21:56:43 -08:00
2013-07-01 14:43:53 -07:00
2013-11-10 21:56:34 -08:00
2013-03-23 16:11:31 -07:00
2013-11-10 21:56:43 -08:00
2013-11-10 21:56:32 -08:00
2013-11-10 21:56:32 -08:00
2013-12-16 14:22:57 -08:00
2013-12-16 14:22:59 -08:00
2013-11-10 21:56:32 -08:00
2013-12-16 14:22:59 -08:00
2013-12-16 14:22:57 -08:00