Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2989418imu; Sun, 9 Dec 2018 14:26:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/XUbJ+2lI7h3uWGtYTOPxXYTD2pzN4DaoNUncsDZzgp8G9xpleOUn1YG7Pqy1ww6ef4w8wa X-Received: by 2002:a17:902:654a:: with SMTP id d10mr9724590pln.324.1544394363019; Sun, 09 Dec 2018 14:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544394362; cv=none; d=google.com; s=arc-20160816; b=wLb/V6fCNgN6T6EO40XID3mtCN7SPMna+LFU1DWRRHOnP7mPJeFh+5gmmfLsdkRqOQ k2gqk3Ca/hJ3RcpIUjErrYO7LiQLo7WXGruOph0pJFMnmrfaafMVzFIA6cFDtQjUbAW8 O1mgEPDxg0l5kd3ERlWGr6Y1X6+h9wHqNz1gtvv9dmVRcbusgFg+GBmKdc8VlFawhpuy wVarglcu6iGxBtuetBJtqpgcgm56SW2bTeV6iLCZ3LM8mKfpT7nySnPJaKy50s0v7kTq qA9rhLPTxVT+wvG95ZZhBOmKVWn0phV/1ROSLZv+HVQuFowPLZAZHAlZVPoZKR5AQvXV jbdg== 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=iMakkucj7jagzJPQC6KI2p2x0p5YVzzqn/atCI1C5zw=; b=Nm1gzxkRVkp3m5ASc25VpUnzwsTprpEDlD6nvMTL/CXoqjN+l6r3v8fOlPs9EaEnHL lYjCApaqiyyL+eicDqGGpeCCivEbMU/NVUbp6ANkDVc3lNwg45/22fVeFZR+XX1E9IYc PgwHoOXiIc44GKi8KnRZqKBCSxlK03H0w2oCSNpfuvWyqw5ZBxMSJyQ91hEgWN6vT0O0 /dXpKtWZ6BvV+APkEkbuwuLukc8xm6sLSTPZaqYLfcJCEWkV2QCz9fSOVH9NnCyqXZun HYLg9Zb4YW2V49Q24mjhTa0wfldTDMtDDwbollO4+cIlK2MAUehd2kyNX3b9DYhy/IJK wlEA== 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 x23si8400033pln.100.2018.12.09.14.25.48; Sun, 09 Dec 2018 14:26:02 -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 S1728605AbeLIWYS (ORCPT + 99 others); Sun, 9 Dec 2018 17:24:18 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35046 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbeLIVzS (ORCPT ); Sun, 9 Dec 2018 16:55:18 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72h-0002im-Ho; Sun, 09 Dec 2018 21:55:15 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72e-0003Rp-KQ; Sun, 09 Dec 2018 21:55:12 +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, "Wen Xu" , "Theodore Ts'o" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 169/328] ext4: avoid divide by zero fault when deleting corrupted inline directories In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 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.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 4d982e25d0bdc83d8c64e66fdeca0b89240b3b85 upstream. A specially crafted file system can trick empty_inline_dir() into reading past the last valid entry in a inline directory, and then run into the end of xattr marker. This will trigger a divide by zero fault. Fix this by using the size of the inline directory instead of dir->i_size. Also clean up error reporting in __ext4_check_dir_entry so that the message is clearer and more understandable --- and avoids the division by zero trap if the size passed in is zero. (I'm not sure why we coded it that way in the first place; printing offset % size is actually more confusing and less useful.) https://bugzilla.kernel.org/show_bug.cgi?id=200933 Signed-off-by: Theodore Ts'o Reported-by: Wen Xu Signed-off-by: Ben Hutchings --- fs/ext4/dir.c | 20 +++++++++----------- fs/ext4/inline.c | 4 +++- 2 files changed, 12 insertions(+), 12 deletions(-) --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -77,7 +77,7 @@ int __ext4_check_dir_entry(const char *f else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len))) error_msg = "rec_len is too small for name_len"; else if (unlikely(((char *) de - buf) + rlen > size)) - error_msg = "directory entry across range"; + error_msg = "directory entry overrun"; else if (unlikely(le32_to_cpu(de->inode) > le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))) error_msg = "inode out of bounds"; @@ -86,18 +86,16 @@ int __ext4_check_dir_entry(const char *f if (filp) ext4_error_file(filp, function, line, bh->b_blocknr, - "bad entry in directory: %s - offset=%u(%u), " - "inode=%u, rec_len=%d, name_len=%d", - error_msg, (unsigned) (offset % size), - offset, le32_to_cpu(de->inode), - rlen, de->name_len); + "bad entry in directory: %s - offset=%u, " + "inode=%u, rec_len=%d, name_len=%d, size=%d", + error_msg, offset, le32_to_cpu(de->inode), + rlen, de->name_len, size); else ext4_error_inode(dir, function, line, bh->b_blocknr, - "bad entry in directory: %s - offset=%u(%u), " - "inode=%u, rec_len=%d, name_len=%d", - error_msg, (unsigned) (offset % size), - offset, le32_to_cpu(de->inode), - rlen, de->name_len); + "bad entry in directory: %s - offset=%u, " + "inode=%u, rec_len=%d, name_len=%d, size=%d", + error_msg, offset, le32_to_cpu(de->inode), + rlen, de->name_len, size); return 1; } --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -1741,6 +1741,7 @@ int empty_inline_dir(struct inode *dir, { int err, inline_size; struct ext4_iloc iloc; + size_t inline_len; void *inline_pos; unsigned int offset; struct ext4_dir_entry_2 *de; @@ -1768,8 +1769,9 @@ int empty_inline_dir(struct inode *dir, goto out; } + inline_len = ext4_get_inline_size(dir); offset = EXT4_INLINE_DOTDOT_SIZE; - while (offset < dir->i_size) { + while (offset < inline_len) { de = ext4_get_inline_entry(dir, &iloc, offset, &inline_pos, &inline_size); if (ext4_check_dir_entry(dir, NULL, de,