smb: client: fix broken multichannel with krb5+signing
Subsystems (2)
Paulo Alcantara
maintainerPATCH 1/1 smb: client: fix broken multichannel with krb5+signing
When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.
Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in SMB2_auth_kerberos().
Repro:
$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i $ sleep 5 $ umount /mnt $ dmesg ... CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x4 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13
--- fs/smb/client/smb2pdu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/smb/client/smb2pdu.c +10 -12
@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) is_binding = (ses->ses_status ==SES_GOOD );spin_unlock (&ses->ses_lock); -/* keep session key if binding */ -if (!is_binding) { -kfree_sensitive (ses->auth_key.response); - ses->auth_key.response =kmemdup (msg->data, msg->sesskey_len, -GFP_KERNEL ); -if (!ses->auth_key.response) { -cifs_dbg (VFS ,"Kerberos can't allocate (%u bytes) memory\n" , - msg->sesskey_len); - rc = -ENOMEM ; - goto out_put_spnego_key; - } - ses->auth_key.len = msg->sesskey_len; +kfree_sensitive (ses->auth_key.response); + ses->auth_key.response =kmemdup (msg->data, + msg->sesskey_len, +GFP_KERNEL ); +if (!ses->auth_key.response) { +cifs_dbg (VFS ,"%s: can't allocate (%u bytes) memory\n" , + __func__, msg->sesskey_len); + rc = -ENOMEM ; + goto out_put_spnego_key; } + ses->auth_key.len = msg->sesskey_len; sess_data->iov[1 ].iov_base = msg->data + msg->sesskey_len; sess_data->iov[1 ].iov_len = msg->secblob_len;
Signature · 1 line
2.53.0
added Cc:stable and tentatively merged into cifs-2.6.git pending more review and testing
Quoted 69 lines · Paulo Alcantara
When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.
Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in
SMB2_auth_kerberos().Repro:
$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i $ sleep 5 $ umount /mnt $ dmesg ... CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x4 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13Reported-by Xiaoli Feng <[email protected]>Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>Cc David Howells <[email protected]>--- fs/smb/client/smb2pdu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)fs/smb/client/smb2pdu.c +10
-13@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) is_binding = (ses->ses_status ==SES_GOOD );spin_unlock (&ses->ses_lock); -/* keep session key if binding */ -if (!is_binding) { -kfree_sensitive (ses->auth_key.response); - ses->auth_key.response =kmemdup (msg->data, msg->sesskey_len, -GFP_KERNEL ); -if (!ses->auth_key.response) { -cifs_dbg (VFS ,"Kerberos can't allocate (%u bytes) memory\n" , - msg->sesskey_len); - rc = -ENOMEM ; - goto out_put_spnego_key; - } - ses->auth_key.len = msg->sesskey_len; +kfree_sensitive (ses->auth_key.response); + ses->auth_key.response =kmemdup (msg->data, + msg->sesskey_len, +GFP_KERNEL ); +if (!ses->auth_key.response) { +cifs_dbg (VFS ,"%s: can't allocate (%u bytes) memory\n" , + __func__, msg->sesskey_len); + rc = -ENOMEM ; + goto out_put_spnego_key; } + ses->auth_key.len = msg->sesskey_len; sess_data->iov[1 ].iov_base = msg->data + msg->sesskey_len; sess_data->iov[1 ].iov_len = msg->secblob_len; --2.53.0
Signature · 3 lines
Thanks, Steve
Quoted 55 lines · Paulo Alcantara
When mounting a share with 'multichannel,max_channels=n,sec=krb5i', the client was duplicating signing key for all secondary channels, thus making the server fail all commands sent from secondary channels due to bad signatures.
Every channel has its own signing key, so when establishing a new channel with krb5 auth, make sure to use the new session key as the derived key to generate channel's signing key in
SMB2_auth_kerberos().Repro:
$ mount.cifs //srv/share /mnt -o multichannel,max_channels=4,sec=krb5i $ sleep 5 $ umount /mnt $ dmesg ... CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x5 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13 CIFS: VFS: sign fail cmd 0x4 message id 0x2 CIFS: VFS: \\srv SMB signature verification returned error = -13Reported-by Xiaoli Feng <[email protected]>Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>Cc David Howells <[email protected]>---
fs/smb/client/smb2pdu.c| 22 ++++++++++------------1 file changed, 10 insertions(+), 12 deletions(-)fs/smb/client/smb2pdu.c +4
-12@@ -1714,19 +1714,17 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) is_binding = (ses->ses_status ==SES_GOOD );spin_unlock (&ses->ses_lock); -/* keep session key if binding */ -if (!is_binding) { -kfree_sensitive (ses->auth_key.response); - ses->auth_key.response =kmemdup (msg->data, msg->sesskey_len, -GFP_KERNEL ); -if (!ses->auth_key.response) { -cifs_dbg (VFS ,"Kerberos can't allocate (%u bytes) memory\n" , - msg->sesskey_len); - rc = -ENOMEM ; - goto out_put_spnego_key; - } - ses->auth_key.len = msg->sesskey_len; +kfree_sensitive (ses->auth_key.response); + ses->auth_key.response =kmemdup (msg->data, + msg->sesskey_len, +GFP_KERNEL );
fs/smb/client/smb2pdu.c SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) · line 1730
Quoted 10 lines
fs/smb/client/smb2pdu.c +6
-0+if (!ses->auth_key.response) { +cifs_dbg (VFS ,"%s: can't allocate (%u bytes) memory\n" , + __func__, msg->sesskey_len); + rc = -ENOMEM ; + goto out_put_spnego_key; } + ses->auth_key.len = msg->sesskey_len; sess_data->iov[1 ].iov_base = msg->data + msg->sesskey_len; sess_data->iov[1 ].iov_len = msg->secblob_len;
You can drop the same check for SessionId/Flags right below, as the server is expected to return the same values for those for multichannel.
(which then means 'is_binding' can be dropped altogether).
Either way,