Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3119295rwb; Mon, 15 Aug 2022 18:35:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rHqWOnxGDY3v5cH229JTcAWWmb0q2D7V05aXaps0zj2UIDnGJs6pQbQz0NiFZdy3X4dqr X-Received: by 2002:a17:90b:3d0a:b0:1f4:f03c:5f55 with SMTP id pt10-20020a17090b3d0a00b001f4f03c5f55mr21332970pjb.103.1660613727400; Mon, 15 Aug 2022 18:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613727; cv=none; d=google.com; s=arc-20160816; b=cw326FipJfpJtZ6zSQ8GACuog13CzkFp7sPMf5dQ/m83MvNe312rwf4MsZDEiyWgN7 uGmKp6gdonyISom4zdcG0u5xTHNauoDcAcIp2GaVzfSKrmHb0hEro8XhCZ3IrAz2oNSJ kFDDa1MXjU6t+ED8m776xG+er9KefQdWB9vOCprRjOgzonCGnCFp4gHzeOE6kbssvc/D ILtLqQScuKhQgtEcm/IpdmdgjSj0PI+IAJGDR+w+i8vR1IqRq8y0k4epoSuil2jSNXV6 ncW4B9jADUWDSSIYFvhlbVswLxtmnVn2C6afWwRCb/2pDGJp8rwilJGMQbfYHvXd6+df 762A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YLYpybP5xTx9hJOmVV4yKL55YJSFfuHcrP2XomiDGGc=; b=VRcUIPi+UQK46tGcf5b74dg12H87oKODI6eGbNYWgVBsHPsrKAkJBViXWKbL4+O/xD np7KHjSl1RHPmStP/M4QlU4owBvRlXP9t9FNjjzekdkZR+Qh+DZirf+55MlHkmFADHmk lsPXE8+mfI7kFPGvCP7jXVnC2DFux1qIC9EeG9Iy1G9fwMFFU1KkDbBrgoyyFbJKWqF/ xa0WZoartXqnMdPRM9wsc8ftSd7Wk4HSUY9y67OOp/P2dn6vlSQVvl5YOotqG5cW0Xx0 C6A5A4+eOZ58z8qL5i33CfpASk6B4jPL42Z9Yvbyo4NChk/6ij4gpj7p2rtu+dKXQlkr PvnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JVXYvYuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a170902744b00b0016cd74e550fsi11320153plt.351.2022.08.15.18.35.16; Mon, 15 Aug 2022 18:35:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JVXYvYuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245504AbiHOXHs (ORCPT + 99 others); Mon, 15 Aug 2022 19:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbiHOXDn (ORCPT ); Mon, 15 Aug 2022 19:03:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D0E140387; Mon, 15 Aug 2022 12:58:26 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6EE0961299; Mon, 15 Aug 2022 19:58:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BA6EC433C1; Mon, 15 Aug 2022 19:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593504; bh=v6rhzKfkgAizoOjuCss4MtEIm16S+hpSuSNYbD1EtjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVXYvYuuxQqBTeZI/9ep/xmlcBFbH24Ju4zLw5rn0DwUjPobLmNuZTd6YbvcB9Fs5 OUG1difKCHMzMfNfzzxvb1g1uPlioRPsmeD/pAa05Xti80g2FhZzkKTsjuUr9w/sFq JgPMBy9HGSuKzyF4CobtaRInuGMR/X9i+jdsyRxU= 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.18 0955/1095] f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED Date: Mon, 15 Aug 2022 20:05:54 +0200 Message-Id: <20220815180508.602611543@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=user, 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=/dev/random of=./file bs=4096 count=30 conv=notrunc 4. $ dd if=/dev/zero of=./file bs=4096 count=34 seek=30 conv=notrunc 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_COMPRESS_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 9a676ea080e4..c2644a085876 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3914,6 +3914,11 @@ static int f2fs_ioc_decompress_file(struct file *filp, unsigned long arg) goto out; } + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + ret = -EINVAL; + goto out; + } + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (ret) goto out; @@ -3981,6 +3986,11 @@ static int f2fs_ioc_compress_file(struct file *filp, unsigned long arg) goto out; } + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + ret = -EINVAL; + goto out; + } + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (ret) goto out; -- 2.35.1