Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28636imm; Fri, 21 Sep 2018 17:24:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZlWy9r2nS0sak9cdDB3HQvOqW+gcZ+9ozecJ/xZHeS5I3ctT3kgcFs0Mg+1u14MLW0ygFU X-Received: by 2002:a62:fd06:: with SMTP id p6-v6mr127179pfh.167.1537575849384; Fri, 21 Sep 2018 17:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575849; cv=none; d=google.com; s=arc-20160816; b=JHSmI08RTYxBMckjoLQM4xcxdSFt5MvL3E8qoBPQxvK8i3BsVbWxr+VsRsf1WCtpVX cfHQJYePKnoNnStW9AX60QyGkXOT2ULNFaWySZmSDxe2RJiUK3sMbe1KHCEUIaKZ8ukd CPNTCNZKEcV1EwIiAeOdi84D70OQCJp7mPqKHky9QfzOHzg+0dlZQKm4Zg4FM1u2igte nitCyRIHIwI/0aXxi455C+EJXbzhmU502XtopZzjYbUEInVcdyHUNnOFrCkQjH772JM8 xvPIlYY0dJpkMt0XGH11RvrEAUAY48CZfeuuMwMlSTB+uc9VpnL76+qlgHeXQ5ETyOvN iNPw== 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=620qct1Ugm9xUrSn38b6UwQcFBV7dRpbZKgQezo0P1o=; b=sspc/Daj+4k7yOo5wPcPqrvxdO0m5lyi4O75id+8lG02TW+y3ziXwTAvV0JsDK6BIJ aIBarlxN4EnxP4xeWhhkFDMb16MfCzOCI4aF/XnPBsm9fSWFlWmUdx/j3rXMSk8fzlli KbBb7NTk5ruO1IDeTwC363aETYaTvuExOFrIAvPXqLUPWav1q+nQhWK36JjDOPP5luoz +nt1nlZ9amwEuuioBWi9mGo8Sh/DH7N0Lz7jTTc/j6pWOK/llwQMMYS9VJ98wTuAshvx kCrUUJL0nGN0kYMnJ4hfxeI4ka0QeWtnLksILEisxYGMa4NKRdgf01+rz+B6DKy7wHbp bLzw== 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 o69-v6si31035896pfo.342.2018.09.21.17.23.53; Fri, 21 Sep 2018 17:24:09 -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; 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 S2392160AbeIVGND (ORCPT + 99 others); Sat, 22 Sep 2018 02:13:03 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44257 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392015AbeIVGKs (ORCPT ); Sat, 22 Sep 2018 02:10:48 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdy-0008Bc-65; Sat, 22 Sep 2018 01:19:30 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000sB-57; Sat, 22 Sep 2018 01:19:20 +0100 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, "Andreas Dilger" , "Theodore Ts'o" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 31/63] ext4: add corruption check in ext4_xattr_set_entry() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 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.58-rc1 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 - Return -EIO instead of -EFSCORRUPTED on error - Adjust context] Signed-off-by: Ben Hutchings --- --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -610,14 +610,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 -EIO; + } if (!last->e_value_block && last->e_value_size) { size_t offs = le16_to_cpu(last->e_value_offs); if (offs < min_offs) @@ -798,7 +804,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), @@ -851,7 +857,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 == -EIO) goto bad_block; if (error) @@ -1021,7 +1027,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)) { @@ -1033,7 +1039,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; @@ -1059,7 +1065,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));