From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Jeff Layton <jlayton@redhat.com>
Cc: mtk.manpages@gmail.com,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
Neil Brown <neilb@suse.de>, Theodore T'so <tytso@mit.edu>,
Christoph Hellwig <hch@infradead.org>,
Andy Lutomirski <luto@amacapital.net>
Subject: Re: Status of fcntl() mandatory locking
Date: Tue, 29 Apr 2014 07:21:42 +0200 [thread overview]
Message-ID: <535F36E6.80606@gmail.com> (raw)
In-Reply-To: <20140428060757.3127a3c7@tlielax.poochiereds.net>
On 04/28/2014 12:07 PM, Jeff Layton wrote:
> On Sun, 27 Apr 2014 17:35:52 +0200
> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> wrote:
>
>> Hello all,
>>
>> For a long time now, the fcntl(2) man page has carried this text
>> regarding mandatory (byte-range) locking:
>>
>>
>> Mandatory locking
>> The implementation of mandatory locking in all known versions
>> of Linux is subject to race conditions which render it unreli‐
>> able: a write(2) call that overlaps with a lock may modify data
>> after the mandatory lock is acquired; a read(2) call that over‐
>> laps with a lock may detect changes to data that were made only
>> after a write lock was acquired. Similar races exist between
>> mandatory locks and mmap(2). It is therefore inadvisable to
>> rely on mandatory locking.
>>
>> I wanted to check: does it remain true with modern kernels that mandatory
>> locking is unreliable? If things have changed, an uopdate to the man page
>> is obviously in order.
>>
>> Cheers,
>>
>> Michael
>>
>>
>
> Yes, it's still unreliable in modern kernels for the same reasons. The
> basic problem is that another task can race in and grab a lock after
> you check for it but before you do the I/O.
>
> FWIW, this probably fixable if someone is motivated enough to do so.
> You could have reads and writes set an implicit lock on the file
> that isn't merged with existing locks. Doing that with mmap might be
> "interesting" though.
Thanks for the confirmation, Jeff.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2014-04-29 5:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-27 15:35 Status of fcntl() mandatory locking Michael Kerrisk (man-pages)
2014-04-28 10:07 ` Jeff Layton
2014-04-29 5:21 ` Michael Kerrisk (man-pages) [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=535F36E6.80606@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=hch@infradead.org \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=neilb@suse.de \
--cc=tytso@mit.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.