Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp879110pxk; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG9uTIAqX4vfO320p9aaD1vRCcvfXUOVx5fhQ85NBS0Ajrwu9VENySNVOXke0jxy2x6APN X-Received: by 2002:a17:906:c289:: with SMTP id r9mr35336235ejz.402.1600398528116; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398528; cv=none; d=google.com; s=arc-20160816; b=MkTalIgp9nz3Yvv6EvDprk2HJyAoOld4GWM2Tvnpm+eHBvoAClOMDt8YRHn6gPYfts WRIY79ikrleJAStShz+c0RB4x+2Fyeda2sQlCCAsMwG3i3Cz457yZEn4/VYFxLQEiOVA 4GmzzkHM9IvtWObQNW2vuBvlnIAf7m0X3f9bds2optocYg+1cA3q9BKM8OecfvuIVMox HHgnTf5uvuhuI7MNMe6GeKk6tHgo2YPCcxh2IhTm03Hj+pFMOTiDCdyRQYM14a0eI1J/ PjTcij3KksmFjYpdShdSx6L1G7XtjAOxCX4lYl9fk1iWesgN7so5VEmE0QvJuvzL5oWK Lsqg== 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 :message-id:date:subject:cc:to:from; bh=SoUiSyDAiXamTuSTWd6yFf/QgBlckA+zgLy4lp0oq6M=; b=ipfQMd3lniF62a/JGxhlSJ0r70CuMPcrGTkUW0d0pn217JdYCvrKysLjRlf1ooV4Pa Ps2F259X+AvAOCgSIQZGcwjqmaHipaY/0vCDFZRR0y0g4ugvJXZgcDFFw+QOERjdR9yt +pjP5LEMOnTncoDHOnPBK7AZBurtHapdaO7+Dl2ANePfpEsr5UrikkF74Of9JGkdpi3O V8wh1fLVRQ1AHZbSmg6CS4aqQta0EfuerFyq9XdLD6sZhSRuZaTtKGOMBQQMyPPPZLoK yuhZp2ieRZZIJI8u398rwk4QkZTX8IhHtjRWvSd8x36OAzEYKjKp7a2jagWESXK2nFS/ GYbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j15si1242770ejs.51.2020.09.17.20.08.24; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728531AbgIRDEI (ORCPT + 99 others); Thu, 17 Sep 2020 23:04:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60756 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730583AbgIRDEG (ORCPT ); Thu, 17 Sep 2020 23:04:06 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 59F21602F5A3BE675A3B; Fri, 18 Sep 2020 11:04:03 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Fri, 18 Sep 2020 11:03:54 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: compress: fix to disallow enabling compress on non-empty file Date: Fri, 18 Sep 2020 11:03:49 +0800 Message-ID: <20200918030349.19667-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 58e464cc15f0..139fdfc1dc55 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1821,6 +1821,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 (inode->i_size) + return -EINVAL; set_compress_context(inode); } -- 2.26.2