Received: by 10.192.165.148 with SMTP id m20csp4198193imm; Mon, 30 Apr 2018 13:41:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqlX7oltdB1087WSHZ1CcFd3dZNC5K4QIEMqLgYuKJaA2zsX5T+17vTb4n3n/LW5CW8kIvh X-Received: by 10.98.91.2 with SMTP id p2mr5210958pfb.96.1525120861965; Mon, 30 Apr 2018 13:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120861; cv=none; d=google.com; s=arc-20160816; b=m0hl2YbYOrDVZSypGExKKeaqeurIHd5w/P2lYxrDkBSCA5r+WWHjmA4qB805NPuwwB y4ZQnNo7OLtLaD3Z0qCuj8nQcewP0Quvdik4U1340VllSAE1YtNbykpgQ8ndrcsT8whC +ESshmd6nCD8gpVMHL1b+6N+5cRTovhknZMxmCkWpZlLJm4BOlfrLC216vmOEH+iIe3A ehMSkgiv/rmk7SP4k6zKwfwhPwS8w8iZ+5l6x3d6YE7hhcIpR9cspEmXVRMf9P/yfBvb jLlhaqGNpSEWqr2DlK30+zZvpbMukDIyqNlNKli5o/FirHQVJwSjfpGcY3YoZ/Nu48NY cIZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=iXWq/wutiUxkxGSu6xmQ54d66+D1od9+u6F+FPi1lco=; b=fui2Or8s03uUPwbshuX0uu6GWj7Vif+X1DRM/U11ubXGTCr2hkfTnMsu6z/hO1JyzD ixfAZQ38gby9QUX8x1EjRensX4dy/Qw5/+UaEbYIPwvn4xreQ3dc8e8g/+mTUgPaUST1 DbdEQ+2Imvz3yPcdxfQIwfE9arnszoBmaZwnH83BqhVGu4aMU1Gl40kNbKmgXl/rNTkE PlZVtxGglR5zoBaZptqqqQvozknH9OHR3/4gxZWOt9PAe7XWf2KWW+BpFleY5Uec++nL XUeACiWXdyQi7Y61gk7dmdV6vYtXaUyMjHKo0ywFT+Y0cYDqaMJrDCePcAwA4jB4F7xf UZUg== 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 a81si7603019pfj.300.2018.04.30.13.40.47; Mon, 30 Apr 2018 13:41:01 -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 S1755358AbeD3TZq (ORCPT + 99 others); Mon, 30 Apr 2018 15:25:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:58518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbeD3TZo (ORCPT ); Mon, 30 Apr 2018 15:25:44 -0400 Received: from localhost (unknown [104.132.1.102]) (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 BF0F521746; Mon, 30 Apr 2018 19:25:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF0F521746 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+06c885be0edcdaeab40c@syzkaller.appspotmail.com, Eric Biggers , Theodore Tso Subject: [PATCH 4.4 01/44] ext4: prevent right-shifting extents beyond EXT_MAX_BLOCKS Date: Mon, 30 Apr 2018 12:24:12 -0700 Message-Id: <20180430190946.371502271@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Eric Biggers commit 349fa7d6e1935f49bf4161c4900711b2989180a9 upstream. During the "insert range" fallocate operation, extents starting at the range offset are shifted "right" (to a higher file offset) by the range length. But, as shown by syzbot, it's not validated that this doesn't cause extents to be shifted beyond EXT_MAX_BLOCKS. In that case ->ee_block can wrap around, corrupting the extent tree. Fix it by returning an error if the space between the end of the last extent and EXT4_MAX_BLOCKS is smaller than the range being inserted. This bug can be reproduced by running the following commands when the current directory is on an ext4 filesystem with a 4k block size: fallocate -l 8192 file fallocate --keep-size -o 0xfffffffe000 -l 4096 -n file fallocate --insert-range -l 8192 file Then after unmounting the filesystem, e2fsck reports corruption. Reported-by: syzbot+06c885be0edcdaeab40c@syzkaller.appspotmail.com Fixes: 331573febb6a ("ext4: Add support FALLOC_FL_INSERT_RANGE for fallocate") Cc: stable@vger.kernel.org # v4.2+ Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/extents.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -5380,8 +5380,9 @@ ext4_ext_shift_extents(struct inode *ino stop = le32_to_cpu(extent->ee_block); /* - * In case of left shift, Don't start shifting extents until we make - * sure the hole is big enough to accommodate the shift. + * For left shifts, make sure the hole on the left is big enough to + * accommodate the shift. For right shifts, make sure the last extent + * won't be shifted beyond EXT_MAX_BLOCKS. */ if (SHIFT == SHIFT_LEFT) { path = ext4_find_extent(inode, start - 1, &path, @@ -5401,9 +5402,14 @@ ext4_ext_shift_extents(struct inode *ino if ((start == ex_start && shift > ex_start) || (shift > start - ex_end)) { - ext4_ext_drop_refs(path); - kfree(path); - return -EINVAL; + ret = -EINVAL; + goto out; + } + } else { + if (shift > EXT_MAX_BLOCKS - + (stop + ext4_ext_get_actual_len(extent))) { + ret = -EINVAL; + goto out; } }