Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3122921rwb; Mon, 15 Aug 2022 18:41:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dJGxumcAig5GaTzQ4IpZaXPKYE2bE5Na1bGCmjhb4QBDKa+Wq2oqWLreeD8xWJqOp7UaH X-Received: by 2002:a05:6402:34c3:b0:43d:d8d7:a328 with SMTP id w3-20020a05640234c300b0043dd8d7a328mr16956840edc.297.1660614088280; Mon, 15 Aug 2022 18:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614088; cv=none; d=google.com; s=arc-20160816; b=c255IDPsRBSMZA+RfcXgfP6FqcOGJXJGb0pEIA61eu2LyEQBYFR6ek6m/ii9zfUgTt tuwbhyMWRhUVsx03m1j6otLylt2YFTIrcRvqqNbINYgjYVe03V5wkoePbzH+oE2xi2RT RJrRS/Z2pDSjXvJXK4Hndjif/UxwVOJTYaUI2jgKGXBeqR2WbfUMI9SV6DqLg+4HT4s1 KpK4bgIM8kR1d+aqAxodpFiKNVdlrvzkSbmfVeBykhg8lgrIBkP1GVYol9XHtHFulOwS ZJzjVcjFyCd7vvEcJEtic9NFADSIzvc0f3LBYI3M4dLUVL42gwEDBpN/56MnENVInJVM g3qA== 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=QDqQRk2PHDv016DOPmyy6Y57x/NfmMjyG/TPlvf9m6M=; b=vP+oMLcq3SJFtKWHpBCCOhNjtjKtvdXAHIt4CdbynfLlAAAV16sxZjZeh1sD/zqvgo xGx2PI6C90iHZUSPSKnnDO7Vocm5y2cRcrD5Y6l/d8jTNAINXOeyayU4l6HQXT2rQb1c Qhgwsd2obBYqpI1fU5cuAc15XnHe0q8opZx5me+M5eRLiSGXTg2DisTemD2ltSoQiK3F YGKGGF9HY8F4Jas+YkRSSFKVby7gYZ1xyfsDsF60XeWFY0KsKPxN+iKq+hVxFZ2zdm3l yTWjkd4zO/CjGvGJ1zALVwmnFkuOu+29Mi+UQrX1psbnKZRGEO/GImN8SVtkWOybIiVq LC4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RqwCtg2W; 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 dt16-20020a170907729000b00708f4d9dbdbsi9130769ejc.79.2022.08.15.18.41.02; Mon, 15 Aug 2022 18:41:28 -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=RqwCtg2W; 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 S1345922AbiHPAvF (ORCPT + 99 others); Mon, 15 Aug 2022 20:51:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348298AbiHPAqQ (ORCPT ); Mon, 15 Aug 2022 20:46:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57BD5195801; Mon, 15 Aug 2022 13:44:42 -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 9C84C61234; Mon, 15 Aug 2022 20:44:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3BD7C433D7; Mon, 15 Aug 2022 20:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596281; bh=Ef3xeZgzahB89Xng1bgwTCNC5rqHxTuILhQ5Jh5It2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RqwCtg2Wg369OxiG7MbDAgli7P2eAzMIHjDUTQvAzDqdS405NTktSNPVY8ddy4J+t g8/pJhyyxaPaVE4kXsrSV57Quu6bha5aWo8lnX399K+wChn4mcgRnvBta1e4NQS8OZ rzyyPwPBC9qt9Vh3K/fsjUbyNTCricH2utp4OkRs= 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.19 1029/1157] f2fs: do not allow to decompress files have FI_COMPRESS_RELEASED Date: Mon, 15 Aug 2022 20:06:25 +0200 Message-Id: <20220815180521.104958541@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 110c459c78b6..fc0f30738b21 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3938,6 +3938,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; @@ -4005,6 +4010,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