summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--patches/cve/CVE-2018-1093-ext4-add-validity-checks-for-bitmap-block-numbers.patch109
1 files changed, 109 insertions, 0 deletions
diff --git a/patches/cve/CVE-2018-1093-ext4-add-validity-checks-for-bitmap-block-numbers.patch b/patches/cve/CVE-2018-1093-ext4-add-validity-checks-for-bitmap-block-numbers.patch
new file mode 100644
index 0000000..a466303
--- /dev/null
+++ b/patches/cve/CVE-2018-1093-ext4-add-validity-checks-for-bitmap-block-numbers.patch
@@ -0,0 +1,109 @@
1From b39430ea068797bb45b72429db3743064280b1be Mon Sep 17 00:00:00 2001
2From: Theodore Ts'o <tytso@mit.edu>
3Date: Mon, 26 Mar 2018 23:54:10 -0400
4Subject: [PATCH] ext4: add validity checks for bitmap block numbers
5
6commit 7dac4a1726a9c64a517d595c40e95e2d0d135f6f upstream.
7
8An privileged attacker can cause a crash by mounting a crafted ext4
9image which triggers a out-of-bounds read in the function
10ext4_valid_block_bitmap() in fs/ext4/balloc.c.
11
12This issue has been assigned CVE-2018-1093.
13
14CVE: CVE-2018-1093
15Upstream-Status: Backport [https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=b39430ea068797bb45b72429db3743064280b1be]
16
17BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199181
18BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1560782
19Reported-by: Wen Xu <wen.xu@gatech.edu>
20Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21Cc: stable@vger.kernel.org
22Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23Signed-off-by: Andreas Wellving <andreas.wellving@enea.com>
24---
25 fs/ext4/balloc.c | 16 ++++++++++++++--
26 fs/ext4/ialloc.c | 7 +++++++
27 2 files changed, 21 insertions(+), 2 deletions(-)
28
29diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
30index db5be5e2e6f2..6dafd9d001c7 100644
31--- a/fs/ext4/balloc.c
32+++ b/fs/ext4/balloc.c
33@@ -338,20 +338,25 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
34 /* check whether block bitmap block number is set */
35 blk = ext4_block_bitmap(sb, desc);
36 offset = blk - group_first_block;
37- if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
38+ if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
39+ !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
40 /* bad block bitmap */
41 return blk;
42
43 /* check whether the inode bitmap block number is set */
44 blk = ext4_inode_bitmap(sb, desc);
45 offset = blk - group_first_block;
46- if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
47+ if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
48+ !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
49 /* bad block bitmap */
50 return blk;
51
52 /* check whether the inode table block number is set */
53 blk = ext4_inode_table(sb, desc);
54 offset = blk - group_first_block;
55+ if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
56+ EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= sb->s_blocksize)
57+ return blk;
58 next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
59 EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
60 EXT4_B2C(sbi, offset));
61@@ -417,6 +422,7 @@ struct buffer_head *
62 ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
63 {
64 struct ext4_group_desc *desc;
65+ struct ext4_sb_info *sbi = EXT4_SB(sb);
66 struct buffer_head *bh;
67 ext4_fsblk_t bitmap_blk;
68 int err;
69@@ -425,6 +431,12 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
70 if (!desc)
71 return ERR_PTR(-EFSCORRUPTED);
72 bitmap_blk = ext4_block_bitmap(sb, desc);
73+ if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
74+ (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
75+ ext4_error(sb, "Invalid block bitmap block %llu in "
76+ "block_group %u", bitmap_blk, block_group);
77+ return ERR_PTR(-EFSCORRUPTED);
78+ }
79 bh = sb_getblk(sb, bitmap_blk);
80 if (unlikely(!bh)) {
81 ext4_error(sb, "Cannot get buffer for block bitmap - "
82diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
83index 7ec55dd8db56..f420124ac035 100644
84--- a/fs/ext4/ialloc.c
85+++ b/fs/ext4/ialloc.c
86@@ -122,6 +122,7 @@ static struct buffer_head *
87 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
88 {
89 struct ext4_group_desc *desc;
90+ struct ext4_sb_info *sbi = EXT4_SB(sb);
91 struct buffer_head *bh = NULL;
92 ext4_fsblk_t bitmap_blk;
93 int err;
94@@ -131,6 +132,12 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
95 return ERR_PTR(-EFSCORRUPTED);
96
97 bitmap_blk = ext4_inode_bitmap(sb, desc);
98+ if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
99+ (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
100+ ext4_error(sb, "Invalid inode bitmap blk %llu in "
101+ "block_group %u", bitmap_blk, block_group);
102+ return ERR_PTR(-EFSCORRUPTED);
103+ }
104 bh = sb_getblk(sb, bitmap_blk);
105 if (unlikely(!bh)) {
106 ext4_error(sb, "Cannot read inode bitmap - "
107--
1082.20.1
109