Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp724110lqe; Sun, 7 Apr 2024 00:26:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVykNaDzWzsXcj+U98a25tQXraK/YX6NlyPFPtTZqUFcwt486YcBlUUT0AIO7fPLSNjbbRw/8WB2YVm0HiE9wj0KMtqd+VO9r127pqgQ== X-Google-Smtp-Source: AGHT+IFaZh4Pb9oqHqNFj4KPckECy3spZubV2dA45gsvycoP3UggG29bWV3JFbs4oTHE2B/4z8AA X-Received: by 2002:a17:907:2d13:b0:a51:b0e1:863f with SMTP id gs19-20020a1709072d1300b00a51b0e1863fmr3707405ejc.13.1712474793831; Sun, 07 Apr 2024 00:26:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712474793; cv=pass; d=google.com; s=arc-20160816; b=OEug/4SRREmjnEDq0PNCwZiIbKwYrqktl4cdWVBk9Oe+vz7JSRN45TfVBmxjFSuhsY VL2aIXlJKMlP1D/xBU38OCdx8FKCsno3KuPp/EH0szTzsVflQfhsxmDYbtet+BIeuZdL DtZRYrK5znbnAxFp2ahq31qzdFnwYDvGYjSTk9H8B+uC+CYBUaiaNPVIrwbX7mgArFkh lHtn+GHBbLUJwf1WBvLQRm5lU5BNAN7Jp/dyrp9hKz2PeWXHIqVH1O40jiGxvwgbJ+PJ 9Ufl4Mwx11+Xirz78+kejz8++GJYTbzgkgX3mavBY1wTyywONuenBpRvpi5qWTPZ5URU PyLw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nXeLSyqlm0ofgMBuASoQ1jIp3rLB1MkJQmGdlpCX63A=; fh=eLW+fWdexutSV82wpzYqRHT7xIXx30+HypqWzPzY8A0=; b=jTX8//XSDDMwdUXx+MEUHz88FpVWk8LeL9nxxUuJ5e7d3hMhuIAcV1iADqweRqpWSt R0Jgn5Scg9arM8rw2mJDCOkBxk6JGuBi/Ws1dzdbG3jglKKjGplwpptoi6hWIbhnYs3T 5ngr5nt4ly3xDlp16UXOKWJJ/vNC36UBuo4sfQyVcPzVa+wioJvwQtepS0N0W4pebP/i fwBuHGrybH0F+3mz+NCp/F5XbsFNbkdEkbElV9C3wR0NBoNlff/jE35cAnwsAHyxg7Wv kf4F/LTvSZYX4KOOZiYZOV8SLDsFJvfni1dwL6cAqow18v1yM1COUf1q1EKn2abnBjs9 57pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jiKKm2z1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-134221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w9-20020a17090652c900b00a4e41d4080dsi2327172ejn.1021.2024.04.07.00.26.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 00:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jiKKm2z1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-134221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134221-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8E2E51F23B23 for ; Sun, 7 Apr 2024 07:26:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67B551118B; Sun, 7 Apr 2024 07:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jiKKm2z1" 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 8F849107A6 for ; Sun, 7 Apr 2024 07:26:17 +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=1712474777; cv=none; b=uGm7yiGJiDEaYlhDrInLqBuDrUSzBB9Vxa1gdiu9ImvF/18Ra3gJoUKlk30UoGvqwu6oj3YCkVnhQfB1ybuJGT/dYF+2/YP43YSg0ePgX8BIS0mT9w1Rnt2gJW6uvvbT26JuKIPpM2zEmkIkUJ/fWFBoFVOnUsBI/qrB/IIY/8I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712474777; c=relaxed/simple; bh=M0/dwoy3n4OuzNbOOGe4V4klmcbe/S0AlwHuaNRNolw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NJ5SqCh0Kuo9FR/BiWvEDC39uRmZ9yzFhxms654PvXaBZLKxJTdxUgyWousNQ72q63LdbCQeVNV+1IF8D1NGtufkeBvfgLHIErLpqdYEUGy+9rAcQ0QLSb9di7mSHyV9Hwqaf8Sz4DgKX46oDquQL0zDSpPBqqvzRCxIfh7B4Uk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jiKKm2z1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 741DEC43390; Sun, 7 Apr 2024 07:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712474777; bh=M0/dwoy3n4OuzNbOOGe4V4klmcbe/S0AlwHuaNRNolw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jiKKm2z1nI2lPSoS8JXqg29xDl3qEuJBR0uZ7KUwK7FNDx5n1Q/JtYFuPbdNxPkHE kI3Txf7+vJHAVmg5nNVYfpfMKIVBlVgX9ZBKa8RQcHwnhGxqoy5ZG73S/p2762tCEL bB7KlyirZFgt2KdxNLY8DbG/G8zBPMypytAQmBXeeY5ZT+PSLkya0dDAA6XgDNRFXV QiOXWf8PkC9hxamEBwGTmGLRItScqapqPx7POTCyXdXnU/tCt3ZQXKkknEXlkNXXyK r3b47ADfPaBday+P7h4tSGmzr6y1BZuaQJ+SfK4NfIxOfvUCxIMfi56d+zziSZsugz kdvI8SuzaDl5A== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Zhiguo Niu Subject: [PATCH 2/2] f2fs: compress: fix to relocate check condition in f2fs_ioc_{,de}compress_file() Date: Sun, 7 Apr 2024 15:26:04 +0800 Message-Id: <20240407072604.3488169-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240407072604.3488169-1-chao@kernel.org> References: <20240407072604.3488169-1-chao@kernel.org> 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 flag should be checked after inode lock held to avoid racing w/ f2fs_setflags_common() , fix it. Fixes: 5fdb322ff2c2 ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE") Reported-by: Zhiguo Niu Closes: https://lore.kernel.org/linux-f2fs-devel/CAHJ8P3LdZXLc2rqeYjvymgYHr2+YLuJ0sLG9DdsJZmwO7deuhw@mail.gmail.com Signed-off-by: Chao Yu --- fs/f2fs/file.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index ca401cf8152a..232dd5fc8ab3 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4142,9 +4142,6 @@ static int f2fs_ioc_decompress_file(struct file *filp) if (!(filp->f_mode & FMODE_WRITE)) return -EBADF; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - f2fs_balance_fs(sbi, true); file_start_write(filp); @@ -4155,7 +4152,8 @@ static int f2fs_ioc_decompress_file(struct file *filp) goto out; } - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto out; } @@ -4220,9 +4218,6 @@ static int f2fs_ioc_compress_file(struct file *filp) if (!(filp->f_mode & FMODE_WRITE)) return -EBADF; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - f2fs_balance_fs(sbi, true); file_start_write(filp); @@ -4233,7 +4228,8 @@ static int f2fs_ioc_compress_file(struct file *filp) goto out; } - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto out; } -- 2.40.1