From 1efdc45ea805e61de2c54736cd1b2a4a5f48a913 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 20 Feb 2015 10:28:25 -0800 Subject: [PATCH] Fix O_APPEND open(2) flag As described in flags section of open(2): O_APPEND: The file is opened in append mode. Before each write(2), the file offset is positioned at the end of the file, as if with lseek(2). O_APPEND may lead to corrupted files on NFS filesys- tems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which can't be done without a race condition. This issue was originally overlooked because normally the generic VFS code handles this for a filesystem. However, because ZFS explictly registers a zpl_write() function it's responsible for the seek. Signed-off-by: Brian Behlendorf Closes #3124 --- module/zfs/zpl_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/zfs/zpl_file.c b/module/zfs/zpl_file.c index 5f5bbba3d..571e04315 100644 --- a/module/zfs/zpl_file.c +++ b/module/zfs/zpl_file.c @@ -272,6 +272,9 @@ zpl_write_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count, uio_t uio; int error; + if (flags & O_APPEND) + *ppos = i_size_read(ip); + uio.uio_iov = (struct iovec *)iovp; uio.uio_resid = count; uio.uio_iovcnt = nr_segs; -- 2.40.0