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: 202887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1044856dyc; Sun, 18 Feb 2024 18:30:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVODgKbc3nOzHirtUp8XsPg15cdNhLa8b4OubjMhXQW6+1ehPMGb4CnUpnvUdBFu0Sles3y5HlU7c9TW3MhVWXI7IYR8A== X-Google-Smtp-Source: AGHT+IHMdU21ngUuGNAgnUo+pAZjQvEUDD7978NTJdYU4I1kFS6FnImRPFnZNSt57tVHKxWXbOmf X-Received: by 2002:a17:90a:bc84:b0:299:5139:600a with SMTP id x4-20020a17090abc8400b002995139600amr2814711pjr.21.1708309838530; Sun, 18 Feb 2024 18:30:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708309838; cv=pass; d=google.com; s=arc-20160816; b=fRN3+hK4k7x5xN1V6AP89SP10lA5IfstOhKRuvlRUDG76Fyykd9+bQYj+LItrbdCBF hskilb0G71ckz7uTwal5aHVLTEaI21ujq+jpZdkc2myon8mwIXaFLSF4IwxRU4/jSR74 3Zuq6cii0AH7imn1qqOqcy5ryoKxD+k1p/qE1WlNc/mMkYEc0MLBvwf2MdnBWrcjgAHW WRUAg7sL/Tqgy3eAf//Ns9kQdYVbZtZc1Zw8MaJHfYydLdmTffcTCdntwV0DeZdaNMvL djOqCAHCf9wIqHf5vJxY1RCs7SBF5mYL0Bq8cVu7mmZYbA52sk7aMW2wdXeUsQ7wQxld KaEA== 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=dcbvIWnboZFfFe9LfmvMsZ5TmJ1Ms6fvjfbT8b3gtxw=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=fXZCPoYlGVTfAzQ/0O/Wa6tUd0Wi2EqVRdMHi07SWPU1T3tPBeUFiMyKhcFlSjVq3Z wVaw82R2fYRW8cSbjMoZgbdkjpE8FFNtO0gG+/i2TpV3IsQXcjZzyOVw7V+fkEmzBtp7 MSnOPKONFY79lQTInxcznI/6aSM6XKClPp2EevjPRULstEFDcZuhr6MaxLvP6FW4akOU LeE29xLqwb1hk1dgwlcxSopmXz9HT7NfdreAJLSEbjjCE+v/NzxgF56VrXlJoM2cnSzX 7VaQ0ZDopeTU4Da6qCCFsjr8Po9JVb0mIVAjDKUiPT/2Kg6Yy2j7VFidGi6U9HDG8uNl 44DQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vt560GmY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id oj12-20020a17090b4d8c00b002965e1e4b1fsi3771362pjb.51.2024.02.18.18.30.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 18:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70651-ouuuleilei=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=Vt560GmY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70651-ouuuleilei=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 2E2AAB21205 for ; Mon, 19 Feb 2024 02:29:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DEA05226; Mon, 19 Feb 2024 02:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vt560GmY" 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 C132720F1 for ; Mon, 19 Feb 2024 02:28:51 +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=1708309731; cv=none; b=tY5701AiymjcZIk2R0aIQMeI0a0dQhe0fpv2pFk9xB44pcdSIBJ1avPYS20QJ9I54eycq0pF/Izr54xtgwfVJwGMPXo7yxNB1Ar9jnRPnC09zBb3OT+NDTq3WhA9Gcv9ta1hfGoXmu+mwA4JztmTNxtROVnarbpTQFAetD8iiPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708309731; c=relaxed/simple; bh=eM91wp5LBAx8zwOBUALHG4hfaSPH2/dYptc//f0MnoY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=f+Qzgl9L/EHJqzbZzMZpzQ6gZRgCSF5sCTnE4+SNJcBCrqvpbVWAL1argALr5BmDK3MaPze+miJyG+xEhqEEs1AUuAAiFMKu1nW0McYoWSc+RXgZC8FL5IvPCHTg2jwqDBhUH2o9fdLYjr4BlCbrbOn2UF4CUSytkuRtQlExq+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vt560GmY; arc=none smtp.client-ip=10.30.226.201 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 Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: compress: fix to check compress flag w/ .i_sem lock 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791292697260864269 X-GMAIL-MSGID: 1791292697260864269 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;