Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2396824lqp; Sun, 24 Mar 2024 17:41:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmsvFad6dVmUls7o9zTsrnkCEpcBNXFngchtuAoFVNiDFDd2QmPOqdfhxUU6V0pM87Q/y2got7a2sztjeuBkXRQ3wydKn1bX4t4coZ/A== X-Google-Smtp-Source: AGHT+IHxNrAjcxLMeiVPigKtcPbzxnBYnbdSdZD46qOA20A4iJflT0ft24QVuNdWZEL8Nd34ESr7 X-Received: by 2002:a81:a0d5:0:b0:60f:d70b:c1f9 with SMTP id x204-20020a81a0d5000000b0060fd70bc1f9mr3887992ywg.24.1711327311061; Sun, 24 Mar 2024 17:41:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327311; cv=pass; d=google.com; s=arc-20160816; b=Y5EJQshJtwtFBS/9j+lmjMWHt9xqEERFGrW4EtOarC3m3qePuZ5Y6iS4jS4JwFsm4r NXsD9VSQ4o41okftrhIjWvbigFxD6LmePVECIn6zIW1cLszNEcKmZ3XT6Ct9kY90USyH icVOPJE8k+SmJmQXSjssyoF4qhx/oxA7SQxr52gW9uxXmKgoFavNXNsVoumN24SYCoDK CegcQPK7dnC7xllMR40qqRrX026qhfI8Wr3qli2c8J6RPf5LsqY5QNkoPNomnCMfvp03 r+dZvQ4avXcL7pF+VzfV6slRnLuHLikTVzv+pO9c2bGVEDiHwANc2KCu3noqqwviLdkj U8Qw== 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=48aobNBU+UuupduqDJKa+HCCMa8IU5pSDeWBiSNaA3k=; fh=12a/sEIKzFufS840P/8mjdllY8V10TQux2Vn471Up2g=; b=KXhHgya+LD+DqYu1KFdJL+vrIERrS1SKZTLWkLBeAWebP6B5ReNa5AM+ZByBvwcjsx DLJ5NhEH97DXlx5t4u8aVd77CWNr0B6wfKMd2dHcC/1vNhf0quEm3hUR7DSXyXC3eAJ7 TxuRwsOJyBdiJ/IeNEwIIJ9xifdNjfkX5l03QqT90PkdO6qgh8ayeUfKjVcS6hZfOIJc LPefYFEvxtanf7buXKzHrrpQuUu4frML0LJnqRPp9X9Ma/06mRCSR3eTfFLjx0zzbjmO 9GeQJzbKdnErXsDm/KIxGFUh2mFy27CKPSZjbWcGWN0iv/Y2LNDelGgU6k/kexv6URBq pfog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Eq/gKX7X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113457-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u14-20020ac858ce000000b004314f16a8acsi2134988qta.667.2024.03.24.17.41.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:41:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Eq/gKX7X"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113457-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 23A761C221B4 for ; Mon, 25 Mar 2024 00:41:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3E8B1B0DC0; Sun, 24 Mar 2024 22:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eq/gKX7X" 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 CDE1C1B0602; Sun, 24 Mar 2024 22:44:18 +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=1711320258; cv=none; b=XCf88Z2uJvFmC39MFGizZhhBrKH5i0fP92mn1lgSmJ0cA1l1V+lfTCStdCZAVR4tfnMXxxgztG4d3xoVttRhOcnrm4ZI7VOl3ftsyf9HjVyZDiLVoQYiruuQoyH+ul2UFDPIOutsJKQBPbJuGcrqugy5poHBmSbcEH6fO4E9M0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320258; c=relaxed/simple; bh=KI8qSZZy6SggNUMA1yvSb34YeToixqBDBxB761i2aM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u7f7NbwmKnEQqO53NSL5pg3WDYCmm+6y78Hx181QLIVFy7Y7a+PDGFcXnjTkLuBDSQc0Dy144FWm/iDxV9Qzrh+jJ10+7TJV2V0mCMjIGZUTNlysfX5rhCYZ5WZUYGcBDyIf7JN5SywZujSgAtkHpA9+nekuLTGlXNk+p55g/mw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eq/gKX7X; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CFC9C433A6; Sun, 24 Mar 2024 22:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320258; bh=KI8qSZZy6SggNUMA1yvSb34YeToixqBDBxB761i2aM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eq/gKX7X5NXZp+BnAlv45YkAx2QNbqQ+5Y7iMN2T1yxxkWWBpQe1o1QZ1Txy/rki3 u73bNTPifdwBCPWUEMJGkTsrncOzbIzVE22OgEWair2kNtFN54spaJnpJG2hGfVmmL ccIpUgSjCyC2E5zkN6HRRZ9jxjKf/+bTjMmPVy6avciPfXvAM4pS83cifyK6+55RND xokNNVW3LO153J8bC5vZb1mwOoubQvwF1L5yC6WKB2eUHXJgYozy4obAY1OFHT5R/3 REs816+eQDOoeWmO1ARTW9thc895eNWv29x2cfV4vqqaqnzHXmmSn+eer3ZnAmM2Mc qYScVLWMv92hw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.8 566/715] f2fs: compress: fix to cover f2fs_disable_compressed_file() w/ i_sem Date: Sun, 24 Mar 2024 18:32:25 -0400 Message-ID: <20240324223455.1342824-567-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Chao Yu [ Upstream commit 2f9420d3a94aeebd92db88f00f4f2f1a3bd3f6cf ] - f2fs_disable_compressed_file - check inode_has_data - f2fs_file_mmap - mkwrite - f2fs_get_block_locked : update metadata in compressed inode's disk layout - fi->i_flags &= ~F2FS_COMPR_FL - clear_inode_flag(inode, FI_COMPRESSED_FILE); we should use i_sem lock to prevent above race case. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e4e249dd4c712..03c0d2e996fff 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4406,15 +4406,24 @@ static inline bool f2fs_disable_compressed_file(struct inode *inode) { struct f2fs_inode_info *fi = F2FS_I(inode); - if (!f2fs_compressed_file(inode)) + f2fs_down_write(&F2FS_I(inode)->i_sem); + + if (!f2fs_compressed_file(inode)) { + f2fs_up_write(&F2FS_I(inode)->i_sem); return true; - if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode)) + } + if (f2fs_is_mmap_file(inode) || + (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))) { + f2fs_up_write(&F2FS_I(inode)->i_sem); return false; + } fi->i_flags &= ~F2FS_COMPR_FL; stat_dec_compr_inode(inode); clear_inode_flag(inode, FI_COMPRESSED_FILE); f2fs_mark_inode_dirty_sync(inode, true); + + f2fs_up_write(&F2FS_I(inode)->i_sem); return true; } -- 2.43.0