cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB1
Subsystems (5)
David Howells
maintainerPATCH 1/1 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).
--- fs/smb/client/cifssmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
@@ -1395,7 +1395,7 @@ cifs_readv_callback(struct mid_q_entry *mid) }else {size_t trans = rdata->subreq.transferred + rdata->got_bytes;if (trans < rdata->subreq.len && - rdata->subreq.start + trans == ictx->remote_i_size) { + rdata->subreq.start + trans >= ictx->remote_i_size) { rdata->result =0 ;__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); }else if (rdata->got_bytes >0 ) {
kernel test robot
build botFYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1
Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH] cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB1
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 24 lines · David Howells
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 ati_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_EOFflag being set, indicating to netfslib that we can't read more.If a subrequest, however, starts after the EOF and not at it,
HIT_EOFwill not be flagged, its error will be set to-ENODATAand it will be abandoned. This will cause the request as a whole to fail with-ENODATA.Fix this by setting
NETFS_SREQ_HIT_EOFon 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).
Quoted 8 lines
Fixes a68c74865f51 ("cifs: Fix SMB1 readv/writev callback in the same way as SMB2/3")Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>
Dave, looks like we're missing a similar fix for smb2_readv_callback() as well.
Can you handle it?
Thanks.
Quoted 36 lines · Paulo Alcantara
Quoted 24 lines · David Howells
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 ati_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_EOFflag being set, indicating to netfslib that we can't read more.If a subrequest, however, starts after the EOF and not at it,
HIT_EOFwill not be flagged, its error will be set to-ENODATAand it will be abandoned. This will cause the request as a whole to fail with-ENODATA.Fix this by setting
NETFS_SREQ_HIT_EOFon 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).
Quoted 8 lines
Fixes a68c74865f51 ("cifs: Fix SMB1 readv/writev callback in the same way as SMB2/3")Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>
Quoted 6 lines
Reviewed-by Paulo Alcantara (Red Hat) <[email protected]>Dave, looks like we're missing a similar fix for
smb2_readv_callback()as well.Can you handle it?
Any luck reproducing it for smb2/smb3/smb3.1.1?
Signature · 3 lines
Thanks, Steve
David Howells
maintainerQuoted 2 lines · Paulo Alcantara
Dave, looks like we're missing a similar fix for
smb2_readv_callback()as well.
I couldn't reproduce the problem with smb2/3, but it's probably worth fixing by analogy.
David
Paulo,
Added your reviewed by to David's patches but wanted to doublecheck that I didn't apply it to too many of them since I couldn't find one of your notes
Does this look ok for your RB on all 14 of these - or just the SMB1 one one?
a6fd899da60f (HEAD -> for-next, origin/for-next, origin/HEAD) cifs:
Remove dead function prototypes1b7270c879f5 smb: server: defer the initial recv completion logic to smb_direct_negotiate_recv_work()9d095775a0cb smb: server: initialize recv_io->cqe.done = recv_done just once 667246dbce2d smb: smbdirect: introduce smbdirect_socket.connect.{lock,work} 2b4e375e4006 cifs: Do some preparation prior to organising the function declarationsc3bdaf3afd87 cifs: Add a tracepoint to log EIO errors cb416ff96b83 cifs: Don't need state locking in smb2_get_mid_entry() a64fa1835237 cifs: Remove the server pointer from smb_message 960cd2e1e28a cifs: Fix specification of function pointers 2fdd780130d1 cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flagsbb8172e800b3 cifs: Clean up some places where an extra kvec[] was required for rfc100241daa3d4a238 cifs: Make smb1's SendReceive() wrap cifs_send_recv() 3ed72b50d276 cifs: Remove the RFC1002 header from smb_hdr 271b1138e8b4 cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB1
Quoted 36 lines · Paulo Alcantara
Quoted 24 lines · David Howells
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 ati_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_EOFflag being set, indicating to netfslib that we can't read more.If a subrequest, however, starts after the EOF and not at it,
HIT_EOFwill not be flagged, its error will be set to-ENODATAand it will be abandoned. This will cause the request as a whole to fail with-ENODATA.Fix this by setting
NETFS_SREQ_HIT_EOFon 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).
Quoted 8 lines
Fixes a68c74865f51 ("cifs: Fix SMB1 readv/writev callback in the same way as SMB2/3")Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>
Quoted 9 lines
Reviewed-by Paulo Alcantara (Red Hat) <[email protected]>Dave, looks like we're missing a similar fix for
smb2_readv_callback()as well.Can you handle it?
Thanks.
--
Thanks,
Steve
Paulo Alcantara
maintainerQuoted 6 lines · Steve French
Paulo,
Added your reviewed by to David's patches but wanted to doublecheck that I didn't apply it to too many of them since I couldn't find one of your notesDoes this look ok for your RB on all 14 of these - or just the SMB1 one one?
I'd reviewed and discussed the other 14 patches with Dave already, so please keep my R-b on all of them.
David Howells
maintainerPATCH 1/1 cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB2
In reply to David HowellsIf 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.
--- fs/smb/client/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2pdu.c +1 -1
@@ -4656,7 +4656,7 @@ smb2_readv_callback(struct mid_q_entry *mid) }else {size_t trans = rdata->subreq.transferred + rdata->got_bytes;if (trans < rdata->subreq.len && - rdata->subreq.start + trans == ictx->remote_i_size) { + rdata->subreq.start + trans >= ictx->remote_i_size) {__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); rdata->result =0 ; }
Re: [PATCH] cifs: Fix handling of a beyond-EOF DIO/unbuffered read over SMB2
Quoted 19 lines · David Howells
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 ati_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_EOFflag being set, indicating to netfslib that we can't read more.If a subrequest, however, starts after the EOF and not at it,
HIT_EOFwill not be flagged, its error will be set to-ENODATAand it will be abandoned. This will cause the request as a whole to fail with-ENODATA.Fix this by setting
NETFS_SREQ_HIT_EOFon any subrequest that lies beyond the EOF marker.
Quoted 8 lines
Fixes 1da29f2c39b6 ("netfs, cifs: Fix handling of short DIO read")Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>