linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Cline <jcline@redhat.com>
To: Theodore Ts'o <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jeremy Cline <jcline@redhat.com>,
	stable@vger.kernel.org
Subject: [PATCH 3/3] ext4: mballoc: Fix spectre gadget in ext4_mb_simple_scan_group
Date: Fri, 27 Jul 2018 16:23:57 +0000	[thread overview]
Message-ID: <20180727162357.30801-4-jcline@redhat.com> (raw)
In-Reply-To: <20180727162357.30801-1-jcline@redhat.com>

'ac->ac_2order' is a user-controlled value used to index into
'grp->bb_counters' and based on the value at that index, 'ac->ac_found'
is written to. Clamp the value right after the bounds check to avoid a
speculative out-of-bounds read of 'grp->bb_counters'.

This also protects the access of the s_mb_offsets and s_mb_maxs arrays
inside mb_find_buddy().

These gadgets were discovered 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)

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
 fs/ext4/mballoc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index f7ab34088162..c0866007a949 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -14,6 +14,7 @@
 #include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/nospec.h>
 #include <linux/backing-dev.h>
 #include <trace/events/ext4.h>
 
@@ -1893,6 +1894,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
 
 	BUG_ON(ac->ac_2order <= 0);
 	for (i = ac->ac_2order; i <= sb->s_blocksize_bits + 1; i++) {
+		i = array_index_nospec(i, sb->s_blocksize_bits + 2);
 		if (grp->bb_counters[i] == 0)
 			continue;
 
-- 
2.17.1


  parent reply	other threads:[~2018-07-27 16:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 16:23 [PATCH 0/3] ext4: fix spectre v1 gadgets Jeremy Cline
2018-07-27 16:23 ` [PATCH 1/3] ext4: super: Fix spectre gadget in ext4_quota_on Jeremy Cline
2018-07-27 17:46   ` Josh Poimboeuf
2018-07-27 19:17     ` Jeremy Cline
2018-07-31  6:39     ` Andreas Dilger
2018-07-31 17:31       ` Josh Poimboeuf
2018-07-27 16:23 ` [PATCH 2/3] ext4: super: Fix spectre gadgets in ext4_quota_{read,write,off} Jeremy Cline
2018-07-27 16:23 ` Jeremy Cline [this message]
2018-07-27 18:10   ` [PATCH 3/3] ext4: mballoc: Fix spectre gadget in ext4_mb_simple_scan_group Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180727162357.30801-4-jcline@redhat.com \
    --to=jcline@redhat.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jpoimboe@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).