smb: client: fix in-place encryption corruption in SMB2_write()
Subsystems (3)
PATCH 1/1 smb: client: fix in-place encryption corruption in SMB2_write()
SMB2_write() places write payload in iov[1..n] as part of rq_iov. smb3_init_transform_rq() pointer-shares rq_iov, so crypt_message() encrypts iov[1] in-place, replacing the original plaintext with ciphertext. On a replayable error, the retry sends the same iov[1] which now contains ciphertext instead of the original data, resulting in corruption.
The corruption is most likely to be observed when connections are unstable, as reconnects trigger write retries that re-send the already-encrypted data.
This affects SFU mknod, MF symlinks, etc. On kernels before 6.10 (prior to the netfs conversion), sync writes also used this path and were similarly affected. The async write path wasn't unaffected as it uses rq_iter which gets deep-copied.
Fix by moving the write payload into rq_iter via iov_iter_kvec(), so smb3_init_transform_rq() deep-copies it before encryption.
--- fs/smb/client/smb2pdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/smb/client/smb2pdu.c +4 -1
@@ -5307,7 +5307,10 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,memset (&rqst,0 ,sizeof (struct smb_rqst )); rqst.rq_iov = iov; - rqst.rq_nvec = n_vec +1 ; +/* iov[0] is the SMB header; move payload to rq_iter for encryption safety */ + rqst.rq_nvec =1 ; +iov_iter_kvec (&rqst.rq_iter,ITER_SOURCE , &iov[1 ], n_vec, + io_parms->length);if (retries) {/* Back-off before retry */
Signature · 1 line
2.48.1
Quoted 43 lines · Bharath SM
SMB2_write()places write payload in iov[1..n] as part ofrq_iov.smb3_init_transform_rq()pointer-sharesrq_iov, socrypt_message()encrypts iov[1] in-place, replacing the original plaintext with ciphertext. On a replayable error, the retry sends the same iov[1] which now contains ciphertext instead of the original data, resulting in corruption.The corruption is most likely to be observed when connections are unstable, as reconnects trigger write retries that re-send the already-encrypted data.
This affects SFU mknod, MF symlinks, etc. On kernels before 6.10 (prior to the netfs conversion), sync writes also used this path and were similarly affected. The async write path wasn't unaffected as it uses
rq_iterwhich gets deep-copied.Fix by moving the write payload into
rq_iterviaiov_iter_kvec(), sosmb3_init_transform_rq()deep-copies it before encryption.Cc [email protected] #6.3+Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/smb2pdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/smb/client/smb2pdu.c +4
-2@@ -5307,7 +5307,10 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,memset (&rqst,0 ,sizeof (struct smb_rqst )); rqst.rq_iov = iov; - rqst.rq_nvec = n_vec +1 ; +/* iov[0] is the SMB header; move payload to rq_iter for encryption safety */ + rqst.rq_nvec =1 ; +iov_iter_kvec (&rqst.rq_iter,ITER_SOURCE , &iov[1 ], n_vec, + io_parms->length);if (retries) {/* Back-off before retry */ --
Quoted 3 lines
2.48.1
Looks good to me.
Signature · 2 lines
Regards, Shyam
Quoted 44 lines · Bharath SM
SMB2_write()places write payload in iov[1..n] as part ofrq_iov.smb3_init_transform_rq()pointer-sharesrq_iov, socrypt_message()encrypts iov[1] in-place, replacing the original plaintext with ciphertext. On a replayable error, the retry sends the same iov[1] which now contains ciphertext instead of the original data, resulting in corruption.The corruption is most likely to be observed when connections are unstable, as reconnects trigger write retries that re-send the already-encrypted data.
This affects SFU mknod, MF symlinks, etc. On kernels before 6.10 (prior to the netfs conversion), sync writes also used this path and were similarly affected. The async write path wasn't unaffected as it uses
rq_iterwhich gets deep-copied.Fix by moving the write payload into
rq_iterviaiov_iter_kvec(), sosmb3_init_transform_rq()deep-copies it before encryption.Cc [email protected] #6.3+Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/smb2pdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/smb/client/smb2pdu.c +4
-1@@ -5307,7 +5307,10 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,memset (&rqst,0 ,sizeof (struct smb_rqst )); rqst.rq_iov = iov; - rqst.rq_nvec = n_vec +1 ; +/* iov[0] is the SMB header; move payload to rq_iter for encryption safety */ + rqst.rq_nvec =1 ; +iov_iter_kvec (&rqst.rq_iter,ITER_SOURCE , &iov[1 ], n_vec, + io_parms->length);if (retries) {/* Back-off before retry */ Signature · 1 line
2.48.1
Steve French
Appliedmerged into cifs-2.6.git for-next
Quoted 48 lines · Henrique Carvalho
Quoted 44 lines · Bharath SM
SMB2_write()places write payload in iov[1..n] as part ofrq_iov.smb3_init_transform_rq()pointer-sharesrq_iov, socrypt_message()encrypts iov[1] in-place, replacing the original plaintext with ciphertext. On a replayable error, the retry sends the same iov[1] which now contains ciphertext instead of the original data, resulting in corruption.The corruption is most likely to be observed when connections are unstable, as reconnects trigger write retries that re-send the already-encrypted data.
This affects SFU mknod, MF symlinks, etc. On kernels before 6.10 (prior to the netfs conversion), sync writes also used this path and were similarly affected. The async write path wasn't unaffected as it uses
rq_iterwhich gets deep-copied.Fix by moving the write payload into
rq_iterviaiov_iter_kvec(), sosmb3_init_transform_rq()deep-copies it before encryption.Cc [email protected] #6.3+Signed-off-by Bharath SM <[email protected]>--- fs/smb/client/smb2pdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/smb/client/smb2pdu.c +4
-2@@ -5307,7 +5307,10 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,memset (&rqst,0 ,sizeof (struct smb_rqst )); rqst.rq_iov = iov; - rqst.rq_nvec = n_vec +1 ; +/* iov[0] is the SMB header; move payload to rq_iter for encryption safety */ + rqst.rq_nvec =1 ; +iov_iter_kvec (&rqst.rq_iter,ITER_SOURCE , &iov[1 ], n_vec, + io_parms->length);if (retries) {/* Back-off before retry */ --2.48.1
Signature · 3 lines
Thanks, Steve