Skip to content

Commit 9d85ac9

Browse files
dhowellssmfrench
authored andcommitted
cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB1
If a DIO read or an unbuffered read request extends beyond the EOF, the server will return a short read and a status code indicating that EOF was hit, which gets translated to -ENODATA. Note that the client does not cap the request at i_size, but asks for the amount requested in case there's a race on the server with a third party. Now, on the client side, the request will get split into multiple subrequests if rsize is smaller than the full request size. A subrequest that starts before or at the EOF and returns short data up to the EOF will be correctly handled, with the NETFS_SREQ_HIT_EOF flag being set, indicating to netfslib that we can't read more. If a subrequest, however, starts after the EOF and not at it, HIT_EOF will not be flagged, its error will be set to -ENODATA and it will be abandoned. This will cause the request as a whole to fail with -ENODATA. Fix this by setting NETFS_SREQ_HIT_EOF on any subrequest that lies beyond the EOF marker. This can be reproduced by mounting with "cache=none,sign,vers=1.0" and doing a read of a file that's significantly bigger than the size of the file (e.g. attempting to read 64KiB from a 16KiB file). Fixes: a68c748 ("cifs: Fix SMB1 readv/writev callback in the same way as SMB2/3") Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> cc: Shyam Prasad N <sprasad@microsoft.com> cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1ef15fb commit 9d85ac9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/smb/client/cifssmb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
13741374
} else {
13751375
size_t trans = rdata->subreq.transferred + rdata->got_bytes;
13761376
if (trans < rdata->subreq.len &&
1377-
rdata->subreq.start + trans == ictx->remote_i_size) {
1377+
rdata->subreq.start + trans >= ictx->remote_i_size) {
13781378
rdata->result = 0;
13791379
__set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
13801380
} else if (rdata->got_bytes > 0) {

0 commit comments

Comments
 (0)