public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smb: client: fix in-place encryption corruption in SMB2_write()
@ 2026-03-09 10:30 Bharath SM
  2026-03-09 12:43 ` Shyam Prasad N
  2026-03-09 15:51 ` Henrique Carvalho
  0 siblings, 2 replies; 4+ messages in thread
From: Bharath SM @ 2026-03-09 10:30 UTC (permalink / raw)
  To: linux-cifs, smfrench, dhowells, sprasad, pc, ematsumiya,
	henrique.carvalho, bharathsm
  Cc: stable

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.

Cc: stable@vger.kernel.org #6.3+
Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
 fs/smb/client/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index c43ca74e8704..5188218c25be 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] smb: client: fix in-place encryption corruption in SMB2_write()
  2026-03-09 10:30 [PATCH] smb: client: fix in-place encryption corruption in SMB2_write() Bharath SM
@ 2026-03-09 12:43 ` Shyam Prasad N
  2026-03-09 15:51 ` Henrique Carvalho
  1 sibling, 0 replies; 4+ messages in thread
From: Shyam Prasad N @ 2026-03-09 12:43 UTC (permalink / raw)
  To: Bharath SM
  Cc: linux-cifs, smfrench, dhowells, sprasad, pc, ematsumiya,
	henrique.carvalho, bharathsm, stable

On Mon, Mar 9, 2026 at 4:02 PM Bharath SM <bharathsm.hsk@gmail.com> wrote:
>
> 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.
>
> Cc: stable@vger.kernel.org #6.3+
> Signed-off-by: Bharath SM <bharathsm@microsoft.com>
> ---
>  fs/smb/client/smb2pdu.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
> index c43ca74e8704..5188218c25be 100644
> --- a/fs/smb/client/smb2pdu.c
> +++ b/fs/smb/client/smb2pdu.c
> @@ -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
>
>

Looks good to me.

-- 
Regards,
Shyam

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] smb: client: fix in-place encryption corruption in SMB2_write()
  2026-03-09 10:30 [PATCH] smb: client: fix in-place encryption corruption in SMB2_write() Bharath SM
  2026-03-09 12:43 ` Shyam Prasad N
@ 2026-03-09 15:51 ` Henrique Carvalho
  2026-03-09 16:49   ` Steve French
  1 sibling, 1 reply; 4+ messages in thread
From: Henrique Carvalho @ 2026-03-09 15:51 UTC (permalink / raw)
  To: Bharath SM
  Cc: linux-cifs, smfrench, dhowells, sprasad, pc, ematsumiya,
	bharathsm, stable

Acked-by: Henrique Carvalho <henrique.carvalho@suse.com>

On Mon, Mar 09, 2026 at 04:00:49PM +0530, Bharath SM wrote:
> 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.
> 
> Cc: stable@vger.kernel.org #6.3+
> Signed-off-by: Bharath SM <bharathsm@microsoft.com>
> ---
>  fs/smb/client/smb2pdu.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
> index c43ca74e8704..5188218c25be 100644
> --- a/fs/smb/client/smb2pdu.c
> +++ b/fs/smb/client/smb2pdu.c
> @@ -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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] smb: client: fix in-place encryption corruption in SMB2_write()
  2026-03-09 15:51 ` Henrique Carvalho
@ 2026-03-09 16:49   ` Steve French
  0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2026-03-09 16:49 UTC (permalink / raw)
  To: Henrique Carvalho
  Cc: Bharath SM, linux-cifs, dhowells, sprasad, pc, ematsumiya,
	bharathsm, stable

merged into cifs-2.6.git for-next

On Mon, Mar 9, 2026 at 10:52 AM Henrique Carvalho
<henrique.carvalho@suse.com> wrote:
>
> Acked-by: Henrique Carvalho <henrique.carvalho@suse.com>
>
> On Mon, Mar 09, 2026 at 04:00:49PM +0530, Bharath SM wrote:
> > 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.
> >
> > Cc: stable@vger.kernel.org #6.3+
> > Signed-off-by: Bharath SM <bharathsm@microsoft.com>
> > ---
> >  fs/smb/client/smb2pdu.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
> > index c43ca74e8704..5188218c25be 100644
> > --- a/fs/smb/client/smb2pdu.c
> > +++ b/fs/smb/client/smb2pdu.c
> > @@ -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
> >



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-09 16:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 10:30 [PATCH] smb: client: fix in-place encryption corruption in SMB2_write() Bharath SM
2026-03-09 12:43 ` Shyam Prasad N
2026-03-09 15:51 ` Henrique Carvalho
2026-03-09 16:49   ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox