Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 252733
b: refs/heads/master
c: 69b4573
h: refs/heads/master
i:
  252731: f25320b
v: v3
  • Loading branch information
Andi Kleen authored and Al Viro committed May 28, 2011
1 parent e538340 commit dcde8d4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d76ee18a8551e33ad7dbd55cac38bc7b094f3abb
refs/heads/master: 69b4573296469fd3f70cf7044693074980517067
7 changes: 7 additions & 0 deletions trunk/fs/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
return -EPERM;
}

if ((ia_valid & ATTR_MODE)) {
mode_t amode = attr->ia_mode;
/* Flag setting protected by i_mutex */
if (is_sxid(amode))
inode->i_flags &= ~S_NOSEC;
}

now = current_fs_time(inode->i_sb);

attr->ia_ctime = now;
Expand Down
7 changes: 5 additions & 2 deletions trunk/fs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
{
struct inode *inode = dentry->d_inode;
int error = -EOPNOTSUPP;
int issec = !strncmp(name, XATTR_SECURITY_PREFIX,
XATTR_SECURITY_PREFIX_LEN);

if (issec)
inode->i_flags &= ~S_NOSEC;
if (inode->i_op->setxattr) {
error = inode->i_op->setxattr(dentry, name, value, size, flags);
if (!error) {
fsnotify_xattr(dentry);
security_inode_post_setxattr(dentry, name, value,
size, flags);
}
} else if (!strncmp(name, XATTR_SECURITY_PREFIX,
XATTR_SECURITY_PREFIX_LEN)) {
} else if (issec) {
const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
error = security_inode_setsecurity(inode, suffix, value,
size, flags);
Expand Down
13 changes: 13 additions & 0 deletions trunk/include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ struct inodes_stat_t {
#define S_PRIVATE 512 /* Inode is fs-internal */
#define S_IMA 1024 /* Inode has an associated IMA struct */
#define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
#define S_NOSEC 4096 /* no suid or xattr security attributes */

/*
* Note that nosuid etc flags are inode-specific: setting some file-system
Expand Down Expand Up @@ -273,6 +274,7 @@ struct inodes_stat_t {
#define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
#define IS_IMA(inode) ((inode)->i_flags & S_IMA)
#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)

/* the read-only stuff doesn't really belong here, but any other place is
probably as bad and I don't want to create yet another include file. */
Expand Down Expand Up @@ -2582,5 +2584,16 @@ int __init get_filesystem_list(char *buf);
#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \
(flag & __FMODE_NONOTIFY)))

static inline int is_sxid(mode_t mode)
{
return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
}

static inline void inode_has_no_xattr(struct inode *inode)
{
if (!is_sxid(inode->i_mode))
inode->i_flags |= S_NOSEC;
}

#endif /* __KERNEL__ */
#endif /* _LINUX_FS_H */
14 changes: 12 additions & 2 deletions trunk/mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1982,16 +1982,26 @@ static int __remove_suid(struct dentry *dentry, int kill)
int file_remove_suid(struct file *file)
{
struct dentry *dentry = file->f_path.dentry;
int killsuid = should_remove_suid(dentry);
int killpriv = security_inode_need_killpriv(dentry);
struct inode *inode = dentry->d_inode;
int killsuid;
int killpriv;
int error = 0;

/* Fast path for nothing security related */
if (IS_NOSEC(inode))
return 0;

killsuid = should_remove_suid(dentry);
killpriv = security_inode_need_killpriv(dentry);

if (killpriv < 0)
return killpriv;
if (killpriv)
error = security_inode_killpriv(dentry);
if (!error && killsuid)
error = __remove_suid(dentry, killsuid);
if (!error)
inode->i_flags |= S_NOSEC;

return error;
}
Expand Down

0 comments on commit dcde8d4

Please sign in to comment.