From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CC8C388F9 for ; Tue, 3 Nov 2020 22:06:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4357E223AB for ; Tue, 3 Nov 2020 22:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604441176; bh=JLplXyY8y8y3p4QwaVfHP09sC69eM8s1cDPWAhIlVgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UyBldrc05QbNdw9keMp1AEb2zYWYaPxMXQAfrrUHv6xCSTK6pARNKaRbmoxlOgJuJ FnipEm1xi8IcaY0IOHacqHMJ3hdjGQPp5bKWhd11Z2VG/lgHtOWln63bYu0KwxFOCE jMDlFRskSLkYGIWA6bcrlERqn6GcRsrTejxe2d/g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbgKCWGP (ORCPT ); Tue, 3 Nov 2020 17:06:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:53654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730014AbgKCUln (ORCPT ); Tue, 3 Nov 2020 15:41:43 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD2652224E; Tue, 3 Nov 2020 20:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436103; bh=JLplXyY8y8y3p4QwaVfHP09sC69eM8s1cDPWAhIlVgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xR/o+CqGrdTkFTV5SPJp/vCy7HX/l3hnibujoTMQVXAzUoljpskCTe7KBbSgq53ic l2CpSvweASpyiKDH4Dt/cHB5+PBnkE7hEze2f+1rbJhBDnm+wEQ/dXVqdr61BPZX/8 GPBBMPOMm+A58BLuD/OvN4kpOQ/MjAVARAIzBouw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.9 056/391] f2fs: compress: fix to disallow enabling compress on non-empty file Date: Tue, 3 Nov 2020 21:31:47 +0100 Message-Id: <20201103203351.210726314@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Chao Yu [ Upstream commit 519a5a2f37b850f4eb86674a10d143088670a390 ] Compressed inode and normal inode has different layout, so we should disallow enabling compress on non-empty file to avoid race condition during inode .i_addr array parsing and updating. Signed-off-by: Chao Yu [Jaegeuk Kim: Fix missing condition] Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 8a422400e824d..4ec10256dc67f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1836,6 +1836,8 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) if (iflags & F2FS_COMPR_FL) { if (!f2fs_may_compress(inode)) return -EINVAL; + if (S_ISREG(inode->i_mode) && inode->i_size) + return -EINVAL; set_compress_context(inode); } -- 2.27.0