Skip to content

Commit ee3f65a

Browse files
jeremyclineZhengShunQian
authored andcommitted
ext4: fix spectre gadget in ext4_mb_regular_allocator()
commit 1a5d5e5 upstream. 'ac->ac_g_ex.fe_len' is a user-controlled value which is used in the derivation of 'ac->ac_2order'. 'ac->ac_2order', in turn, is used to index arrays which makes it a potential spectre gadget. Fix this by sanitizing the value assigned to 'ac->ac2_order'. This covers the following accesses found with the help of smatch: * fs/ext4/mballoc.c:1896 ext4_mb_simple_scan_group() warn: potential spectre issue 'grp->bb_counters' [w] (local cap) * fs/ext4/mballoc.c:445 mb_find_buddy() warn: potential spectre issue 'EXT4_SB(e4b->bd_sb)->s_mb_offsets' [r] (local cap) * fs/ext4/mballoc.c:446 mb_find_buddy() warn: potential spectre issue 'EXT4_SB(e4b->bd_sb)->s_mb_maxs' [r] (local cap) Suggested-by: Josh Poimboeuf <[email protected]> Signed-off-by: Jeremy Cline <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a7a5485 commit ee3f65a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/ext4/mballoc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/log2.h>
2727
#include <linux/module.h>
2828
#include <linux/slab.h>
29+
#include <linux/nospec.h>
2930
#include <linux/backing-dev.h>
3031
#include <trace/events/ext4.h>
3132

@@ -2144,7 +2145,8 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
21442145
* This should tell if fe_len is exactly power of 2
21452146
*/
21462147
if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
2147-
ac->ac_2order = i - 1;
2148+
ac->ac_2order = array_index_nospec(i - 1,
2149+
sb->s_blocksize_bits + 2);
21482150
}
21492151

21502152
/* if stream allocation is enabled, use global goal */

0 commit comments

Comments
 (0)