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 2/3] ext4: super: Fix spectre gadgets in ext4_quota_{read,write,off}
Date: Fri, 27 Jul 2018 16:23:56 +0000 [thread overview]
Message-ID: <20180727162357.30801-3-jcline@redhat.com> (raw)
In-Reply-To: <20180727162357.30801-1-jcline@redhat.com>
'type' is a user-controlled value used to index 'sb_dqopt(sb)->files'.
Clamp 'type' to the size of the array to avoid a speculative
out-of-bounds read.
These gadgets were found with the help of smatch:
* fs/ext4/super.c:5741 ext4_quota_read() warn: potential spectre issue
'sb_dqopt(sb)->files' [r]
* fs/ext4/super.c:5778 ext4_quota_write() warn: potential spectre issue
'sb_dqopt(sb)->files' [r]
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
fs/ext4/super.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index c04a09b51742..de358eba024a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5693,10 +5693,13 @@ static int ext4_enable_quotas(struct super_block *sb)
static int ext4_quota_off(struct super_block *sb, int type)
{
- struct inode *inode = sb_dqopt(sb)->files[type];
+ struct inode *inode;
handle_t *handle;
int err;
+ type = array_index_nospec(type, MAXQUOTAS);
+ inode = sb_dqopt(sb)->files[type];
+
/* Force all delayed allocation blocks to be allocated.
* Caller already holds s_umount sem */
if (test_opt(sb, DELALLOC))
@@ -5740,13 +5743,17 @@ static int ext4_quota_off(struct super_block *sb, int type)
static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
size_t len, loff_t off)
{
- struct inode *inode = sb_dqopt(sb)->files[type];
+ struct inode *inode;
ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
int offset = off & (sb->s_blocksize - 1);
int tocopy;
size_t toread;
struct buffer_head *bh;
- loff_t i_size = i_size_read(inode);
+ loff_t i_size;
+
+ type = array_index_nospec(type, MAXQUOTAS);
+ inode = sb_dqopt(sb)->files[type];
+ i_size = i_size_read(inode);
if (off > i_size)
return 0;
@@ -5777,13 +5784,16 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
static ssize_t ext4_quota_write(struct super_block *sb, int type,
const char *data, size_t len, loff_t off)
{
- struct inode *inode = sb_dqopt(sb)->files[type];
+ struct inode *inode;
ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
int err, offset = off & (sb->s_blocksize - 1);
int retries = 0;
struct buffer_head *bh;
handle_t *handle = journal_current_handle();
+ type = array_index_nospec(type, MAXQUOTAS);
+ inode = sb_dqopt(sb)->files[type];
+
if (EXT4_SB(sb)->s_journal && !handle) {
ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
" cancelled because transaction is not started",
--
2.17.1
next prev parent reply other threads:[~2018-07-27 16:23 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 ` Jeremy Cline [this message]
2018-07-27 16:23 ` [PATCH 3/3] ext4: mballoc: Fix spectre gadget in ext4_mb_simple_scan_group Jeremy Cline
2018-07-27 18:10 ` 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-3-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).