Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1318497yba; Tue, 2 Apr 2019 06:47:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2ugvom+VuTZ9Xi6XKcpzdHb3UoT31BUoPLz7AQaXb70nuioJdGctl5gKO0jy4VMAYsMGf X-Received: by 2002:a17:902:6b48:: with SMTP id g8mr69950002plt.21.1554212849595; Tue, 02 Apr 2019 06:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554212849; cv=none; d=google.com; s=arc-20160816; b=nRPkd/PEu4SXMgN5s8C6Q+MAKOJsB7VhqITXrLZtqvRO7893H4oHyHPgqSgtNihveK T0TNMP2SXPl/qJRAsfo6vqu0550j2uT8bxq901cybztvTNvOYtUJ/z4cFZNGBKxSPmvF 8T7BJlyrqv5LzF7oq1Tt3cGfgT6JAqRLip0J3tCOvPh4V7ZY+xTm6q1z8LMgtO5/Yspz nh3gq2LfAGNGC2u2n4EoMuMLx95vciaH/8e4pqk0UdiAzljJ9jL4l3dWAsYHeXdi7prs 1pa2MoE9oZv0pQ3hXbvlrBbXL3tdeWDd3PTxH3Ci0+JSjuuPodFdgrp4kHUZ7LfnKrdT sDRw== 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=yKsYhFhsIU4BvUM0MaeGwb7btCwILrec3Bgwj+17Op8=; b=R19jQvFaDFIwZ6UeRYU7tpJfNq+dC41JksXmK9w8SEmSmahumXNzhofL9STkss+R26 7kU+m6au1IPZWRwCvSokCohCZHhEWmCeLVNXZ/aqCPKD6gDUDsmSG25O8PJK14Bej5IM GkCOm0prQyJ6HYgWELy+jSYSmnv+2kd8AwKSTLzu9jDjKUaTsB4ZadTiKNK45KxouKbw P/XnkAqVmU9AXBw2ryO6Hr0iJfuL1WE3789t7XVwZAr4TcJKqeEJfPgxpKJ21jSK+UjK +AnLiUUNot0FHlmCu8AZAqZjzOmli+xqV3G0Te542VcP0Whak4x7ilGXWoSjCt/cCp7n T9IQ== 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 w12si11028100pgr.104.2019.04.02.06.47.13; Tue, 02 Apr 2019 06:47:29 -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 S1732047AbfDBNow (ORCPT + 99 others); Tue, 2 Apr 2019 09:44:52 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43446 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731476AbfDBNkI (ORCPT ); Tue, 2 Apr 2019 09:40:08 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJe0-0002oY-H3; Tue, 02 Apr 2019 14:40:04 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdx-0004wv-M8; Tue, 02 Apr 2019 14:40:01 +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, Denis Kirjanov , "Theodore Ts'o" , "Dmitry Monakhov" Date: Tue, 02 Apr 2019 14:38:28 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 80/99] ext4: ext4_inline_data_fiemap should respect callers argument In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 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.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Monakhov commit d952d69e268f833c85c0bafee9f67f9dba85044b upstream. Currently ext4_inline_data_fiemap ignores requested arguments (start and len) which may lead endless loop if start != 0. Also fix incorrect extent length determination. Signed-off-by: Dmitry Monakhov Signed-off-by: Theodore Ts'o [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/ext4/ext4.h | 2 +- fs/ext4/extents.c | 3 ++- fs/ext4/inline.c | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2712,7 +2712,7 @@ extern struct buffer_head *ext4_get_firs int *retval); extern int ext4_inline_data_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - int *has_inline); + int *has_inline, __u64 start, __u64 len); extern void ext4_inline_data_truncate(struct inode *inode, int *has_inline); extern int ext4_convert_inline_data(struct inode *inode); --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -5153,7 +5153,8 @@ int ext4_fiemap(struct inode *inode, str if (ext4_has_inline_data(inode)) { int has_inline = 1; - error = ext4_inline_data_fiemap(inode, fieinfo, &has_inline); + error = ext4_inline_data_fiemap(inode, fieinfo, &has_inline, + start, len); if (has_inline) return error; --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -1816,11 +1816,12 @@ int ext4_destroy_inline_data(handle_t *h int ext4_inline_data_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - int *has_inline) + int *has_inline, __u64 start, __u64 len) { __u64 physical = 0; - __u64 length; - __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_LAST; + __u64 inline_len; + __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | + FIEMAP_EXTENT_LAST; int error = 0; struct ext4_iloc iloc; @@ -1829,6 +1830,13 @@ int ext4_inline_data_fiemap(struct inode *has_inline = 0; goto out; } + inline_len = min_t(size_t, ext4_get_inline_size(inode), + i_size_read(inode)); + if (start >= inline_len) + goto out; + if (start + len < inline_len) + inline_len = start + len; + inline_len -= start; error = ext4_get_inode_loc(inode, &iloc); if (error) @@ -1837,11 +1845,10 @@ int ext4_inline_data_fiemap(struct inode physical = (__u64)iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits; physical += (char *)ext4_raw_inode(&iloc) - iloc.bh->b_data; physical += offsetof(struct ext4_inode, i_block); - length = i_size_read(inode); if (physical) - error = fiemap_fill_next_extent(fieinfo, 0, physical, - length, flags); + error = fiemap_fill_next_extent(fieinfo, start, physical, + inline_len, flags); brelse(iloc.bh); out: up_read(&EXT4_I(inode)->xattr_sem);