summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2019-06-09 22:04:33 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-07-31 07:28:47 +0200
commitf04a76af1e70c82cdef1036f8d3e02016a4018dd (patch)
tree4c03201e1a6d6d11cce5d941154496acd4b389fe /fs
parentefb8a11e4f61fbe4f88b3738d10cba5d223b434c (diff)
downloadlinux-stable-f04a76af1e70c82cdef1036f8d3e02016a4018dd.tar.gz
linux-stable-f04a76af1e70c82cdef1036f8d3e02016a4018dd.tar.bz2
linux-stable-f04a76af1e70c82cdef1036f8d3e02016a4018dd.zip
ext4: enforce the immutable flag on open files
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 <tytso@mit.edu> Cc: "Darrick J. Wong" <darrick.wong@oracle.com> Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/file.c4
-rw-r--r--fs/ext4/inode.c11
2 files changed, 15 insertions, 0 deletions
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 44966b272216..4ede0af9d6fe 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -163,6 +163,10 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *from)
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.
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 862766a1b080..d14cb51e6904 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5341,6 +5341,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
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 *vmf)
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);