diff options
author | Theodore Ts'o <tytso@mit.edu> | 2019-06-09 22:04:33 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2019-06-09 22:04:33 -0400 |
commit | 02b016ca7f99229ae6227e7b2fc950c4e140d74a (patch) | |
tree | b372e85bc1d9c11dca0d949f713723d4b6a648da /fs/ext4/inode.c | |
parent | 2e53840362771c73eb0a5ff71611507e64e8eecd (diff) | |
download | linux-02b016ca7f99229ae6227e7b2fc950c4e140d74a.tar.gz linux-02b016ca7f99229ae6227e7b2fc950c4e140d74a.tar.bz2 linux-02b016ca7f99229ae6227e7b2fc950c4e140d74a.zip |
ext4: enforce the immutable flag on open files
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
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c16071547c9c..ed1d8f9ce5f9 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5520,6 +5520,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; @@ -6194,6 +6202,9 @@ vm_fault_t 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); |