[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <45F09F9C.4030801@cosmosbay.com>
Date: Fri, 09 Mar 2007 00:43:24 +0100
From: Eric Dumazet <dada1@...mosbay.com>
To: "Michael K. Edwards" <medwards.linux@...il.com>
CC: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: sys_write() racy for multi-threaded append?
Michael K. Edwards a écrit :
> from sys_write():
>
> file = fget_light(fd, &fput_needed);
> if (file) {
> loff_t pos = file_pos_read(file);
> ret = vfs_write(file, buf, count, &pos);
> file_pos_write(file, pos);
> fput_light(file, fput_needed);
> }
>
> Surely that's racy when two threads write to the same fd and the first
> vfs_write call blocks or is preempted. Or does fget_light take some
> per-file lock that I'm not seeing?
Nothing in the manuals says that write() on same fd should be non racy : In
particular file pos might be undefined. There is a reason pwrite() exists.
Kernel doesnt have to enforce thread safety as standard is quite clear.
Only O_APPEND case is specially handled (and NFS might fail to handle this
case correctly)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists