home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!mips!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.unix.internals
- Subject: Re: Problems with fsync(2) in SunOS
- Keywords: fsync EACCES
- Message-ID: <15bpnkINNhim@early-bird.think.com>
- Date: 31 Jul 92 16:28:36 GMT
- References: <1089@krabat.marco.de>
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 55
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1089@krabat.marco.de> leo@krabat.marco.de (Matthias Pfaller) writes:
- >main(argc, argv)
- >int argc; char **argv;
- >{
- > int fd;
- > char b[80];
- >
- > if ((fd = open(argv[1], O_WRONLY|O_CREAT, 0666)) < 0) {
- > perror("open");
- > exit(1);
- > }
- >
- > if (fchmod(fd, 0444))
- > perror("fchmod");
- >
- > sprintf(b, "su root -c '/etc/chown bin %s'", argv[1]);
- > system(b);
- >
- > if (write(fd, "hallo\n", 6) != 6)
- > perror("write");
- > if (fsync(fd))
- > perror("fsync");
- > if (close(fd))
- > perror("close");
- > exit(0);
- >}
-
- The error actually occurred because of the write(2). But since writes are
- buffered up in the kernel, you don't find out about the error until you
- call fsync(2) or close(2).
-
- This problem is due to the statelessness of NFS. For UFS, access is only
- checked when you open a file, and the allowable access modes are stored in
- the process's file table; after that, you can change the file modes, change
- the owner, even delete the file, and still write to the file.
-
- The NFS protocol doesn't have the concept of an "open file"; each read or
- write to the object is independent. Therefore, the server checks access on
- each operation. In this case, when it received the WRITE request, it sees
- that you don't have write access, and returns an error.
-
- You may be wondering why the chown is necessary to demontrate this problem.
- Well, there's a kludge that exists mainly because of programs that do a
- fchmod(3) after they open a file. If the write request comes from the
- file's owner, the NFS server always permits it. This isn't really a
- security violation, since the owner has the ability to change the
- permission if he wants to. It generally doesn't cause problems because
- most clients also do access checking when they open a file, so they'll
- return an error from open(2) if you ask for write access when you don't
- have it.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-