From patchwork Tue Aug 30 03:59:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeff.liu" X-Patchwork-Id: 1111722 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7U4AjZ0022962 for ; Tue, 30 Aug 2011 04:10:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750832Ab1H3EKi (ORCPT ); Tue, 30 Aug 2011 00:10:38 -0400 Received: from rcsinet15.oracle.com ([148.87.113.117]:22981 "EHLO rcsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750742Ab1H3EKh (ORCPT ); Tue, 30 Aug 2011 00:10:37 -0400 Received: from rtcsinet21.oracle.com (rtcsinet21.oracle.com [66.248.204.29]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p7U4AQaW003116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Aug 2011 04:10:35 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by rtcsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p7U3xEor009950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 30 Aug 2011 03:59:15 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p7U3x8oS008611; Mon, 29 Aug 2011 22:59:08 -0500 Received: from [192.168.1.103] (/221.223.112.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Aug 2011 20:59:08 -0700 Message-ID: <4E5C6009.6020908@oracle.com> Date: Tue, 30 Aug 2011 11:59:05 +0800 From: Jeff Liu Reply-To: jeff.liu@oracle.com Organization: Oracle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org CC: chris.mason@oracle.com, tm@tao.ma Subject: Re: Fix btrfs_file_llseek() to return -EINVAL directly References: <4E5B6055.1080807@oracle.com> In-Reply-To: <4E5B6055.1080807@oracle.com> X-Source-IP: rtcsinet21.oracle.com [66.248.204.29] X-CT-RefId: str=0001.0A090207.4E5C62BB.007F,ss=1,re=0.000,fgs=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 30 Aug 2011 04:10:45 +0000 (UTC) Sorry, I forgot unlocking inode before returning -EINVAL in the previous patch, thanks Tao pointing this out! From 1825149c67cbfe7cbafcee4156e1f301dade7b0b Mon Sep 17 00:00:00 2001 From: Jie Liu Date: Tue, 30 Aug 2011 11:51:00 +0800 Subject: [PATCH 1/1] Return -EINVAL ranther than offset if offset < 0 or offset > inode->i_sb->s_maxbytes. Reported-by: Tao Ma Signed-off-by: Jie Liu --- fs/btrfs/file.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) mutex_unlock(&inode->i_mutex); @@ -1821,11 +1826,11 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int origin) } if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) { - ret = -EINVAL; + offset = -EINVAL; goto out; } if (offset > inode->i_sb->s_maxbytes) { - ret = -EINVAL; + offset = -EINVAL; goto out; } diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e7872e4..082ae91 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1813,6 +1813,11 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int origin) goto out; case SEEK_DATA: case SEEK_HOLE: + if (offset >= inode->i_size) { + mutex_unlock(&inode->i_mutex); + return -ENXIO; + } + ret = find_desired_extent(inode, &offset, origin); if (ret) {