From: Michal Hocko Subject: Re: file offset corruption on 32-bit machines? Date: Thu, 10 Apr 2008 15:55:58 +0200 Message-ID: <200804101555.58643.mhocko@suse.cz> References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: Linux Kernel list , linux-fsdevel@vger.kernel.org To: Meelis Roos Return-path: Received: from styx.suse.cz ([82.119.242.94]:49587 "EHLO mail.suse.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755248AbYDJN4D (ORCPT ); Thu, 10 Apr 2008 09:56:03 -0400 In-Reply-To: Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: [Adding fsdevel list] On Tuesday 08 April 2008 10:05:47 am Meelis Roos wrote: > Jeff Robertson analyzes the behaviour of different operating systems' > 64-bit file offset implementation and concludes that on 32-bit > machines, Linux and Solaris lack any locking to keep the two 32-bit > halves in sync and this could cause rare file offset corruption. > > http://jeffr-tech.livejournal.com/21014.html AFAICS, this race is theoretically possible, but it is very hard (almost impossible) to trigger with a sane file usage pattern. Note that you have to access shared struct file (same file descriptor) in different threads which should be synchronized by caller anyway (*). I also don't see any security implications from this race, but maybe someone with more knowlage about fs can see (f_pos is used at many places in the kernel code). I think that it is better to live with tiny-race-on-broken-patterns rather than paying for synchronization which is not needed for correct paths. [*] file_pos_{read,write} (fs/read_write.c) are not called under lock (in sys_read, sys_write, ...), so even if f_pos is written atomically, you will be able to get races when accessing shared descriptor from different threads. I think that POSIX states, that behavior is undefined under these conditions. Best regards -- Michal Hocko SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic