From: Theodore Ts'o Date: Wed, 13 Jun 2018 04:51:28 +0000 (-0400) Subject: ext4: always verify the magic number in xattr blocks X-Git-Tag: v4.1.12-124.31.3~240 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9c0e4d398e7180269e3b166eb0de13d4f2965df2;p=users%2Fjedix%2Flinux-maple.git ext4: always verify the magic number in xattr blocks commit 513f86d73855ce556ea9522b6bfd79f87356dc3a upstream. If there an inode points to a block which is also some other type of metadata block (such as a block allocation bitmap), the buffer_verified flag can be set when it was validated as that other metadata block type; however, it would make a really terrible external attribute block. The reason why we use the verified flag is to avoid constantly reverifying the block. However, it doesn't take much overhead to make sure the magic number of the xattr block is correct, and this will avoid potential crashes. This addresses CVE-2018-10879. https://bugzilla.kernel.org/show_bug.cgi?id=200001 Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 3150e8913b957d71398511a0580606e181153d10) Orabug: 29437127 CVE: CVE-2018-10879 Signed-off-by: John Donnelly Reviewed-by: Jack Vogel Signed-off-by: Brian Maly Conflicts: fs/ext4/xattr.c Signed-off-by: Brian Maly --- diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 72721c8c3585..fc023d3af21e 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -213,25 +213,37 @@ ext4_xattr_check_names(struct ext4_xattr_entry *entry, void *end, } static inline int -ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh) +__ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh, + const char *function, unsigned int line) { - int error; + int error = -EFSCORRUPTED; + if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || + BHDR(bh)->h_blocks != cpu_to_le32(1)) + goto errout; if (buffer_verified(bh)) return 0; + + error = -EFSBADCRC; - if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || - BHDR(bh)->h_blocks != cpu_to_le32(1)) - return -EIO; if (!ext4_xattr_block_csum_verify(inode, bh->b_blocknr, BHDR(bh))) - return -EIO; + goto errout; + error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size, bh->b_data); - if (!error) +errout: + if (error) + __ext4_error_inode(inode, function, line, 0, + "corrupted xattr block %llu", + (unsigned long long) bh->b_blocknr); + else set_buffer_verified(bh); return error; } +#define ext4_xattr_check_block(inode, bh) \ + __ext4_xattr_check_block((inode), (bh), __func__, __LINE__) + static inline int ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size) {