Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp883808pxb; Wed, 3 Mar 2021 19:38:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgc5uVt14ISrYz0Rd90P/YUaKWRTzI/Uz7/Tpp/AjuY6n6I9enmPUVh1EUBF5MUila9yeI X-Received: by 2002:a17:906:8447:: with SMTP id e7mr1989494ejy.523.1614829139175; Wed, 03 Mar 2021 19:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614829139; cv=none; d=google.com; s=arc-20160816; b=VjSJQTV76eDZRet56yrduJ80gOy4IITo4/WkZDbKKr0mIYe4h0rk4tXBftJsC4wTQ5 cF1ShmWdhTqPZhGre4ZGcBzU2QeYNvJ8J1ihvC++mk4iioSn6AQsrcXBcXbdUeaF/kYC lT73Cx11JNkg/SXWpki6PCE0BRkD56ItfRgOcOiVhSYOwfozYBigXVv4NclHALmTpoEC rEhiB+xo0osagivNzjAlQLeryJsKvU2LTOD+/l6Xc1ErRy48WCDvM6ShS9GYW0kV3YCK x+ZzCfKE7dGTwd3bwxr6ZACa+nwfNcaySuuouEd96+WPEUCUPzzpFHWNdI1XfUJeDmTp Et/Q== 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=J7dy2YXOEWY90BUW2IfO4d4GZwyGweVbefR4yulUG8o=; b=qjn3KULXKPPj0MkrOb/CzFDR58zh/ubAOtCVjs9FWIZS9GSehRRP2ookYp2TjWsGFe NLXhtqmv1pl5hRN8xqfCCUI5fJuV4IJEx0p40gv60oEPu9wD7BGbAGYFgM44xFap/C99 wdi18D3GNqehqPYcSO4ljhX+dIBWWZB25TbSM3OJYARHQr1D3AUfr6Kx/1EwteiOMPsW PRDwxN6LswNUVZxRBZAaLxtpLtSEn7np3IYzEhZo0dUI7XrRtEFnAGiTYdohGR2D6eWo /f/nUg5DmXLh6gRNpxCyHg2i36kogh5jqzPlGdeiyBPmrsfx9c94ZDkOoAozM4BvFb/q tMkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LXpJxCY4; 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 a3si4204424ejv.34.2021.03.03.19.38.37; Wed, 03 Mar 2021 19:38:59 -0800 (PST) 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=LXpJxCY4; 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 S1379550AbhCBB3d (ORCPT + 99 others); Mon, 1 Mar 2021 20:29:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:43778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241336AbhCATRl (ORCPT ); Mon, 1 Mar 2021 14:17:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5D3A364FAC; Mon, 1 Mar 2021 17:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619927; bh=jkYkVpAqzEwNzMLJMnx9H+tcjBK5LEBloeLvPcOnei0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXpJxCY4LMEVSz1A0SuTrkNuWlnuBsmDWw8zYluGFneItBz2BBQl46UU+xqol/3eh xv3OWOIUriN86B8hotNVQ7JxV+b5MjpY2xqoO8b42o3Qq4i5VOxSuseIoCvlYW+ipm b1XXxsBuaHFcjFnekbbrywil9w091CLboABULAuM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Chao Yu , Jaegeuk Kim Subject: [PATCH 5.10 632/663] f2fs: enforce the immutable flag on open files Date: Mon, 1 Mar 2021 17:14:40 +0100 Message-Id: <20210301161213.125037321@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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 commit e0fcd01510ad025c9bbce704c5c2579294056141 upstream. This patch ports commit 02b016ca7f99 ("ext4: enforce the immutable flag on open files") to f2fs. According to the chattr man page, "a file with the 'i' attribute cannot be modified..." Historically, this was only enforced when the file was opened, per the rest of the description, "... and the file can not be opened in write mode". There is general agreement that we should standardize all file systems to prevent modifications even for files that were opened at the time the immutable flag is set. Eventually, a change to enforce this at the VFS layer should be landing in mainline. Cc: stable@kernel.org Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/file.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -59,6 +59,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(s bool need_alloc = true; int err = 0; + if (unlikely(IS_IMMUTABLE(inode))) + return VM_FAULT_SIGBUS; + if (unlikely(f2fs_cp_error(sbi))) { err = -EIO; goto err; @@ -869,6 +872,14 @@ int f2fs_setattr(struct dentry *dentry, if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) return -EIO; + if (unlikely(IS_IMMUTABLE(inode))) + return -EPERM; + + if (unlikely(IS_APPEND(inode) && + (attr->ia_valid & (ATTR_MODE | ATTR_UID | + ATTR_GID | ATTR_TIMES_SET)))) + return -EPERM; + if ((attr->ia_valid & ATTR_SIZE) && !f2fs_is_compress_backend_ready(inode)) return -EOPNOTSUPP; @@ -4084,6 +4095,11 @@ static ssize_t f2fs_file_write_iter(stru inode_lock(inode); } + if (unlikely(IS_IMMUTABLE(inode))) { + ret = -EPERM; + goto unlock; + } + ret = generic_write_checks(iocb, from); if (ret > 0) { bool preallocated = false; @@ -4148,6 +4164,7 @@ write: if (ret > 0) f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret); } +unlock: inode_unlock(inode); out: trace_f2fs_file_write_iter(inode, iocb->ki_pos,