Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3786734ybi; Mon, 29 Jul 2019 12:36:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwU75pXFmgqmZke1ORjm3od78PnVGhyEx0SpyjaGC44UipWJJsP3yHWT6H5tAsARfFDwZ5N X-Received: by 2002:a63:9318:: with SMTP id b24mr94749888pge.31.1564428981374; Mon, 29 Jul 2019 12:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428981; cv=none; d=google.com; s=arc-20160816; b=HJghgMK75gpW3cA/hc94rhdQu8L8rySaSKAOVZ4fPplOBhM90RGvYGDI9znON21OO9 N/FjU0HvOAxWZvDkA68MmTKXaenchz1ZVj4Eu021FkNJ3d5dvGVS73UHkSOwZF7xGjcu nBEhWv+d1vck3eyIchycUj4eH+yTJoHePwqN9vP3Rw1v5dMFftAnB5GIID4//KG0cl0p I0ktegbdBQ+P1ZdNJ7oN+j/C8x7s1RzkMzIrtd/wLnn/Rs6W9pTjfPYmv6RLjJbLS5wY h8A2bpBQHxaCxCNaxQh05d+91QVAEl+aQ6Uw6/4uw1fYnLFs7imdToCy1qqgYQd2LEwC QpMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nFGAz5FdHnXYRECdZ8UNnoBdvxF9q9NOgIGfnw9ZXeA=; b=U7PI0Z9l1iCRfZmBoQT4wlj48cszK8m0qxTD3ZszF3QWP9K99nkSKeMjP+bg9Xg3E4 29A1qQS1cufqmDJmcOR3t9Ot83hpbb4Hx8rqibnHAHTc2xPfwk+5J8xNDMVtHXazh+Nh 4vE94+OpR6e/YRtVIKuNGpK9OWI4jz0v3mKzVhYV8ZUDv8Ep5ChOgAecAWYEuvrk2NdB MdQeLBeEo9KtaXbzTlNp1ZjOvSi6E9Xd0FC1bWrhAIhZ+IKRI+GSYmvUKkj+u0Qw2sZt e2dSUhk7V//0L1c/iZUZUGBtcvtjHgcx9KdYGCkNa9LZOJrmcnmIpsupWLOkgViSGZP0 YvvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bQ4zcNCD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123si31585648pgb.374.2019.07.29.12.36.06; Mon, 29 Jul 2019 12:36:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bQ4zcNCD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388348AbfG2TeY (ORCPT + 99 others); Mon, 29 Jul 2019 15:34:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:48786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388300AbfG2TeV (ORCPT ); Mon, 29 Jul 2019 15:34:21 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 8D4A12070B; Mon, 29 Jul 2019 19:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428861; bh=JXXnD+mSNHBXC3kUYw63taAy32BnqtO0iu62oDfcaok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQ4zcNCDc8FMuTGGkrm4rMTzaTIacgEYog1U1ZUBFy/nxhlSng3oEsBlO42l0ZRd0 dbT4g2JHXfYu8z4+RhMgHyX2RAaNgd8vTWYst4pgq2rE4kQAP6RoEMGeL78jTHadEq 9p5FZtq4CrVK1tw51EBYWrgTG8w7LaU999REPifU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , "Darrick J. Wong" , stable@kernel.org Subject: [PATCH 4.14 209/293] ext4: enforce the immutable flag on open files Date: Mon, 29 Jul 2019 21:21:40 +0200 Message-Id: <20190729190840.474798256@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Theodore Ts'o commit 02b016ca7f99229ae6227e7b2fc950c4e140d74a upstream. 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. Until then, enforce this at the ext4 level to prevent xfstests generic/553 from failing. Signed-off-by: Theodore Ts'o Cc: "Darrick J. Wong" Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/file.c | 4 ++++ fs/ext4/inode.c | 11 +++++++++++ 2 files changed, 15 insertions(+) --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -163,6 +163,10 @@ static ssize_t ext4_write_checks(struct ret = generic_write_checks(iocb, from); if (ret <= 0) return ret; + + if (unlikely(IS_IMMUTABLE(inode))) + return -EPERM; + /* * If we have encountered a bitmap-format file, the size limit * is smaller than s_maxbytes, which is for extent-mapped files. --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5341,6 +5341,14 @@ int ext4_setattr(struct dentry *dentry, if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) return -EIO; + if (unlikely(IS_IMMUTABLE(inode))) + return -EPERM; + + if (unlikely(IS_APPEND(inode) && + (ia_valid & (ATTR_MODE | ATTR_UID | + ATTR_GID | ATTR_TIMES_SET)))) + return -EPERM; + error = setattr_prepare(dentry, attr); if (error) return error; @@ -6045,6 +6053,9 @@ int ext4_page_mkwrite(struct vm_fault *v get_block_t *get_block; int retries = 0; + if (unlikely(IS_IMMUTABLE(inode))) + return VM_FAULT_SIGBUS; + sb_start_pagefault(inode->i_sb); file_update_time(vma->vm_file);