Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6642647ybi; Wed, 29 May 2019 10:44:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2c1+W0zNon/aNZdl9RrYlopcPW6+1jS6yyHjsv24B37UDj5MouPw8lXWm3/fBOPKwGRdE X-Received: by 2002:a17:902:9f94:: with SMTP id g20mr24651149plq.56.1559151872458; Wed, 29 May 2019 10:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559151872; cv=none; d=google.com; s=arc-20160816; b=gv9vN81gWBuk4i9wH3DOjivKyqQx2jZocFD3RZMpvtjQZtIYzL3LQWEUI/rBW1D5mM FFS7Iw4VVbd+kBiQkC7wKvVx3yWAcI2NrxAygugwSIOlkaMSWY24iso+k7HE0tPi5b9V 5URQyt+lFYUY29ZbWsWyPIbgiRGxYlYFPYES4VR9vyj7w6NE8d+zo+PqVkB8rENGzvL5 U0jKYjsk+na4pwDK5D9lepiYxEz1tYLPdfRNpB/SJhUxjkywiZhFu9bblu/sy1Tw/1ob F/DtH/gTOS/bCpFzcV9z4aZr955kUJmfEdAjgIij1QRhwdYfz1fiVm5ZKwOSFbeqOsZN Yg1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=NeKDiq+5p2NPB+OcuE01UzrlB5njM3yLN2qd6AodpeU=; b=Lv2qkkCVD3MZLtD8LW1JWkI/aQOtoIxZiNHi9TCb6bYB4hRENXX/jbtzDIztBDeGEJ GyK4uXphBmTBe8wzzKerlEp0w7m9bVhgiNN2CHpuXqfMn8PLPm6z5IiVti/T4i/djE0k Ex7jcswUeL7l4tDWC7T/MlmMb8M7kPpc1KArc+lEufcltLbAjYpj3wqJRo7Z1X+uSgFf Y8BCRCSP5d7Lr6UyRhLlhV3V3VRSEaKQMXsPtgAaZhAy5TbtIdX1PnY3YMrNYfpnWh0I CJTeJX7qamYvVfEH8Jry5Bkfl+Cm6D07qAcpYyj70PyQIO0hiRtq/FsDH0whQSLhT1Qx HsXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QN4dIaN9; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12si347626pgq.351.2019.05.29.10.44.18; Wed, 29 May 2019 10:44:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QN4dIaN9; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbfE2Rno (ORCPT + 99 others); Wed, 29 May 2019 13:43:44 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53583 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbfE2Rnn (ORCPT ); Wed, 29 May 2019 13:43:43 -0400 Received: by mail-wm1-f67.google.com with SMTP id d17so2249047wmb.3; Wed, 29 May 2019 10:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NeKDiq+5p2NPB+OcuE01UzrlB5njM3yLN2qd6AodpeU=; b=QN4dIaN9QMaFtoyG1MUp3LUKUh3ugT/NLU0caZNTFXyG+VEwCFfSZ7mD8R4ExD6UXl gOYwKkKWru9NBTMqz2dLCYd6divEv4VxRn9L/xfgmYsnWPWYanKR+5T9cqVr77JQ3DVA UCbWv1SoobyBKVlV1UospEjByMAApeveSG6P9pQcvZogWrw1GCLzEYMjEp9ICab6sVwe MleSETzpiVcMoSl5TEaM8Zm1KYTpW4jXrNVb/TouiRehBOhM0cwE4OyzbFIGSVb7DVr6 kFpAfSEkd0ruju3U1cz31YBgfo9fjbsnDy9f+1MmnvzAotmiLbvk8C9MTyzaf3aMauOn ciRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NeKDiq+5p2NPB+OcuE01UzrlB5njM3yLN2qd6AodpeU=; b=jPUXmQHgtbS4Rq/9GGDNd8yiKDBwCN5vGFMt1tlBDJNOn7PboKaXLl0fqXdFrFCIZO AJHPUVY3N2pY1c0KisD7xylSogObIcX9MZBU481GDB7hNf85YlvGfdD46kQ2eFjb7gro S5UMnbDiLptyg3TU1xGL3kWXER4/UE1uDrCEwskMStmrTHk7QFKCHE6Jy07/6gLacr2f W2TGPCcU74KGHRfrF0P9NgPtbwMgtgYUtOPvoDF4KpYZIdM48IzFWnvyqfR8tjJsmHfW +aE0O46pyvcO97XKAEQiQJ3ViR0LRFSIbrZw2nkf+R68dDqiRpSIh5ygwPXG/LBpwJh/ oPsA== X-Gm-Message-State: APjAAAWIPEMpvO/3y09BEpMSQTnO5xrXlnDGAh1/qMD84Duh0toc4dXR adtmM9BKCcQ5xspwqv1Xdq0= X-Received: by 2002:a05:600c:23cf:: with SMTP id p15mr7996691wmb.31.1559151815769; Wed, 29 May 2019 10:43:35 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:35 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 04/13] vfs: remove redundant checks from generic_remap_checks() Date: Wed, 29 May 2019 20:43:08 +0300 Message-Id: <20190529174318.22424-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The access limit checks on input file range in generic_remap_checks() are redundant because the input file size is guaranteied to be within limits and pos+len are already checked to be within input file size. Beyond the fact that the check cannot fail, if it would have failed, it could return -EFBIG for input file range error. There is no precedent for that. -EFBIG is returned in syscalls that would change file length. With that call removed, we can fold generic_access_check_limits() into generic_write_check_limits(). Signed-off-by: Amir Goldstein --- mm/filemap.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index a38619a4a6af..44361928bbb0 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2895,24 +2895,11 @@ EXPORT_SYMBOL(read_cache_page_gfp); * LFS limits. If pos is under the limit it becomes a short access. If it * exceeds the limit we return -EFBIG. */ -static int generic_access_check_limits(struct file *file, loff_t pos, - loff_t *count) -{ - struct inode *inode = file->f_mapping->host; - loff_t max_size = inode->i_sb->s_maxbytes; - - if (!(file->f_flags & O_LARGEFILE)) - max_size = MAX_NON_LFS; - - if (unlikely(pos >= max_size)) - return -EFBIG; - *count = min(*count, max_size - pos); - return 0; -} - static int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count) { + struct inode *inode = file->f_mapping->host; + loff_t max_size = inode->i_sb->s_maxbytes; loff_t limit = rlimit(RLIMIT_FSIZE); if (limit != RLIM_INFINITY) { @@ -2923,7 +2910,15 @@ static int generic_write_check_limits(struct file *file, loff_t pos, *count = min(*count, limit - pos); } - return generic_access_check_limits(file, pos, count); + if (!(file->f_flags & O_LARGEFILE)) + max_size = MAX_NON_LFS; + + if (unlikely(pos >= max_size)) + return -EFBIG; + + *count = min(*count, max_size - pos); + + return 0; } /* @@ -2963,7 +2958,7 @@ EXPORT_SYMBOL(generic_write_checks); /* * Performs necessary checks before doing a clone. * - * Can adjust amount of bytes to clone. + * Can adjust amount of bytes to clone via @req_count argument. * Returns appropriate error code that caller should return or * zero in case the clone should be allowed. */ @@ -3001,10 +2996,6 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, return -EINVAL; count = min(count, size_in - (uint64_t)pos_in); - ret = generic_access_check_limits(file_in, pos_in, &count); - if (ret) - return ret; - ret = generic_write_check_limits(file_out, pos_out, &count); if (ret) return ret; -- 2.17.1