]> git.hungrycats.org Git - linux/commitdiff
vfs: export check_sticky()
authorMiklos Szeredi <mszeredi@suse.cz>
Thu, 23 Oct 2014 22:14:36 +0000 (00:14 +0200)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Sun, 14 Dec 2014 03:32:55 +0000 (22:32 -0500)
It's already duplicated in btrfs and about to be used in overlayfs too.

Move the sticky bit check to an inline helper and call the out-of-line
helper only in the unlikly case of the sticky bit being set.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
(cherry picked from commit cbdf35bcb833bfd00f0925d7a9a33a21f41ea582)

fs/btrfs/ioctl.c
fs/namei.c
include/linux/fs.h

index 33c80f560f98d17a4de320c910f3f9ec7be25478..a01fa97595ff0016caa33630e63d3bf4cd7c9f93 100644 (file)
@@ -765,23 +765,6 @@ out:
        return ret;
 }
 
-/*  copy of check_sticky in fs/namei.c()
-* It's inline, so penalty for filesystems that don't use sticky bit is
-* minimal.
-*/
-static inline int btrfs_check_sticky(struct inode *dir, struct inode *inode)
-{
-       kuid_t fsuid = current_fsuid();
-
-       if (!(dir->i_mode & S_ISVTX))
-               return 0;
-       if (uid_eq(inode->i_uid, fsuid))
-               return 0;
-       if (uid_eq(dir->i_uid, fsuid))
-               return 0;
-       return !capable(CAP_FOWNER);
-}
-
 /*  copy of may_delete in fs/namei.c()
  *     Check whether we can remove a link victim from directory dir, check
  *  whether the type of victim is right.
@@ -817,8 +800,7 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)
                return error;
        if (IS_APPEND(dir))
                return -EPERM;
-       if (btrfs_check_sticky(dir, victim->d_inode)||
-               IS_APPEND(victim->d_inode)||
+       if (check_sticky(dir, victim->d_inode) || IS_APPEND(victim->d_inode) ||
            IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
                return -EPERM;
        if (isdir) {
index bb02687272d71dac49b791c2b77a0665cb99ca83..6ecc37cc132acaf8d6b41dfd3efe7f3514833888 100644 (file)
@@ -2382,22 +2382,17 @@ kern_path_mountpoint(int dfd, const char *name, struct path *path,
 }
 EXPORT_SYMBOL(kern_path_mountpoint);
 
-/*
- * It's inline, so penalty for filesystems that don't use sticky bit is
- * minimal.
- */
-static inline int check_sticky(struct inode *dir, struct inode *inode)
+int __check_sticky(struct inode *dir, struct inode *inode)
 {
        kuid_t fsuid = current_fsuid();
 
-       if (!(dir->i_mode & S_ISVTX))
-               return 0;
        if (uid_eq(inode->i_uid, fsuid))
                return 0;
        if (uid_eq(dir->i_uid, fsuid))
                return 0;
        return !capable_wrt_inode_uidgid(inode, CAP_FOWNER);
 }
+EXPORT_SYMBOL(__check_sticky);
 
 /*
  *     Check whether we can remove a link victim from directory dir, check
index 94187721ad412c6c8da4b44e946d24ecd240beb0..6a5a9f30f391ccbbce561d7ad0a836ec1db301b1 100644 (file)
@@ -2271,6 +2271,7 @@ extern sector_t bmap(struct inode *, sector_t);
 extern int notify_change(struct dentry *, struct iattr *, struct inode **);
 extern int inode_permission(struct inode *, int);
 extern int generic_permission(struct inode *, int);
+extern int __check_sticky(struct inode *dir, struct inode *inode);
 
 static inline bool execute_ok(struct inode *inode)
 {
@@ -2753,6 +2754,14 @@ static inline int is_sxid(umode_t mode)
        return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
 }
 
+static inline int check_sticky(struct inode *dir, struct inode *inode)
+{
+       if (!(dir->i_mode & S_ISVTX))
+               return 0;
+
+       return __check_sticky(dir, inode);
+}
+
 static inline void inode_has_no_xattr(struct inode *inode)
 {
        if (!is_sxid(inode->i_mode) && (inode->i_sb->s_flags & MS_NOSEC))