Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3866567pxv; Mon, 19 Jul 2021 10:37:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUqMZYk8Wb6qzk3pTfUCbWGjcEf0TfFhy8dMlGr3OILYUSbnOqUNl/+22KvOt+d71rnrOo X-Received: by 2002:a17:906:3e8d:: with SMTP id a13mr28316977ejj.463.1626716276841; Mon, 19 Jul 2021 10:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626716276; cv=none; d=google.com; s=arc-20160816; b=xxBv4lVU5rEp3HNMZ8e1aIjchjc4dDgUtHFgjSR1it/a9BCbO7JHycR5zAZE8tUM6k P+9LCWbGcIpUKsctAjcyBHDRv9bT2/UazoWRnVzKJXysKRpwySaqbHWLvKKxSY8jNnQf 1E74YOCV8OUtTJyS9zJzrtRTJZ/oz+Ftz1/ROQLoPxOksTFNzOTqjQyBxaVQyDnXK2+X 7zJP7F1dZpfOJQtAxhQjQOryC26FNX9iRQUhY+9MMzvmjz0uVRejInWyMK0xHuALCFLN xsq9l5tAjKIuhThHbKcmQji07lTjL32LHWQFO82/va3+ERUDXh1xgt7aTSno9mNSiLfW DNuQ== 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=M91s3SK/PfGS5olf+97rOPI5JolDvdBZB61PceeOdVc=; b=0oc8J5AUjPBSVmmuX+7GuQfptIXGZXb0rcnn0A69AD4sHAJG8uLa6HK8Eq9uGNvJ1C sG7xN8cjnV1WzSSNoQBrbBjjoXraOtIal3nux3lKdP2X7XGsYPtX1w86MnvKArvVy1Wn 2ZsyFPYXtT7kds6Gtsl3/xHWrDlbM52Tt2+dyPKBtYOcrAGnSCYwmyebdWCCXypGEtke YFQ3KgO2mFA0o/HJPbqyewFQWz0o/juGU10KRtfBoAKhLKIIT2PyHF4B3F7V4WVmAgHy mTYVKvB0sqrlF9Wy7eJt/b/B+vntdJAVAjfL1PCc2v+OFnpaTQFQMWv0UnSg+1JCeYdS qRFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p1CatD4r; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y94si22406834ede.150.2021.07.19.10.37.33; Mon, 19 Jul 2021 10:37:56 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p1CatD4r; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357857AbhGSQwX (ORCPT + 99 others); Mon, 19 Jul 2021 12:52:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:59626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347836AbhGSPVv (ORCPT ); Mon, 19 Jul 2021 11:21:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 261C161436; Mon, 19 Jul 2021 15:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710361; bh=Y7yppflBy5utAZsnnHlfwjALjTCptW7yoJJ8lffSU2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1CatD4rSruYbJSJKWox3ubd+iotYry7sSBr+oCpz0IcrN9YoBtI+zvEHy/oWDtPZ J8sGbZabn/nj3gkVBExrsuXAnSSD1LYzS2TjTEKinHjuE7yyZRmQMxsZCNer5XIDND 5kgE1NqqOCsxxQz2yToOdqkFaYmL7tmt+J3EiiCA= 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.10 150/243] f2fs: compress: fix to disallow temp extension Date: Mon, 19 Jul 2021 16:52:59 +0200 Message-Id: <20210719144945.750453894@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@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: linux-kernel@vger.kernel.org From: Chao Yu [ Upstream commit 4a67d9b07ac8dce7f1034e0d887f2f4ee00fe118 ] This patch restricts to configure compress extension as format of: [filename + '.' + extension] rather than: [filename + '.' + extension + (optional: '.' + temp extension)] in order to avoid to enable compression incorrectly: 1. compress_extension=so 2. touch file.soa 3. touch file.so.tmp Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/namei.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 5f7ab4f11322..17d0e5f4efec 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -153,7 +153,8 @@ fail_drop: return ERR_PTR(err); } -static inline int is_extension_exist(const unsigned char *s, const char *sub) +static inline int is_extension_exist(const unsigned char *s, const char *sub, + bool tmp_ext) { size_t slen = strlen(s); size_t sublen = strlen(sub); @@ -169,6 +170,13 @@ static inline int is_extension_exist(const unsigned char *s, const char *sub) if (slen < sublen + 2) return 0; + if (!tmp_ext) { + /* file has no temp extension */ + if (s[slen - sublen - 1] != '.') + return 0; + return !strncasecmp(s + slen - sublen, sub, sublen); + } + for (i = 1; i < slen - sublen; i++) { if (s[i] != '.') continue; @@ -194,7 +202,7 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode * hot_count = sbi->raw_super->hot_ext_count; for (i = 0; i < cold_count + hot_count; i++) { - if (is_extension_exist(name, extlist[i])) + if (is_extension_exist(name, extlist[i], true)) break; } @@ -295,7 +303,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, hot_count = sbi->raw_super->hot_ext_count; for (i = cold_count; i < cold_count + hot_count; i++) { - if (is_extension_exist(name, extlist[i])) { + if (is_extension_exist(name, extlist[i], false)) { up_read(&sbi->sb_lock); return; } @@ -306,7 +314,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, ext = F2FS_OPTION(sbi).extensions; for (i = 0; i < ext_cnt; i++) { - if (!is_extension_exist(name, ext[i])) + if (!is_extension_exist(name, ext[i], false)) continue; set_compress_context(inode); -- 2.30.2