PATCH: under pre-patch-2.1.45, open("xxx",O_WRONLY|O_CREAT,0444) gives EACCES

Kevin Buhr (buhr@stat.wisc.edu)
09 Jul 1997 17:24:03 -0500


--Multipart_Wed_Jul__9_17:24:03_1997-1
Content-Type: text/plain; charset=US-ASCII

Linus:

Under "pre-patch-2.1.45" (and vanilla 2.1.44), the "open_namei" code
in "linux/fs/namei.c" is broken for O_CREAT-ing files. If a new,
regular file is actually created, the current code continues to do a
bunch of pointless checks, including an overzealous permission check.
As a result, a call like:

open("zork", O_WRONLY|O_CREAT, 0444);

fails with an EACCES error (because the code mistakenly thinks that an
*existing* file without write permissions is being opened for
writing).

In particular, this breaks my "procmail"'s locking scheme.

The enclosed patch fixes the problem by short-circuiting the
unnecessary checks, the way the old "namei.c" did.

Kevin <buhr@stat.wisc.edu>

--Multipart_Wed_Jul__9_17:24:03_1997-1
Content-Type: application/octet-stream; type=patch
Content-Disposition: attachment; filename="namei.patch"
Content-Transfer-Encoding: 7bit

Index: linux/fs/namei.c
diff -u linux/fs/namei.c:1.1.1.2 linux/fs/namei.c:1.1.1.2.2.1
--- linux/fs/namei.c:1.1.1.2 Wed Jul 9 14:37:52 1997
+++ linux/fs/namei.c Wed Jul 9 17:10:14 1997
@@ -543,6 +543,15 @@
if (dir->i_sb && dir->i_sb->dq_op)
dir->i_sb->dq_op->initialize(dir, -1);
error = dir->i_op->create(dir, dentry, mode);
+ if (!error) {
+ inode = dentry->d_inode;
+ if (flag & FMODE_WRITE)
+ if (inode->i_sb && inode->i_sb->dq_op)
+ inode->i_sb->dq_op->initialize(inode, -1);
+ up(&dir->i_sem);
+ iput(dir);
+ goto create_okay;
+ }
}
up(&dir->i_sem);
iput(dir);
@@ -611,9 +620,11 @@
if (inode->i_sb && inode->i_sb->dq_op)
inode->i_sb->dq_op->initialize(inode, -1);

+ error = 0;
+
+create_okay:
*res_inode = inode;
atomic_inc(&inode->i_count);
- error = 0;

exit:
dput(dentry);

--Multipart_Wed_Jul__9_17:24:03_1997-1--