From patchwork Mon Feb 19 02:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13562137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EACC1C48BC4 for ; Mon, 19 Feb 2024 02:29:11 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rbtP1-0007oP-3J; Mon, 19 Feb 2024 02:29:08 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rbtOz-0007oI-JC for linux-f2fs-devel@lists.sourceforge.net; Mon, 19 Feb 2024 02:29:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dcbvIWnboZFfFe9LfmvMsZ5TmJ1Ms6fvjfbT8b3gtxw=; b=ii7AzQriCGcjgfMedPO/XKDqfc n7+2mKn9aV7Y1i41N32HL8xrCJ22F1DnQaFuLBNn99BFH/8dEcFEASp/VVrxrIUShNlp5wlExMNeg uhfvxVRKFKOsEqnJQxoWMrFio1Ycigpzep0rvSpbEW+ZLlUugtvYk26uNAVrx471k2X4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=dcbvIWnboZFfFe9LfmvMsZ5TmJ1Ms6fvjfbT8b3gtxw=; b=j Q0oRydaTsGY1y0OCGSLaYtcWGqjPsHU44E1uxTE1P/EKDBwwXRW1h9oPkdIDqLyXccj2CsSkdu5NQ EKafv9RHYi4medblL+ssRwoqwRlfBUND16o5aLYk7Vsw9F/95Xd4/RGfmFqrLw8RmRjRaSGQdOxPk 4xtuc8tBDbbYhke8=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rbtOu-00065D-Ok for linux-f2fs-devel@lists.sourceforge.net; Mon, 19 Feb 2024 02:29:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AB4FE60C20 for ; Mon, 19 Feb 2024 02:28:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCE51C433C7; Mon, 19 Feb 2024 02:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708309731; bh=eM91wp5LBAx8zwOBUALHG4hfaSPH2/dYptc//f0MnoY=; h=From:To:Cc:Subject:Date:From; b=Vt560GmYBuyRJ26CzATnwp7aqyLWr1MABA/yKZVulnb5NFml42f7DtlJwzNNx9ljw 9ZgBfXul2d4fKm88yTFpdf6SFXvF+x2rQl4YLS1iQbc0Zwcmb+gWRe9ovjRSp4RrNe 2UakcO/BEC1ho/NcrZfRkftZ22A0x7W9Hsvf7u+1Ogdnhn0qBJnfYurLFhcVCnp1uD qHazk3FBCu74DsOIPO2wWvtcCjzFkNi7w5ZSZ+7vdvrYMr3p1gsh7f/Azr2MaQy1jO 4Ab2QG+DL9wBYPhw6Y9W7L0W4DNdVssJlqSLTeN9umTuf1d6Z0VgUWOH3rwI6TtsKa OoAFWVXtFlkZw== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 19 Feb 2024 10:28:44 +0800 Message-Id: <20240219022844.3461390-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1rbtOu-00065D-Ok Subject: [f2fs-dev] [PATCH] f2fs: compress: fix to check compress flag w/ .i_sem lock X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net It needs to check compress flag w/ .i_sem lock, otherwise, compressed inode may be disabled after the check condition, it's not needed to set compress option on non-compress inode. Fixes: e1e8debec656 ("f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index e1e9b98f4408..62b51ac550f0 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4028,16 +4028,20 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) sizeof(option))) return -EFAULT; - if (!f2fs_compressed_file(inode) || - option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || - option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || - option.algorithm >= COMPRESS_MAX) + if (option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || + option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || + option.algorithm >= COMPRESS_MAX) return -EINVAL; file_start_write(filp); inode_lock(inode); f2fs_down_write(&F2FS_I(inode)->i_sem); + if (!f2fs_compressed_file(inode)) { + ret = -EINVAL; + goto out; + } + if (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) { ret = -EBUSY; goto out;