From patchwork Mon Aug 29 09:48: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: 1106922 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7T9nFnm001377 for ; Mon, 29 Aug 2011 09:49:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753219Ab1H2JtM (ORCPT ); Mon, 29 Aug 2011 05:49:12 -0400 Received: from rcsinet15.oracle.com ([148.87.113.117]:24636 "EHLO rcsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115Ab1H2JtM (ORCPT ); Mon, 29 Aug 2011 05:49:12 -0400 Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p7T9n9BN021049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Aug 2011 09:49:11 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p7T9n8dZ000617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 29 Aug 2011 09:49:09 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p7T9n2UP019577 for ; Mon, 29 Aug 2011 04:49:02 -0500 Received: from [192.168.1.103] (/123.119.98.76) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Aug 2011 02:48:08 -0700 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 Message-ID: <4E5B6055.1080807@oracle.com> Date: Mon, 29 Aug 2011 02:48:05 -0700 (PDT) From: Jeff Liu To: linux-btrfs@vger.kernel.org Cc: chris.mason@oracle.com Subject: Fix btrfs_file_llseek() to return -EINVAL directly Reply-To: jeff.liu@oracle.com X-Source-IP: rtcsinet22.oracle.com [66.248.204.30] X-CT-RefId: str=0001.0A090207.4E5B6097.01E8,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 (demeter2.kernel.org [140.211.167.43]); Mon, 29 Aug 2011 09:49:15 +0000 (UTC) Hello, In btrfs_file_llseek(), if the offset < 0 or offset > inode->i_sb->s_maxbytes, we should return -EINVAL rather than offset. Also, if the offset >= inode->i_size for SEEK_DATA or SEEK_HOLE, return -ENXIO is ok IMHO. Signed-off-by: Jie Liu mutex_unlock(&inode->i_mutex); @@ -1820,14 +1825,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; - goto out; - } - if (offset > inode->i_sb->s_maxbytes) { - ret = -EINVAL; - goto out; - } + if (offset < 0 && !(file->f_mode & FMODE_UNSIGNED_OFFSET)) + return -EINVAL; + + if (offset > inode->i_sb->s_maxbytes) + return -EINVAL; /* Special lock needed here? */ if (offset != file->f_pos) { --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e7872e4..2c126d0 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) {