Skip to content

Instantly share code, notes, and snippets.

@mokomull
Created June 18, 2013 16:50
Show Gist options
  • Save mokomull/5807128 to your computer and use it in GitHub Desktop.
Save mokomull/5807128 to your computer and use it in GitHub Desktop.
The kernel does it!
// fs/open.c
static int chown_common(struct path *path, uid_t user, gid_t group)
{
struct inode *inode = path->dentry->d_inode;
[...]
if (!S_ISDIR(inode->i_mode))
newattrs.ia_valid |=
ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
[...]
}
// fs/attr.c
int notify_change(struct dentry * dentry, struct iattr * attr)
{
[...]
unsigned int ia_valid = attr->ia_valid;
[...]
if (ia_valid & ATTR_KILL_SUID) {
if (mode & S_ISUID) {
ia_valid = attr->ia_valid |= ATTR_MODE;
attr->ia_mode = (inode->i_mode & ~S_ISUID);
}
}
if (ia_valid & ATTR_KILL_SGID) {
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
if (!(ia_valid & ATTR_MODE)) {
ia_valid = attr->ia_valid |= ATTR_MODE;
attr->ia_mode = inode->i_mode;
}
attr->ia_mode &= ~S_ISGID;
}
}
[...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment