Skip to content

Commit

Permalink
fs: file_remove_privs_flags()
Browse files Browse the repository at this point in the history
Rename and export __file_remove_privs(); for a buffered write path that
doesn't take the inode lock we need to be able to check if the operation
needs to do work first.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Kent Overstreet committed Mar 14, 2024
1 parent 7efa287 commit 66a67c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ static int __remove_privs(struct mnt_idmap *idmap,
return notify_change(idmap, dentry, &newattrs, NULL);
}

static int __file_remove_privs(struct file *file, unsigned int flags)
int file_remove_privs_flags(struct file *file, unsigned int flags)
{
struct dentry *dentry = file_dentry(file);
struct inode *inode = file_inode(file);
Expand All @@ -2056,6 +2056,7 @@ static int __file_remove_privs(struct file *file, unsigned int flags)
inode_has_no_xattr(inode);
return error;
}
EXPORT_SYMBOL_GPL(file_remove_privs_flags);

/**
* file_remove_privs - remove special file privileges (suid, capabilities)
Expand All @@ -2068,7 +2069,7 @@ static int __file_remove_privs(struct file *file, unsigned int flags)
*/
int file_remove_privs(struct file *file)
{
return __file_remove_privs(file, 0);
return file_remove_privs_flags(file, 0);
}
EXPORT_SYMBOL(file_remove_privs);

Expand Down Expand Up @@ -2161,7 +2162,7 @@ static int file_modified_flags(struct file *file, int flags)
* Clear the security bits if the process is not being run by root.
* This keeps people from modifying setuid and setgid binaries.
*/
ret = __file_remove_privs(file, flags);
ret = file_remove_privs_flags(file, flags);
if (ret)
return ret;

Expand Down
1 change: 1 addition & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3004,6 +3004,7 @@ extern struct inode *new_inode_pseudo(struct super_block *sb);
extern struct inode *new_inode(struct super_block *sb);
extern void free_inode_nonrcu(struct inode *inode);
extern int setattr_should_drop_suidgid(struct mnt_idmap *, struct inode *);
extern int file_remove_privs_flags(struct file *file, unsigned int flags);
extern int file_remove_privs(struct file *);
int setattr_should_drop_sgid(struct mnt_idmap *idmap,
const struct inode *inode);
Expand Down

0 comments on commit 66a67c8

Please sign in to comment.