Skip to content

Commit ca9ca1a

Browse files
dhowellsbrauner
authored andcommitted
netfs: Fix missing zero-length check in unbuffered write
Fix netfs_unbuffered_write_iter() to return immediately if generic_write_checks() returns 0, indicating there's nothing to write. Note that netfs_file_write_iter() already does this. Also, whilst we're at it, put in checks for the size being zero before we even take the locks. Note that generic_write_checks() can still reduce the size to zero, so we still need that check. Without this, a warning similar to the following is logged to dmesg: netfs: Zero-sized write [R=1b6da] and the syscall fails with EIO, e.g.: /sbin/ldconfig.real: Writing of cache extension data failed: Input/output error This can be reproduced on 9p by: xfs_io -f -c 'pwrite 0 0' /xfstest.test/foo Fixes: 153a996 ("netfs: Implement unbuffered/DIO write support") Reported-by: Eric Van Hensbergen <[email protected]> Link: https://lore.kernel.org/r/ZbQUU6QKmIftKsmo@FV7GG9FTHL/ Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Dominique Martinet <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: Dominique Martinet <[email protected]> cc: Jeff Layton <[email protected]> cc: <[email protected]> cc: <[email protected]> cc: <[email protected]> cc: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 2147caa commit ca9ca1a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

fs/netfs/buffered_write.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
477477

478478
_enter("%llx,%zx,%llx", iocb->ki_pos, iov_iter_count(from), i_size_read(inode));
479479

480+
if (!iov_iter_count(from))
481+
return 0;
482+
480483
if ((iocb->ki_flags & IOCB_DIRECT) ||
481484
test_bit(NETFS_ICTX_UNBUFFERED, &ictx->flags))
482485
return netfs_unbuffered_write_iter(iocb, from);

fs/netfs/direct_write.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,17 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)
139139

140140
_enter("%llx,%zx,%llx", iocb->ki_pos, iov_iter_count(from), i_size_read(inode));
141141

142+
if (!iov_iter_count(from))
143+
return 0;
144+
142145
trace_netfs_write_iter(iocb, from);
143146
netfs_stat(&netfs_n_rh_dio_write);
144147

145148
ret = netfs_start_io_direct(inode);
146149
if (ret < 0)
147150
return ret;
148151
ret = generic_write_checks(iocb, from);
149-
if (ret < 0)
152+
if (ret <= 0)
150153
goto out;
151154
ret = file_remove_privs(file);
152155
if (ret < 0)

0 commit comments

Comments
 (0)