Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2257584imm; Thu, 18 Oct 2018 11:31:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV60s/H+B90JXiv32iPCs9vziyySUVIXTFYQ0ICOy9d8vOJSFRjwfhN1bbMDyO0RahAIRxby2 X-Received: by 2002:a65:4d03:: with SMTP id i3-v6mr29610175pgt.239.1539887496934; Thu, 18 Oct 2018 11:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539887496; cv=none; d=google.com; s=arc-20160816; b=t5incEpLg1psIEaIAML+ojuZVX6QIuwqApabb47+DGIzl1fygjgUYA7ZtnQGqQFoPO lEm3IPGP9aBqp16Z9NSihGntxWhlgrVaAbPqNI2xHz992lTcVDo0yTS1hBKHtd+uq6MZ hIHKT1lYrx/iFpc5HPGXQ/OgkfLChmMR1nDoeEhRNStbNpFA46o8aWEijY60tJCaV/6D WvI9GYaB2272EqIKEftgKwzZkNxjaZnm+q2QG1M/Ccu9wQu3Z57fDEg3zaqaMcguBpLK xlXz+M0dHwSvE/QqfskRKfllXVD9QwQ0lHDaRA5/qrXTPhtqep6AUqcQIlNoE4FpzAtl INPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ioi9pSY5UaUPVcnADde8Ouo8SPexvB/f7dv8+nRZvGc=; b=LuMjIHojFenCXtCZuGFZmxvTL52PpvzTol/oCL2/jdwXn3lzuNRx2qG9yW/UbYVVRu PN8Q5r4990VbcMDujzHlRhJ1Ia+6hMz7uzDs1iDf/+N4Yph0blrW87TzhJGJbl6T0qb+ WgDmi33RgTqd7MFPa3OKZLI/Qp6x1nuVMfr4vN7DPiqTbinzdXNn13LWlx/9Ctkd3OXz 7lnspoPghj3Ll64UpsNd+/OldkrdB06jp5ej7XDXXhyPE7soC35RJbVcX7YH0CAWWxte lfzojhjbaPndvhAuNv9D/y7eP4R+IZV0Xa1/0X1SfbqypSfK51NuFdf+lV3aw4V/vW3s 8Gmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ed4nyT9v; 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 20-v6si21840386pgk.190.2018.10.18.11.31.21; Thu, 18 Oct 2018 11:31:36 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ed4nyT9v; 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 S1730156AbeJSCG5 (ORCPT + 99 others); Thu, 18 Oct 2018 22:06:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:55404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726516AbeJSCG5 (ORCPT ); Thu, 18 Oct 2018 22:06:57 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 25EE52148D; Thu, 18 Oct 2018 18:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885889; bh=DSJc3g1xNMsHZFFiGfhoU4iZoYv4AfrdROhZ9gVh6zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ed4nyT9v4K9/VZ+m/HfTWHnbWxJaQE1cAuXysFrKCEX/0WKgWcxWVUWvpwt2yevdD /V2Pi5bMeyMGieRCidTSL/HluvHDAJH6VzQRgO/eYErCzUJMalmTsxrMzJvCKOyLZI b/RAkWobNr9V65MwuO0Js5kE0bfPBIBL3i2CjJKI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Andreas Dilger , Ben Hutchings , Daniel Rosenberg Subject: [PATCH 4.4 10/48] ext4: add corruption check in ext4_xattr_set_entry() Date: Thu, 18 Oct 2018 19:54:45 +0200 Message-Id: <20181018175428.537398160@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175427.133690306@linuxfoundation.org> References: <20181018175427.133690306@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 5369a762c882c0b6e9599e4ebbb3a9ba9eee7e2d upstream. In theory this should have been caught earlier when the xattr list was verified, but in case it got missed, it's simple enough to add check to make sure we don't overrun the xattr buffer. This addresses CVE-2018-10879. https://bugzilla.kernel.org/show_bug.cgi?id=200001 Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger [bwh: Backported to 3.16: - Add inode parameter to ext4_xattr_set_entry() and update callers - Adjust context] Signed-off-by: Ben Hutchings [adjusted for 4.4 context] Signed-off-by: Daniel Rosenberg Signed-off-by: Greg Kroah-Hartman --- fs/ext4/xattr.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -638,14 +638,20 @@ static size_t ext4_xattr_free_space(stru } static int -ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s) +ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s, + struct inode *inode) { - struct ext4_xattr_entry *last; + struct ext4_xattr_entry *last, *next; size_t free, min_offs = s->end - s->base, name_len = strlen(i->name); /* Compute min_offs and last. */ last = s->first; - for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { + for (; !IS_LAST_ENTRY(last); last = next) { + next = EXT4_XATTR_NEXT(last); + if ((void *)next >= s->end) { + EXT4_ERROR_INODE(inode, "corrupted xattr entries"); + return -EFSCORRUPTED; + } if (!last->e_value_block && last->e_value_size) { size_t offs = le16_to_cpu(last->e_value_offs); if (offs < min_offs) @@ -825,7 +831,7 @@ ext4_xattr_block_set(handle_t *handle, s ce = NULL; } ea_bdebug(bs->bh, "modifying in-place"); - error = ext4_xattr_set_entry(i, s); + error = ext4_xattr_set_entry(i, s, inode); if (!error) { if (!IS_LAST_ENTRY(s->first)) ext4_xattr_rehash(header(s->base), @@ -875,7 +881,7 @@ ext4_xattr_block_set(handle_t *handle, s s->end = s->base + sb->s_blocksize; } - error = ext4_xattr_set_entry(i, s); + error = ext4_xattr_set_entry(i, s, inode); if (error == -EFSCORRUPTED) goto bad_block; if (error) @@ -1037,7 +1043,7 @@ int ext4_xattr_ibody_inline_set(handle_t if (EXT4_I(inode)->i_extra_isize == 0) return -ENOSPC; - error = ext4_xattr_set_entry(i, s); + error = ext4_xattr_set_entry(i, s, inode); if (error) { if (error == -ENOSPC && ext4_has_inline_data(inode)) { @@ -1049,7 +1055,7 @@ int ext4_xattr_ibody_inline_set(handle_t error = ext4_xattr_ibody_find(inode, i, is); if (error) return error; - error = ext4_xattr_set_entry(i, s); + error = ext4_xattr_set_entry(i, s, inode); } if (error) return error; @@ -1075,7 +1081,7 @@ static int ext4_xattr_ibody_set(handle_t if (EXT4_I(inode)->i_extra_isize == 0) return -ENOSPC; - error = ext4_xattr_set_entry(i, s); + error = ext4_xattr_set_entry(i, s, inode); if (error) return error; header = IHDR(inode, ext4_raw_inode(&is->iloc));