Re: Update of file offset on write() etc. is non-atomic with I/O

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 3, 2014 at 1:45 PM, Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
>
> Um...  That's odd - we *could* get there with f.need_put and
> file_count(file) equal to 1, but why would we want to take
> f_pos_lock in that case?

Because that means that the file table is shared among threads. So
another thread can access the struct file pointer and do a concurrent
read() or write() on it, and so we need to lock f_pos.

Basically, there are two cases:

 - duplicated file pointers due to fork(). That's the "file_count()" test.

   Yes, this will trigger even if they didn't fork, just dup'ed the
file descriptor. We have no way of telling the difference, though.

 - concurrent access due to duplicated "struct file_table" pointers.
This is the "need_put" test, since __fget_light() will have tested the
proper files->count already.

Both need f_pos_lock.

               Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux