Commit beb29e058c35ab69e96e455a12ccf7505f6de425

Authored by Miklos Szeredi
Committed by Al Viro
1 parent b1da47e29e

[patch 4/4] vfs: immutable inode checking cleanup

Move the immutable and append-only checks from chmod, chown and utimes
into notify_change().  Checks for immutable and append-only files are
always performed by the VFS and not by the filesystem (see
permission() and may_...() in namei.c), so these belong in
notify_change(), and not in inode_change_ok().

This should be completely equivalent.

CC: Ulrich Drepper <drepper@redhat.com>
CC: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 3 changed files with 7 additions and 26 deletions Side-by-side Diff

... ... @@ -108,6 +108,11 @@
108 108 struct timespec now;
109 109 unsigned int ia_valid = attr->ia_valid;
110 110  
  111 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
  112 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  113 + return -EPERM;
  114 + }
  115 +
111 116 now = current_fs_time(inode->i_sb);
112 117  
113 118 attr->ia_ctime = now;
... ... @@ -588,9 +588,6 @@
588 588 err = mnt_want_write(file->f_path.mnt);
589 589 if (err)
590 590 goto out_putf;
591   - err = -EPERM;
592   - if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
593   - goto out_drop_write;
594 591 mutex_lock(&inode->i_mutex);
595 592 if (mode == (mode_t) -1)
596 593 mode = inode->i_mode;
... ... @@ -598,8 +595,6 @@
598 595 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
599 596 err = notify_change(dentry, &newattrs);
600 597 mutex_unlock(&inode->i_mutex);
601   -
602   -out_drop_write:
603 598 mnt_drop_write(file->f_path.mnt);
604 599 out_putf:
605 600 fput(file);
... ... @@ -623,11 +618,6 @@
623 618 error = mnt_want_write(nd.path.mnt);
624 619 if (error)
625 620 goto dput_and_out;
626   -
627   - error = -EPERM;
628   - if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
629   - goto out_drop_write;
630   -
631 621 mutex_lock(&inode->i_mutex);
632 622 if (mode == (mode_t) -1)
633 623 mode = inode->i_mode;
... ... @@ -635,8 +625,6 @@
635 625 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
636 626 error = notify_change(nd.path.dentry, &newattrs);
637 627 mutex_unlock(&inode->i_mutex);
638   -
639   -out_drop_write:
640 628 mnt_drop_write(nd.path.mnt);
641 629 dput_and_out:
642 630 path_put(&nd.path);
643 631  
... ... @@ -651,18 +639,10 @@
651 639  
652 640 static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
653 641 {
654   - struct inode * inode;
  642 + struct inode *inode = dentry->d_inode;
655 643 int error;
656 644 struct iattr newattrs;
657 645  
658   - error = -ENOENT;
659   - if (!(inode = dentry->d_inode)) {
660   - printk(KERN_ERR "chown_common: NULL inode\n");
661   - goto out;
662   - }
663   - error = -EPERM;
664   - if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
665   - goto out;
666 646 newattrs.ia_valid = ATTR_CTIME;
667 647 if (user != (uid_t) -1) {
668 648 newattrs.ia_valid |= ATTR_UID;
... ... @@ -678,7 +658,7 @@
678 658 mutex_lock(&inode->i_mutex);
679 659 error = notify_change(dentry, &newattrs);
680 660 mutex_unlock(&inode->i_mutex);
681   -out:
  661 +
682 662 return error;
683 663 }
684 664  
... ... @@ -64,10 +64,6 @@
64 64  
65 65 newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
66 66 if (times) {
67   - error = -EPERM;
68   - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
69   - goto mnt_drop_write_and_out;
70   -
71 67 if (times[0].tv_nsec == UTIME_OMIT)
72 68 newattrs.ia_valid &= ~ATTR_ATIME;
73 69 else if (times[0].tv_nsec != UTIME_NOW) {