mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: lsorense@csclub.uwaterloo.ca (Lennart Sorensen)
To: Pavel Machek <pavel@ucw.cz>
Cc: Jan Kara <jack@suse.cz>, Bodo Eggert <7eggert@gmx.de>,
	Diego Calleja <diegocg@gmail.com>, Jiri Kosina <jkosina@suse.cz>,
	Michal Hocko <mhocko@suse.cz>, Meelis Roos <mroos@linux.ee>,
	Linux Kernel list <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: file offset corruption on 32-bit machines?
Date: Tue, 15 Apr 2008 15:49:22 -0400	[thread overview]
Message-ID: <20080415194922.GT7385@csclub.uwaterloo.ca> (raw)
In-Reply-To: <20080415191238.GC4994@elf.ucw.cz>

On Tue, Apr 15, 2008 at 09:12:38PM +0200, Pavel Machek wrote:
> It does not say "repositions the offset to the random number" nor
> "under certain conditions repositions the offsets" nor "it repositions
> the offset unless you are unlucky and hit kernel race". More
> seriously, it does not contain note "not safe from multithreaded
> programs" nor "multithreaded behaviour is undefined".

And if you debug it on a 64bit system then it won't be able to do that.
So not exactly a useful thing to try, and even trying 1000 times you are
unlikely to hit it, so you can't know for sure unless you happen to be
lucky and hit it.

> So this pretty clearly is application bug.

> Really? I see an application to detecting if I'm being debugged. Try
> to hit the race 1000 times, if you hit it, you are probably not
> debugged (because debugger would be very likely to make that race hard
> to hit). Will only work on multicores, but...

If lseek not being atomic breaks your application, then your application
would be broken already.  Any weird debug detection you might be able to
do using the fact is isn't atomic could I suppose be considered a kernel
bug if you think being able to do such detection is a bug.  Nothing
prevents the debuger from preloading an override to the access to lseek
that uses it's own locks to make the call atomic and hence prevent such
use.

So other than that, is there any case in which lseek being not atomic
can cause an application to break if it wasn't already broken (due to
having a race condition by trying to do 2 or more seeks on the same file
handle at the same time)?  If not, I think adding any kind of locking to
seek in the kernel (which would I think have to cause a slight slow
down) is a bad move.  But hey that's just my opinion. :)  I won't be
upset either way.

> [Plus, there's "strace seen it writing to either offset A or offset B,
> but I see the data at offset C, WTF?]

Most likely it would also be a program where you see it randomly seek to
A and write or seek to A then B then write depending on how it happens
to get scheduled when you run it.  Already the program is clearly doing
something unreliable.  And C only happens to vary from B if A and B
differ in the upper 32 bits of the file position.

> I'm not saying this kernel bug is likely to hit in practice. It is
> still a kernel bug.
> 
> Is the slowdown of lseek worth getting rid of this minor bug? Not
> sure, probably yes.

I think a slow down is the worse choice.  Adding a note to the
documentation saying that "By the way, on 32bit systems the seek call is
not atomic for 64bit file offsets, so if you happen to issue two at the
same time to the same file pointer to offsets that differ in the upper
32bits, then the result of the seek might not be either of A or B but
will contain the upper 32bits of either A or B and the lower 32bits of
ether A or B.  You should of course use locking for your file access to
ensure you know where your threads end up writing so this should be a
non issue."

-- 
Len Sorensen

  reply	other threads:[~2008-04-15 19:49 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <agh4d-6yc-35@gated-at.bofh.it>
     [not found] ` <ah5tY-3lR-7@gated-at.bofh.it>
     [not found]   ` <ah5DA-3X9-9@gated-at.bofh.it>
     [not found]     ` <ah5X5-4tl-13@gated-at.bofh.it>
     [not found]       ` <ah66A-4Nk-7@gated-at.bofh.it>
     [not found]         ` <ah7vN-7Wz-9@gated-at.bofh.it>
2008-04-11 12:24           ` Bodo Eggert
2008-04-11 13:55             ` Lennart Sorensen
2008-04-11 16:59               ` Bryan Henderson
2008-04-11 17:15                 ` Lennart Sorensen
2008-04-11 21:29                   ` Bryan Henderson
2008-04-12  8:48                   ` Pavel Machek
2008-04-14 16:20               ` Jan Kara
2008-04-14 16:22                 ` Lennart Sorensen
2008-04-14 16:53                   ` Jan Kara
2008-04-14 16:54                     ` Alan Cox
2008-04-14 18:34                       ` Alexey Dobriyan
2008-04-14 17:06                     ` Lennart Sorensen
2008-04-14 19:03                       ` Jan Kara
2008-04-14 19:29                         ` Lennart Sorensen
2008-04-14 19:42                           ` Jan Kara
2008-04-14 19:45                             ` Lennart Sorensen
2008-04-15  8:57                           ` Pavel Machek
2008-04-15 15:32                             ` Lennart Sorensen
2008-04-15 17:34                               ` Pavel Machek
2008-04-15 18:24                                 ` Lennart Sorensen
2008-04-15 19:12                                   ` Pavel Machek
2008-04-15 19:49                                     ` Lennart Sorensen [this message]
2008-04-15 20:06                                       ` Pavel Machek
2008-04-15 20:28                                         ` Peter Zijlstra
2008-04-16  8:15                                           ` Pavel Machek
2008-04-16  8:20                                             ` Peter Zijlstra
2008-04-16 10:54                                             ` Alan Cox
2008-04-16 13:57                                             ` Lennart Sorensen
2008-04-15 20:29                                         ` Lennart Sorensen
2008-04-15 22:11                                           ` Bryan Henderson
2008-04-16  9:40                                             ` Jamie Lokier
2008-04-08  8:05 Meelis Roos
2008-04-10 13:55 ` Michal Hocko
2008-04-10 14:01   ` Jiri Kosina
2008-04-10 14:27     ` Jan Kara
2008-04-10 14:31       ` Jiri Kosina
2008-04-10 14:48         ` Matthew Wilcox
2008-04-10 15:22           ` Jan Kara
2008-04-10 15:30             ` Matthew Wilcox
2008-04-10 15:19         ` Jan Kara
2008-04-10 15:37           ` Michal Hocko
2008-04-10 15:56             ` Jan Kara
2008-04-10 16:03         ` Diego Calleja
2008-04-10 16:15           ` Jan Kara
2008-04-11 19:26       ` Pavel Machek
2008-04-14 16:25         ` Jan Kara
2008-04-10 14:31     ` Michal Hocko
2008-04-10 14:35       ` Jiri Kosina
2008-04-10 14:11   ` Martin Mares
2008-04-10 15:12     ` Jan Kara
2008-04-10 15:14     ` Jamie Lokier
2008-04-10 15:21       ` Matthew Wilcox
2008-04-10 15:28       ` Jan Kara
2008-04-10 15:33   ` Andi Kleen

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=20080415194922.GT7385@csclub.uwaterloo.ca \
    --to=lsorense@csclub.uwaterloo.ca \
    --cc=7eggert@gmx.de \
    --cc=diegocg@gmail.com \
    --cc=jack@suse.cz \
    --cc=jkosina@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=mroos@linux.ee \
    --cc=pavel@ucw.cz \
    /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®