Commit dd20908a authored by Al Viro's avatar Al Viro

don't bother with {get,put}_write_access() on non-regular files

it's pointless and actually leads to wrong behaviour in at least one
moderately convoluted case (pipe(), close one end, try to get to
another via /proc/*/fd and run into ETXTBUSY).

Cc: stable@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 44ba8406
...@@ -209,10 +209,10 @@ static void drop_file_write_access(struct file *file) ...@@ -209,10 +209,10 @@ static void drop_file_write_access(struct file *file)
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
put_write_access(inode);
if (special_file(inode->i_mode)) if (special_file(inode->i_mode))
return; return;
put_write_access(inode);
if (file_check_writeable(file) != 0) if (file_check_writeable(file) != 0)
return; return;
__mnt_drop_write(mnt); __mnt_drop_write(mnt);
......
...@@ -641,23 +641,12 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) ...@@ -641,23 +641,12 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
static inline int __get_file_write_access(struct inode *inode, static inline int __get_file_write_access(struct inode *inode,
struct vfsmount *mnt) struct vfsmount *mnt)
{ {
int error; int error = get_write_access(inode);
error = get_write_access(inode);
if (error) if (error)
return error; return error;
/*
* Do not take mount writer counts on
* special files since no writes to
* the mount itself will occur.
*/
if (!special_file(inode->i_mode)) {
/*
* Balanced in __fput()
*/
error = __mnt_want_write(mnt); error = __mnt_want_write(mnt);
if (error) if (error)
put_write_access(inode); put_write_access(inode);
}
return error; return error;
} }
...@@ -690,11 +679,10 @@ static int do_dentry_open(struct file *f, ...@@ -690,11 +679,10 @@ static int do_dentry_open(struct file *f,
path_get(&f->f_path); path_get(&f->f_path);
inode = f->f_inode = f->f_path.dentry->d_inode; inode = f->f_inode = f->f_path.dentry->d_inode;
if (f->f_mode & FMODE_WRITE) { if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
error = __get_file_write_access(inode, f->f_path.mnt); error = __get_file_write_access(inode, f->f_path.mnt);
if (error) if (error)
goto cleanup_file; goto cleanup_file;
if (!special_file(inode->i_mode))
file_take_write(f); file_take_write(f);
} }
...@@ -742,7 +730,6 @@ static int do_dentry_open(struct file *f, ...@@ -742,7 +730,6 @@ static int do_dentry_open(struct file *f,
cleanup_all: cleanup_all:
fops_put(f->f_op); fops_put(f->f_op);
if (f->f_mode & FMODE_WRITE) { if (f->f_mode & FMODE_WRITE) {
put_write_access(inode);
if (!special_file(inode->i_mode)) { if (!special_file(inode->i_mode)) {
/* /*
* We don't consider this a real * We don't consider this a real
...@@ -750,6 +737,7 @@ static int do_dentry_open(struct file *f, ...@@ -750,6 +737,7 @@ static int do_dentry_open(struct file *f,
* because it all happenend right * because it all happenend right
* here, so just reset the state. * here, so just reset the state.
*/ */
put_write_access(inode);
file_reset_write(f); file_reset_write(f);
__mnt_drop_write(f->f_path.mnt); __mnt_drop_write(f->f_path.mnt);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment