From: Andrew Morton Cc: Dave Hansen Cc: Christoph Hellwig Signed-off-by: Andrew Morton --- fs/namei.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff -puN fs/namei.c~r-o-bind-mounts-elevate-write-count-opened-files-oops-fix fs/namei.c --- a/fs/namei.c~r-o-bind-mounts-elevate-write-count-opened-files-oops-fix +++ a/fs/namei.c @@ -1722,7 +1722,7 @@ static inline int sys_open_flags_to_name return flag; } -static inline int open_will_write_to_fs(int flag, struct inode *inode) +static int open_will_write_to_fs(int flag, struct inode *inode) { /* * We'll never write to the fs underlying @@ -1752,6 +1752,7 @@ struct file *open_pathname(int dfd, cons struct path path; struct dentry *dir; int count = 0; + int will_write; int flag = sys_open_flags_to_namei_flags(sys_open_flag); acc_mode = ACC_MODE(flag); @@ -1870,14 +1871,15 @@ ok: * be avoided. Taking this mnt write here * ensures that (2) can not occur. */ - if (open_will_write_to_fs(flag, nd.dentry->d_inode)) { + will_write = open_will_write_to_fs(flag, nd.dentry->d_inode); + if (will_write) { error = mnt_want_write(nd.mnt); if (error) goto exit; } error = may_open(&nd, acc_mode, flag); if (error) { - if (open_will_write_to_fs(flag, nd.dentry->d_inode)) + if (will_write) mnt_drop_write(nd.mnt); goto exit; } @@ -1887,7 +1889,7 @@ ok: * because the filp has had a write taken * on its behalf. */ - if (open_will_write_to_fs(flag, nd.dentry->d_inode)) + if (will_write) mnt_drop_write(nd.mnt); return filp; _