diff options
author | Cong Wang <xiyou.wangcong@gmail.com> | 2012-05-15 02:57:33 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-05-30 21:04:52 -0400 |
commit | 3ed37648e1cbf1bbebc200c6ea8fd8daf8325843 (patch) | |
tree | 60f27fc77a1e5c9c48790243266367318a3267dc /mm | |
parent | 8bdc81c5069e43755d6e59e5e990e21ca200e8e2 (diff) |
fs: move file_remove_suid() to fs/inode.c
file_remove_suid() is a generic function operates on struct file,
it almost has no relations with file mapping, so move it to fs/inode.c.
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/filemap.c | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index 79c4b2b0b14e..21e5abfbcdf6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c | |||
@@ -1938,71 +1938,6 @@ struct page *read_cache_page(struct address_space *mapping, | |||
1938 | } | 1938 | } |
1939 | EXPORT_SYMBOL(read_cache_page); | 1939 | EXPORT_SYMBOL(read_cache_page); |
1940 | 1940 | ||
1941 | /* | ||
1942 | * The logic we want is | ||
1943 | * | ||
1944 | * if suid or (sgid and xgrp) | ||
1945 | * remove privs | ||
1946 | */ | ||
1947 | int should_remove_suid(struct dentry *dentry) | ||
1948 | { | ||
1949 | umode_t mode = dentry->d_inode->i_mode; | ||
1950 | int kill = 0; | ||
1951 | |||
1952 | /* suid always must be killed */ | ||
1953 | if (unlikely(mode & S_ISUID)) | ||
1954 | kill = ATTR_KILL_SUID; | ||
1955 | |||
1956 | /* | ||
1957 | * sgid without any exec bits is just a mandatory locking mark; leave | ||
1958 | * it alone. If some exec bits are set, it's a real sgid; kill it. | ||
1959 | */ | ||
1960 | if (unlikely((mode & S_ISGID) && (mode & S_IXGRP))) | ||
1961 | kill |= ATTR_KILL_SGID; | ||
1962 | |||
1963 | if (unlikely(kill && !capable(CAP_FSETID) && S_ISREG(mode))) | ||
1964 | return kill; | ||
1965 | |||
1966 | return 0; | ||
1967 | } | ||
1968 | EXPORT_SYMBOL(should_remove_suid); | ||
1969 | |||
1970 | static int __remove_suid(struct dentry *dentry, int kill) | ||
1971 | { | ||
1972 | struct iattr newattrs; | ||
1973 | |||
1974 | newattrs.ia_valid = ATTR_FORCE | kill; | ||
1975 | return notify_change(dentry, &newattrs); | ||
1976 | } | ||
1977 | |||
1978 | int file_remove_suid(struct file *file) | ||
1979 | { | ||
1980 | struct dentry *dentry = file->f_path.dentry; | ||
1981 | struct inode *inode = dentry->d_inode; | ||
1982 | int killsuid; | ||
1983 | int killpriv; | ||
1984 | int error = 0; | ||
1985 | |||
1986 | /* Fast path for nothing security related */ | ||
1987 | if (IS_NOSEC(inode)) | ||
1988 | return 0; | ||
1989 | |||
1990 | killsuid = should_remove_suid(dentry); | ||
1991 | killpriv = security_inode_need_killpriv(dentry); | ||
1992 | |||
1993 | if (killpriv < 0) | ||
1994 | return killpriv; | ||
1995 | if (killpriv) | ||
1996 | error = security_inode_killpriv(dentry); | ||
1997 | if (!error && killsuid) | ||
1998 | error = __remove_suid(dentry, killsuid); | ||
1999 | if (!error && (inode->i_sb->s_flags & MS_NOSEC)) | ||
2000 | inode->i_flags |= S_NOSEC; | ||
2001 | |||
2002 | return error; | ||
2003 | } | ||
2004 | EXPORT_SYMBOL(file_remove_suid); | ||
2005 | |||
2006 | static size_t __iovec_copy_from_user_inatomic(char *vaddr, | 1941 | static size_t __iovec_copy_from_user_inatomic(char *vaddr, |
2007 | const struct iovec *iov, size_t base, size_t bytes) | 1942 | const struct iovec *iov, size_t base, size_t bytes) |
2008 | { | 1943 | { |