Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3317276imu; Sun, 11 Nov 2018 12:13:57 -0800 (PST) X-Google-Smtp-Source: AJdET5fqyry23o2BXwujSF6twlsGmg3eEJR3wNtyr8fdXmeQytUbjrMI39J2ZWJKf3810JkOEGZY X-Received: by 2002:a65:4b82:: with SMTP id t2mr15164062pgq.189.1541967237822; Sun, 11 Nov 2018 12:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967237; cv=none; d=google.com; s=arc-20160816; b=l+7uoiFG8+JYmPjyaseeWi1++7kS8DvB19X+UHQvj8DkKfRxnCo/CD6PSYZYX0nttj LBRut/jdjVnjcfnAfN0ilPDeT5mxgcZ8xMbliKWQQZCSMaMITLeeW2VObYgNB9/lRhIR +BFwm6PxfwJbrInXds4488fzmuIQXi1cTi2CD8q1EO5wY7Pl5ct0sZndl6ksvm3t4wt4 ZCCTw4nKw+4Y3QJbBHBU72kCE5K5IQwKdIr+cU5LdibODWueO0EekXzXLbW/rrGgZwnX 4C2oebudgf9Hij9XXLv5FpYC8VHMnA/tXTkkgzE9Rs8G+BoAQ5kMHWKOI2SFdIeBeqkB spZg== 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=tqQIawOoN3yn0zBmbimrEwWhHWQ9PmxpR1/hLAjFqUc=; b=onb/YKu81XPMW7oECWdxrFhiaFe+TNAjHv3ZvzC348rC0JcIzwrLPr7iPlG9Dbk9M0 NCZcFpcmRaoc/IcDtO8vfG9RmDUaprQcQjicfqjGPNIi+dbVQ+4QQXtXK7uza3KS9Kf3 hwVAEfRCCrhXIDtXJAo0qcmX3kdP/3LBbIedWSG8K4JlRWz0+DxlwBDhJkbNgKJQg1v+ emDI4X+a++EXH6eduPjG1fwXBf6TeV2miyuzgKGDk5NPKz039ASkqfObFSLttXaLR8Sm Ak3ht/AS+ax+PUgoPydvPpZ6HjA7k4zB1ido6p4qd8Qv0LXGczyIZVv8F++GSbIH20Ur xERw== 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 u7si14815130pgg.357.2018.11.11.12.13.42; Sun, 11 Nov 2018 12:13:57 -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 S1731593AbeKLGCi (ORCPT + 99 others); Mon, 12 Nov 2018 01:02:38 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52686 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726709AbeKLGCi (ORCPT ); Mon, 12 Nov 2018 01:02:38 -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 1gLvt7-0000lK-M0; Sun, 11 Nov 2018 19:59:17 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsQ-0001SO-1e; Sun, 11 Nov 2018 19:58:34 +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, "Eric Biggers" , "Theodore Ts'o" , "Andreas Dilger" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 079/366] ext4: don't read out of bounds when checking for in-inode xattrs 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: Eric Biggers commit 290ab230016f187c3551d8380ea742889276d03a upstream. With i_extra_isize equal to or close to the available space, it was possible for us to read past the end of the inode when trying to detect or validate in-inode xattrs. Fix this by checking for the needed extra space first. This patch shouldn't have any noticeable effect on non-corrupted/non-malicious filesystems. Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/ext4/inode.c | 4 +++- fs/ext4/xattr.c | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4165,7 +4165,9 @@ static inline void ext4_iget_extra_inode { __le32 *magic = (void *)raw_inode + EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize; - if (*magic == cpu_to_le32(EXT4_XATTR_MAGIC)) { + if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize + sizeof(__le32) <= + EXT4_INODE_SIZE(inode->i_sb) && + *magic == cpu_to_le32(EXT4_XATTR_MAGIC)) { ext4_set_inode_state(inode, EXT4_STATE_XATTR); ext4_find_inline_data_nolock(inode); } else --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -247,13 +247,12 @@ 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) || + if (end - (void *)header < sizeof(*header) + sizeof(u32) || (header->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC))) goto errout; - error = ext4_xattr_check_names(entry, end, entry); + error = ext4_xattr_check_names(IFIRST(header), end, IFIRST(header)); errout: if (error) __ext4_error_inode(inode, function, line, 0,