Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp182393ybt; Thu, 9 Jul 2020 19:16:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjOdEvbJZoahboDH+zTH5wWuInCjUzrouVHus/SM52TIjSWeH5JMjb/OohcO1pp/zCV9h1 X-Received: by 2002:a17:906:945:: with SMTP id j5mr59497829ejd.52.1594347369938; Thu, 09 Jul 2020 19:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594347369; cv=none; d=google.com; s=arc-20160816; b=YlUJ54Hj7e8W8LsFRuaUo6S5wWWN2HYXCtj4B6sdlojlPn1qf6XGU8Ww13oNGiXuNc uwEn2tkcrAhUBo1Qd75Gii0XaYgIrO78mqPXRLu3lvZebCQv49IqvxAh94L6ZHiDfoMh cMuXD7aOxjHu38EMmuS7TGfDh5zYWVs5JXGbOvPuDga66X++ae1WQnvBoYqAaHmqbiGt 0l0KSISX/BAkRb8u9w17JCyHBwFNoA4G26tqS3e9+tT2GKw7HEhkRi21Z8wHKvKaanFy 1J97EIvrbCv7tk26oBvJJU8gzB/0/oIOMDrpEuPyjzDuxR218/oobArmWoZljVjivhJ2 PRrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QkQSECiHHKjY2wMf5WdW+4+ngmPLR5hshwDsZDOZ0qY=; b=mydDoQ9mmoFoxNARrrhA9Od+x3HkUI8AGKiIcO4bktMRcSGMrEg0Xmiw1PSO1WI+h+ lmpLxx+qrnw9MykgXsiw0OXXwHJ5UdraTl1qey7oaUOaVOOZefMxRPTxz5PAIxZr5ON4 ZWBXlb1Hq5xErwoE6iYNSOJHUO2Xd0CtrUSRzGIbOgBpRGWu5/vc9/JWHmYCfjk0s9lM 8g67jWFDEgTrQ/cIBUcQk8YKg1tIXigTKzxMzj92g2Y+iGfQCWJZHo7IxtsbwbVmYcMN 8tHYvnyDWlV/aoJMRgmCQGIm74CVGi83Pn76/3kpRinnbDLP+6qdf0T1/kefdnkG8w3G fvRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ax9JFe+x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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. [23.128.96.18]) by mx.google.com with ESMTP id w13si2616329ejj.564.2020.07.09.19.15.47; Thu, 09 Jul 2020 19:16:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ax9JFe+x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726934AbgGJCPO (ORCPT + 99 others); Thu, 9 Jul 2020 22:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgGJCPN (ORCPT ); Thu, 9 Jul 2020 22:15:13 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AE4CC08C5CE for ; Thu, 9 Jul 2020 19:15:13 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id e18so1828172pgn.7 for ; Thu, 09 Jul 2020 19:15:13 -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:mime-version :content-transfer-encoding; bh=QkQSECiHHKjY2wMf5WdW+4+ngmPLR5hshwDsZDOZ0qY=; b=Ax9JFe+xCSrnS5iZU07rdj4BMegbKRHByEA8KIB170r2p1prZMYiQAksTM9eePOgkC KARvN11mXFlZAJDSrxVeHL1H6nMIPbDpWBOuv4n43DtfSn7p9IvAScA6o20QG66Y7R4W jxn2azc1m+a04Ntx+D8JD+Eczob/PWHJnVxQ6SDWIGNzbPMzrsL/h6aQ0H6zqyC7smwM Tg8GNZFODhVFkwp0XnLWkGl9aTqy/89dr29vGrZmftswi8hiOYYAKOMEnQbDCVlHM78v llSDRikRevxxx8UoFfKBhrPXZrOvsV9oHK9MGC0mid+jFw7AbHue6UZvt3viR06NewKZ QORw== 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:mime-version :content-transfer-encoding; bh=QkQSECiHHKjY2wMf5WdW+4+ngmPLR5hshwDsZDOZ0qY=; b=XITLGbE0M3SGW8zBThGvsY21MUVjNzoSXOrarFzsLM7ZyKHdVn77nm1q/BKe9wxV6K uNKbE7GBcomcG/sjtA20zNGCRkryfWHRkMkp6MaQbexWNq5p+zUmdqjRxvWei+MBpeV6 PZwCgT9327ND4ahSuYEIa23yxO/3OEvpUz+GZQ5wK3XvubRgZDKt7dpfHWHHHzCMvI0S aI8UEptTgB9ohmDpapXIGD/7MHeOwif2j9TONlMCjVumPbueOG3d61O1WlKMatRIOllc R1RxkItfKuTfHu6BxJeUm0SQNH+vv1mi0heYb4pTEu6GBju1BVw1G26AdjgqjQwCeCRI tRig== X-Gm-Message-State: AOAM5327s/2F+Z2uW76dx+yrQhHL2quCWstfNxFyhmH036nR9uhQNo5I i6EDlCwsi93cKTTkYiN9ZKqReou3D+U= X-Received: by 2002:a62:e206:: with SMTP id a6mr53727039pfi.24.1594347312716; Thu, 09 Jul 2020 19:15:12 -0700 (PDT) Received: from daehojeong1.seo.corp.google.com ([172.30.115.29]) by smtp.gmail.com with ESMTPSA id y18sm4190687pff.10.2020.07.09.19.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 19:15:11 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH] f2fs: change the way of handling range.len in F2FS_IOC_SEC_TRIM_FILE Date: Fri, 10 Jul 2020 11:15:05 +0900 Message-Id: <20200710021505.2405872-1-daeho43@gmail.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daeho Jeong Changed the way of handling range.len of F2FS_IOC_SEC_TRIM_FILE. 1. Added -1 value support for range.len to signify the end of file. 2. If the end of the range passes over the end of file, it means until the end of file. 3. ignored the case of that range.len is zero to prevent the function from making end_addr zero and triggering different behaviour of the function. Signed-off-by: Daeho Jeong --- fs/f2fs/file.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 368c80f8e2a1..1c4601f99326 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3813,21 +3813,19 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) file_start_write(filp); inode_lock(inode); - if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) { + if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) || + range.start >= inode->i_size) { ret = -EINVAL; goto err; } - if (range.start >= inode->i_size) { - ret = -EINVAL; + if (range.len == 0) goto err; - } - if (inode->i_size - range.start < range.len) { - ret = -E2BIG; - goto err; - } - end_addr = range.start + range.len; + if (range.len == (u64)-1 || inode->i_size - range.start < range.len) + end_addr = inode->i_size; + else + end_addr = range.start + range.len; to_end = (end_addr == inode->i_size); if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || -- 2.27.0.383.g050319c2ae-goog