Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2885705rwb; Mon, 15 Aug 2022 13:18:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7wmxZUZWtv39MhHRxeSLOjTkkteXQOJdrafxMq4mVLBSyLa/ccRtTzWIM5EKvW9Z/8fRPl X-Received: by 2002:a05:6402:530e:b0:443:df38:9df with SMTP id eo14-20020a056402530e00b00443df3809dfmr3585138edb.9.1660594699082; Mon, 15 Aug 2022 13:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594699; cv=none; d=google.com; s=arc-20160816; b=QoyUiBd/qtNDFvX38liajPxkKsUbY4L1F5vC1Ful5u2UGlRK0qqvFrM1pPyinOw1Rh bPI8VWKBpnBTIaEqOLAlg9ehD+uzYYymvro/OmQqQE9/PXPrrELX9whUE7ee6jGXlXaw LeYFRvk+uIe3xLsiqW9GkHtD4nyA3iO7aohHhbReG6oxWABePXnNDZdPjjrv/dTU8KjO rcpTkAn3KLmv9sSEHjSAX4uGdHlxWljMCeQbW78T4KroNCNFn706LZB519NgrScewB3o LL8/3gJP7YY6+e9Yljkv64/Np3skhJTB+KqzB8VDnp+52/jo+qDnaD4VZ13UqPWlRN0S 9r1A== 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=0SGEsw+9KMSPZaT6JiAELeP4OVuuU+MFpwl4jYY70Kc=; b=rboc3W+Tr20EeSaFncS0JjUROLNem4tTqdTM7GKVcClkL8oA0VHIM1GaMbObHnoY6J TCmtLLzLAzLg7VtXc/3H2YYE/6sooUfDJAXYQo76yEKU4BF/HQrt3zUpIoy8zY/5Cuuo 5M1+s6AUZ1NNj18Mp9mAvu4rzjPh2ca1X1bGVBwYzw6ssAP5AoeGwHGRyHuz3HLaMH1G Q1mi0b7VU0w2NgZoZx62cWsb1kcWnES2sDS/7IQ2xUEKZCUy01Cssb39ftGtJK7wSJg9 HSfaJdUduSF0Ooi4njX72E7u2jf82OfMpDYDE9kjbFpNOMy8ceAUXESwRID0ukEC5VF4 MO/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fumdkHlq; 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 s23-20020a50ab17000000b0043bca9c457csi8810070edc.396.2022.08.15.13.17.53; Mon, 15 Aug 2022 13:18:19 -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=fumdkHlq; 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 S1345251AbiHOTtH (ORCPT + 99 others); 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-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 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 *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; @@ -4078,6 +4083,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