From: Pavel Kankovsky <peak@argo.troja.mff.cuni.cz>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Linux kernel file offset pointer races
Date: Wed, 18 Aug 2004 13:03:25 +0200 (MET DST) [thread overview]
Message-ID: <20040818103356.6974.0@argo.troja.mff.cuni.cz> (raw)
In-Reply-To: <1092345143.22458.105.camel@localhost.localdomain>
On Thu, 12 Aug 2004, Alan Cox wrote:
> > In this scenario, the 1st and 3rd pages read by read() contain the old
> > data (before write()) but the 2nd page contains the new data (after
> > write()). This is absurd.
>
> Why ?
Ok, it is not absurd. It is insane. :)
As far as I know, POSIX compliant read() and write() et al. are
supposed to be serializable.
> > BTW: What about writev() (esp. with O_APPEND)? It appears Linux
> > implementation makes it possible to interleave parts of writev() with
> > other writes.
>
> If that can occur with O_APPEND it might be a bug. SuS does make some
> real guarantees about what O_APPEND means.
The following scenario appears to be possible when the default
implementation in do_readv_writev() is used:
1. process P1 calls writev(), writes the 1st chunk
fs specific write operation grabs i_sem when it starts...
and releases it when it finished
2. process P2 calls write() on the same file
i_sem is free now, and P2 can grab it..and release it again
3. process P1 writes the 2nd chunk
i_sem is free again, and P1 can grab it to write the 2nd chunk
The good news is some filesystems use generic_file_writev() (ext2, ext3)
or their own implementation (xfs) rather than the "supergeneric" code in
do_readv_writev(). The bad news is some other filesystems (reiser) use the
"supergeneric" code.
> > Moreover, there appears to be a race condition between locks_verify_area()
> > and the actual I/O operation(s).
>
> Details ?
When I hold a mandatory lock on a file then no other process will be
allowed to read from/write to (depending on the type of the lock) that
file, right? The code (vfs_read(), vfs_write(), do_readv_writev()) in
Linux appears to work as follows:
1. locks_verify_area() is called
2. file i/o is performed
As far as I can tell, the process holds no locks covering both steps.
Another process might call fcntl(...F_SETLK...) between steps 1 and 2,
i.e. after locks_verify_area() said "ok" but before the actual i/o is
finished, and the result would be one process doing i/o on a file
while the other process holds a mandatory lock on the same file.
--Pavel Kankovsky aka Peak [ Boycott Microsoft--http://www.vcnet.com/bms ]
"Resistance is futile. Open your source code and prepare for assimilation."
prev parent reply other threads:[~2004-08-18 11:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.44.0408041220550.26961-100000@isec.pl>
2004-08-04 20:36 ` Pavel Kankovsky
2004-08-06 12:56 ` Alan Cox
2004-08-07 12:38 ` Amon Ott
2004-08-07 13:18 ` viro
2004-08-07 16:02 ` Amon Ott
2004-08-12 21:38 ` Pavel Kankovsky
2004-08-12 21:12 ` Alan Cox
2004-08-18 11:03 ` Pavel Kankovsky [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040818103356.6974.0@argo.troja.mff.cuni.cz \
--to=peak@argo.troja.mff.cuni.cz \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®