From nobody Sun Dec 14 08:05:25 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47FC2C00140 for ; Mon, 15 Aug 2022 19:49:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345254AbiHOTtH (ORCPT ); Mon, 15 Aug 2022 15:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345560AbiHOTrH (ORCPT ); Mon, 15 Aug 2022 15:47:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C4CA70E64; Mon, 15 Aug 2022 11:49:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B0117B810A1; Mon, 15 Aug 2022 18:49:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAE89C433C1; Mon, 15 Aug 2022 18:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589368; bh=MXWx+3HasW0tR213YqIc6ahlgS/NMcSpnkiVtVTpnvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fumdkHlqrimhcrllJ4qus25NVcbJTFzSlDo4qL1hzzxktwPIWq0caoMSdE0tg+3zo Lvn5FMwCC0kAu24SwJIcdjh+Bwb0FGzBf/0HDA/suea60P2fCmtHscJTLeYMJon0eP vD0fCvty0fD4cLyLjOsXHIZmQg9VrT+U3CwmK8k4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junbeom Yeom , Sungjong Seo , Youngjin Gil , Jaewook Kim , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.15 665/779] f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED Date: Mon, 15 Aug 2022 20:05:09 +0200 Message-Id: <20220815180405.775800553@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jaewook Kim [ Upstream commit 90be48bd9d29ece3965e5e8b21499b6db166e57b ] If a file has FI_COMPRESS_RELEASED, all writes for it should not be allowed. However, as of now, in case of compress_mode=3Duser, writes triggered by IOCTLs like F2FS_IOC_DE/COMPRESS_FILE are allowed unexpectly, which could crash that file. To fix it, let's do not allow F2FS_IOC_DE/COMPRESS_IOCTL if a file already has FI_COMPRESS_RELEASED flag. This is the reproduction process: 1. $ touch ./file 2. $ chattr +c ./file 3. $ dd if=3D/dev/random of=3D./file bs=3D4096 count=3D30 conv=3Dnotrunc 4. $ dd if=3D/dev/zero of=3D./file bs=3D4096 count=3D34 seek=3D30 conv=3Dn= otrunc 5. $ sync 6. $ do_compress ./file ; call F2FS_IOC_COMPRESS_FILE 7. $ get_compr_blocks ./file ; call F2FS_IOC_GET_COMPRESS_BLOCKS 8. $ release ./file ; call F2FS_IOC_RELEASE_COMPRESS_BLOCKS 9. $ do_compress ./file ; call F2FS_IOC_COMPRESS_FILE again 10. $ get_compr_blocks ./file ; call F2FS_IOC_GET_COMPRESS_BLOCKS again This reproduction process is tested in 128kb cluster size. You can find compr_blocks has a negative value. Fixes: 5fdb322ff2c2b ("f2fs: add F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMP= RESS_FILE") Signed-off-by: Junbeom Yeom Signed-off-by: Sungjong Seo Signed-off-by: Youngjin Gil Signed-off-by: Jaewook Kim Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 0669464a942a..758048a885d2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4011,6 +4011,11 @@ static int f2fs_ioc_decompress_file(struct file *fil= p, unsigned long arg) goto out; } =20 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + ret =3D -EINVAL; + goto out; + } + ret =3D filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (ret) goto out; @@ -4078,6 +4083,11 @@ static int f2fs_ioc_compress_file(struct file *filp,= unsigned long arg) goto out; } =20 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + ret =3D -EINVAL; + goto out; + } + ret =3D filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (ret) goto out; --=20 2.35.1