Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2758622lqz; Wed, 3 Apr 2024 07:53:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCy6ZAzV/oiyayAbrho/4/3NLz1fl3m/Jn6qWbw/NXZLuqk4s1nJkH3WCUy9hogtSNjQbZWwkj1rO6RJnCxJhmhVixdjLkcq2ocK1hjQ== X-Google-Smtp-Source: AGHT+IF9JaDfDx8no+nPI6or7tnGGl1qzir/oEQVVW7HBYm8O/qQvvkf79uLYb7Eexr8Pj+Ri7mN X-Received: by 2002:a05:6358:49f:b0:183:630a:a88d with SMTP id x31-20020a056358049f00b00183630aa88dmr3023297rwi.9.1712156015870; Wed, 03 Apr 2024 07:53:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712156015; cv=pass; d=google.com; s=arc-20160816; b=DivUpP+0KwIBnlM9mxd4hgspkVCvDXKMEkuBoHV6n6DdlRJdnnmF4MTs3t9ksId3lh k/aK0Ff3cypocTQXR2sWg49+1FO1w68xzNW1tE2rAB12N70MNAVmw5wyVZsD1oPYxoNT 8rpoiEz/pio1oTjNCCY4dAPUL9ErmfYBtD6ntbmkOuh/3M13F1FTFqRVqh9zX9naRbEB oOqnM17jGAyS9ccGI05ARLHnEcpAp1QkQLvI7HKYOZ6IhMA91dot1auIYPDlyfxYq4qY xD+GWgPSRatJGfPw7QXrC6sJLzXUSPm9oqTHD83jPWgC2ykO3Dgr8rV1YpZHXPXCD4Y1 fc4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=08tdGDn/YbVgivOQdbwsN8tJkVGMa960FjEswE1bqmI=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=L30ElXb6QR1XCIzz+bB+GjagvpNlMm7CSMsItaXtxEEze1pZKmvnc+mqBeJsH1meLO jruIwCu9csHlZ7FJV8Sfzx4ju4kGau5l+ZzkrF8HqfiPl+4nR16bwTnD1PezcmMpFmBL wGC9/NIlzvJtYP/rRbvL3qR9GVGSim7LIEpaCNsUqzkoteGWNWCGthC4p87hIehaSMa/ 5m43NQgwgGrxTJpA4QmFQ9peJtcOZnp0xjlJa6OxVwK9RRJCqn4W7A2BWK2eMQPTbxv2 3ah0Cn4y/P+h6lv4DBtPf0/vmBXY9HAPhdY8C1YBUCM+k0FbPX414iC2K4ik9xm2tMUz b8Og==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q4FhDPtz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-129955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f29-20020a63511d000000b005dca7d41860si13226950pgb.418.2024.04.03.07.53.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q4FhDPtz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-129955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8DDA2B2E275 for ; Wed, 3 Apr 2024 14:25:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44B1C149C5D; Wed, 3 Apr 2024 14:24:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q4FhDPtz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C3631494A4 for ; Wed, 3 Apr 2024 14:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154268; cv=none; b=VX0xczxznTCWF49P78t6nHDx78n6XWUc+wVwY4Hf8HPHeIh4MyJBzCR7iuY36fpK+7mLvYKtpvHaSSF8v7I74piq2WPaGVdQ2U4d4tmAnXlHKfJBWR8DagevR9jcz14jv2/+sVrH8WLKwk+Z6mdGRjoQ6A7W4xKv89rHW1dcsnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154268; c=relaxed/simple; bh=Et6k9jnpHCmh8RkVkmceF4DfrHtMEGLOP0mlzrDQVTg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Ogyt9ymPf8+ZeR1R/QUrDCMCzEJlGq9F4Bu7e1pdLhb3y5sUod+a+g4bVFg1jy60wKrbbNim15J6ZTYVY4XliBbmXkueRlzwWhvwkCrI4/X5VcR520JS5/e+M2laISKk+VjyqSK21t9aCMbXrGyFKIiM/Ya1vZ8XsV8m7COMofc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q4FhDPtz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A697EC433F1; Wed, 3 Apr 2024 14:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712154267; bh=Et6k9jnpHCmh8RkVkmceF4DfrHtMEGLOP0mlzrDQVTg=; h=From:To:Cc:Subject:Date:From; b=q4FhDPtznoIvgxXYNNTmflJkwAz5zan8MN7d5DCZWR+npG9lvlELY4xhniWJF/Qr3 0tBjo2D4tiAqrDQ4Rho1DCjgp6l02JntfbQHocIYDsjgS0reSS1LG2L4ePy/GXXjdI vIRvLmR2buLiB+Pwq7dWnNA8fJtOb346RXmWYp5lTbQXMV5w5bbfhD6bwTJp8PWxLj xiTRi0rOYinFu9xwTQKgv3s1yzPt26/hnQRViMAYSYqMRr+ogGAkiWPm9YiL8+zwZD Xk0fy0Fhfp8tlRbW405XaVYRrghfX+WAUNdDWHa3sCJRGl50At2akdoDrIDPSaIXZM BGBNC92fMR8Sw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/2] f2fs: fix to relocate check condition in f2fs_fallocate() Date: Wed, 3 Apr 2024 22:24:19 +0800 Message-Id: <20240403142420.2042498-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit compress and pinfile flag should be checked after inode lock held to avoid race condition, fix it. Fixes: 4c8ff7095bef ("f2fs: support data compression") Fixes: 5fed0be8583f ("f2fs: do not allow partial truncation on pinned file") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 148bfe3effdf..83a807e25e31 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1820,15 +1820,6 @@ static long f2fs_fallocate(struct file *file, int mode, (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) return -EOPNOTSUPP; - /* - * Pinned file should not support partial truncation since the block - * can be used by applications. - */ - if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && - (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | - FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) - return -EOPNOTSUPP; - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)) @@ -1836,6 +1827,17 @@ static long f2fs_fallocate(struct file *file, int mode, inode_lock(inode); + /* + * Pinned file should not support partial truncation since the block + * can be used by applications. + */ + if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && + (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | + FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) { + ret = -EOPNOTSUPP; + goto out; + } + ret = file_modified(file); if (ret) goto out; -- 2.40.1