Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3315500imu; Sun, 11 Nov 2018 12:12:03 -0800 (PST) X-Google-Smtp-Source: AJdET5cBecENJHfYsBvx5aiZ2qBWd5M89cqp0wL8wQoo5tjC6J7JKkYZxC7y44zG9cXiFmPdnW/w X-Received: by 2002:a17:902:7c0a:: with SMTP id x10-v6mr10044417pll.263.1541967123719; Sun, 11 Nov 2018 12:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967123; cv=none; d=google.com; s=arc-20160816; b=ApulcpHL63sw2oqvbJKM4kMkJCCsgaHBf0+Jin7vWvQ+mkvNuvLf02rE3UzxYuEzeo em6yDsqPPRKEXlREAYNi9cBBkxEpQiXMYe2sds325e8SHQAfB1Jha8tlOZuSIdxcQbqv XV2nV9SoTd4oxgnBCB+7HntOasUHH1jcztmbkcHNXIDtBZLhrqIwWIjO/+5uFTw6EJ6d JWQY8LVhFOHuHMlxLRnTMIqCj8Sk0QaupDWcqk6/uI0H5c5/zFAnLA9DnkRXQxed/T7l BB0cUuWcNWGjNpmrCJTxbolqhVmwVWIHHWCbIJqJ1WdPNfBSyLsIMhTnaqMd3/3os1yx 7WHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=4E0FDT6QsOhPCuGB8a7H4sqjzKyjubM92G6NN+eqoaI=; b=NL138A3oA2zi4w2a7+M2PCqxvARajESypHUoFw/MgHTA9E78z/Z0b6E9Duj87MVJJN N/LAK2NM2luxYNCVhmAwjPjmOVqhro+Scj2dpJBUOU175EUnLQU89WDzXszD1omINCDw GVZl/dtfP5xv6eDSVA4stARh7l46btR5Mk/6Dk6x2z3ju1WJuFWchisnaX0U++8Sq4pR cP9CUbryMMzanUPeqFUlprFSZ7vLfZ2v0gYYCt92YdogykEYJw7S0re7OWjqK4S4fbmn 7HquY4bTEaHR2fm/Y/9IfWIQ+yHp9KWLp/urrlkCR5EAvRJJDsjG19IIz/GOA3qsUaLQ IeLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si16068194plr.113.2018.11.11.12.11.48; Sun, 11 Nov 2018 12:12:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731583AbeKLGAW (ORCPT + 99 others); Mon, 12 Nov 2018 01:00:22 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52410 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726471AbeKLGAW (ORCPT ); Mon, 12 Nov 2018 01:00:22 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt8-0000l6-4u; Sun, 11 Nov 2018 19:59:18 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsP-0001SE-VP; Sun, 11 Nov 2018 19:58:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Theodore Ts'o" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 077/366] ext4: check if in-inode xattr is corrupted in ext4_expand_extra_isize_ea() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 9e92f48c34eb2b9af9d12f892e2fe1fce5e8ce35 upstream. We aren't checking to see if the in-inode extended attribute is corrupted before we try to expand the inode's extra isize fields. This can lead to potential crashes caused by the BUG_ON() check in ext4_xattr_shift_entries(). Signed-off-by: Theodore Ts'o [bwh: Backported to 3.16: s/EFSCORRUPTED/EIO/] Signed-off-by: Ben Hutchings --- fs/ext4/xattr.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -243,6 +243,27 @@ ext4_xattr_check_block(struct inode *ino return error; } +static int +__xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header, + void *end, const char *function, unsigned int line) +{ + struct ext4_xattr_entry *entry = IFIRST(header); + int error = -EIO; + + if (((void *) header >= end) || + (header->h_magic != le32_to_cpu(EXT4_XATTR_MAGIC))) + goto errout; + error = ext4_xattr_check_names(entry, end, entry); +errout: + if (error) + __ext4_error_inode(inode, function, line, 0, + "corrupted in-inode xattr"); + return error; +} + +#define xattr_check_inode(inode, header, end) \ + __xattr_check_inode((inode), (header), (end), __func__, __LINE__) + static inline int ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size) { @@ -368,7 +389,7 @@ ext4_xattr_ibody_get(struct inode *inode header = IHDR(inode, raw_inode); entry = IFIRST(header); end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; - error = ext4_xattr_check_names(entry, end, entry); + error = xattr_check_inode(inode, header, end); if (error) goto cleanup; error = xattr_find_entry(inode, &entry, end, name_index, name, @@ -506,7 +527,7 @@ ext4_xattr_ibody_list(struct dentry *den raw_inode = ext4_raw_inode(&iloc); header = IHDR(inode, raw_inode); end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; - error = ext4_xattr_check_names(IFIRST(header), end, IFIRST(header)); + error = xattr_check_inode(inode, header, end); if (error) goto cleanup; error = ext4_xattr_list_entries(dentry, IFIRST(header), @@ -1038,8 +1059,7 @@ int ext4_xattr_ibody_find(struct inode * is->s.here = is->s.first; is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) { - error = ext4_xattr_check_names(IFIRST(header), is->s.end, - IFIRST(header)); + error = xattr_check_inode(inode, header, is->s.end); if (error) return error; /* Find the named attribute. */ @@ -1319,6 +1339,10 @@ retry: last = entry; total_ino = sizeof(struct ext4_xattr_ibody_header); + error = xattr_check_inode(inode, header, end); + if (error) + goto cleanup; + free = ext4_xattr_free_space(last, &min_offs, base, &total_ino); if (free >= new_extra_isize) { entry = IFIRST(header);